diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d864afe..73cd9b5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,15 +1,15 @@ name: build -on: +on: push: branches: - master paths: - - 'backend/package.json' + - "backend/package.json" pull_request: branches: - master paths: - - 'backend/package.json' + - "backend/package.json" jobs: build: runs-on: ubuntu-latest @@ -17,7 +17,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - ref: 'master' + ref: "master" - name: Set up Node.js uses: actions/setup-node@v3 with: @@ -34,6 +34,11 @@ jobs: run: | cd backend pnpm run build + - name: Bundle + run: | + cd backend + pnpm i -D estrella + pnpm run bundle - id: tag name: Generate release tag run: | @@ -52,3 +57,4 @@ jobs: ./backend/dist/sub-store-1.min.js ./backend/dist/sub-store-parser.loon.min.js ./backend/dist/cron-sync-artifacts.min.js + ./backend/dist/sub-store.bundle.js diff --git a/backend/bundle.js b/backend/bundle.js new file mode 100644 index 0000000..8ebe890 --- /dev/null +++ b/backend/bundle.js @@ -0,0 +1,23 @@ +#!/usr/bin/env node +const fs = require('fs'); + +const path = require('path'); + +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', +}); + +const { build } = require('estrella'); +build({ + entry: 'dist/sub-store.no-bundle.js', + outfile: 'dist/sub-store.bundle.js', + bundle: true, + platform: 'node', +}); diff --git a/backend/package.json b/backend/package.json index 9a05ad1..cc7f750 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.37", + "version": "2.14.38", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { @@ -8,7 +8,8 @@ "test": "gulp peggy && npx cross-env BABEL_ENV=test mocha src/test/**/*.spec.js --require @babel/register --recursive", "serve": "node sub-store.min.js", "start": "nodemon -w src -w package.json --exec babel-node src/main.js", - "build": "gulp" + "build": "gulp", + "bundle": "node bundle.js" }, "author": "Peng-YM", "license": "GPL-3.0", diff --git a/backend/src/utils/resource-cache.js b/backend/src/utils/resource-cache.js index 3c4e46b..6bb3092 100644 --- a/backend/src/utils/resource-cache.js +++ b/backend/src/utils/resource-cache.js @@ -48,7 +48,7 @@ class ResourceCache { } set(id, value) { - this.resourceCache[id] = { time: new Date().getTime(), data: value } + this.resourceCache[id] = { time: new Date().getTime(), data: value }; this._persist(); } }