From 5f5219fd31c562e40cdd16ef7f22b3850e6b3142 Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 3 Feb 2024 22:34:58 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=9C=A8=20bundle=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=A1=B6=E9=83=A8=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/bundle-esbuild.js | 14 +++++++++ backend/bundle.js | 64 +++++++++++++++++++++++++++------------ backend/package.json | 2 +- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/backend/bundle-esbuild.js b/backend/bundle-esbuild.js index 26ca95b..05d6bd6 100644 --- a/backend/bundle-esbuild.js +++ b/backend/bundle-esbuild.js @@ -4,6 +4,10 @@ const path = require('path'); const { build } = require('esbuild'); !(async () => { + const version = JSON.parse( + fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'), + ).version.trim(); + const artifacts = [ { src: 'src/main.js', dest: 'sub-store.min.js' }, { @@ -54,6 +58,16 @@ const { build } = require('esbuild'); format: 'cjs', outfile: 'dist/sub-store.bundle.js', }); + fs.writeFileSync( + path.join(__dirname, 'dist/sub-store.bundle.js'), + `// SUB_STORE_BACKEND_VERSION: ${version} +${fs.readFileSync(path.join(__dirname, 'dist/sub-store.bundle.js'), { + encoding: 'utf8', +})}`, + { + encoding: 'utf8', + }, + ); })() .catch((e) => { console.log(e); diff --git a/backend/bundle.js b/backend/bundle.js index da61ded..e196153 100644 --- a/backend/bundle.js +++ b/backend/bundle.js @@ -3,23 +3,49 @@ const fs = require('fs'); const path = require('path'); const { build } = require('esbuild'); -let content = fs.readFileSync(path.join(__dirname, 'sub-store.min.js'), { - encoding: 'utf8', -}); -content = content.replace( - /eval\(('|")(require\(('|").*?('|")\))('|")\)/g, - '$2', -); -fs.writeFileSync(path.join(__dirname, 'dist/sub-store.no-bundle.js'), content, { - encoding: 'utf8', -}); +!(async () => { + const version = JSON.parse( + fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'), + ).version.trim(); -build({ - entryPoints: ['dist/sub-store.no-bundle.js'], - bundle: true, - minify: true, - sourcemap: true, - platform: 'node', - format: 'cjs', - outfile: 'dist/sub-store.bundle.js', -}); + let content = fs.readFileSync(path.join(__dirname, 'sub-store.min.js'), { + encoding: 'utf8', + }); + content = content.replace( + /eval\(('|")(require\(('|").*?('|")\))('|")\)/g, + '$2', + ); + fs.writeFileSync( + path.join(__dirname, 'dist/sub-store.no-bundle.js'), + content, + { + encoding: 'utf8', + }, + ); + + await build({ + entryPoints: ['dist/sub-store.no-bundle.js'], + bundle: true, + minify: true, + sourcemap: true, + platform: 'node', + format: 'cjs', + outfile: 'dist/sub-store.bundle.js', + }); + fs.writeFileSync( + path.join(__dirname, 'dist/sub-store.bundle.js'), + `// SUB_STORE_BACKEND_VERSION: ${version} +${fs.readFileSync(path.join(__dirname, 'dist/sub-store.bundle.js'), { + encoding: 'utf8', +})}`, + { + encoding: 'utf8', + }, + ); +})() + .catch((e) => { + console.log(e); + }) + .finally(() => { + console.log('done'); + }); diff --git a/backend/package.json b/backend/package.json index 0d0e425..77b29e3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.204", + "version": "2.14.205", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": {