From 6614d8270fecd07f00eb99d5deb42aa1aef6debd Mon Sep 17 00:00:00 2001 From: Il Harper Date: Sun, 10 Mar 2024 02:32:10 +0800 Subject: [PATCH] ci: pack llqqnt engines --- .github/workflows/build.yml | 24 +++++++++---- package.json | 3 +- scripts/packllqqntengine.cts | 69 ++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 scripts/packllqqntengine.cts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1ac7a96..7c57c92 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,17 +36,29 @@ jobs: name: chronocat-llqqnt-${{ github.sha }} path: build/dist/llqqnt - - name: Upload engine-chronocat-api + - name: Upload engine-chronocat-api LiteLoaderQQNT Plugin uses: actions/upload-artifact@v3 with: - name: engine-chronocat-api-${{ github.sha }} - path: build/dist/engine-chronocat-api + name: chronocat-llqqnt-engine-chronocat-api-${{ github.sha }} + path: build/dist/llqqnt-plugin-chronocat-engine-chronocat-api - - name: Upload engine-chronocat-event + - name: Upload engine-chronocat-event LiteLoaderQQNT Plugin uses: actions/upload-artifact@v3 with: - name: engine-chronocat-event-${{ github.sha }} - path: build/dist/engine-chronocat-event + name: chronocat-llqqnt-engine-chronocat-event-${{ github.sha }} + path: build/dist/llqqnt-plugin-chronocat-engine-chronocat-event + + # - name: Upload engine-chronocat-api + # uses: actions/upload-artifact@v3 + # with: + # name: engine-chronocat-api-${{ github.sha }} + # path: build/dist/engine-chronocat-api + + # - name: Upload engine-chronocat-event + # uses: actions/upload-artifact@v3 + # with: + # name: engine-chronocat-event-${{ github.sha }} + # path: build/dist/engine-chronocat-event - name: Upload IIFE uses: actions/upload-artifact@v3 diff --git a/package.json b/package.json index 0ecc38f..fdf63ed 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,9 @@ ], "scripts": { "clean": "node -r esbuild-register scripts/clean.cts", - "build": "concurrently -n red \"yarn workspace @chronocat/red build\" && concurrently -n shell \"yarn workspace @chronocat/shell build\" && concurrently -n api,event \"yarn workspace @chronocat/engine-chronocat-api build\" \"yarn workspace @chronocat/engine-chronocat-event build\" && concurrently -n llqqnt,iife \"yarn workspace @chronocat/plugin-llqqnt build\" \"yarn workspace @chronocat/plugin-iife build\" && concurrently -n packengine yarn:packengine", + "build": "concurrently -n red \"yarn workspace @chronocat/red build\" && concurrently -n shell \"yarn workspace @chronocat/shell build\" && concurrently -n api,event \"yarn workspace @chronocat/engine-chronocat-api build\" \"yarn workspace @chronocat/engine-chronocat-event build\" && concurrently -n llqqnt,iife \"yarn workspace @chronocat/plugin-llqqnt build\" \"yarn workspace @chronocat/plugin-iife build\" && concurrently -n packengine,packllqqntengine yarn:packengine yarn:packllqqntengine", "packengine": "node -r esbuild-register scripts/packengine.cts", + "packllqqntengine": "node -r esbuild-register scripts/packllqqntengine.cts", "lint": "eslint --ignore-path .gitignore --ignore-pattern '**/*.d.ts' .", "lint:fix": "yarn lint --fix", "test": "jest" diff --git a/scripts/packllqqntengine.cts b/scripts/packllqqntengine.cts new file mode 100644 index 0000000..b843ba5 --- /dev/null +++ b/scripts/packllqqntengine.cts @@ -0,0 +1,69 @@ +import { cp, mkdir, writeFile } from 'node:fs/promises' +import { join, resolve } from 'node:path' + +void Promise.all( + ['engine-chronocat-api', 'engine-chronocat-event'].map(async (x) => { + const upper = `${x[0]!.toUpperCase()}${x.slice(1, 7)}${x[7]!.toUpperCase()}${x.slice(8, 17)}${x[17]!.toUpperCase()}${x.slice(18)}` + const distName = `LiteLoaderQQNT-Plugin-Chronocat-${upper}` + + const corePath = resolve(__dirname, `../packages/${x}/lib/index.js`) + const coreName = `${x.slice(7)}.engine.js` + + const distPath = resolve( + __dirname, + `../build/dist/llqqnt-plugin-chronocat-${x}/${distName}`, + ) + + const srcPath = join(distPath, 'src') + + await mkdir(srcPath, { + recursive: true, + }) + + await writeFile( + join(srcPath, 'main.js'), + `setTimeout(()=>{process.version='__chronocat__';process.version.load(require('./${coreName}'))},0)`, + ) + + await cp(corePath, join(srcPath, coreName)) + + const { version, description } = + // eslint-disable-next-line @typescript-eslint/no-var-requires + require(`../packages/${x}/package.json`) as { + version: string + description: string + } + + const manifest = { + manifest_version: 4, + type: 'extension', + name: `Chronocat Engine: ${x[7]!.toUpperCase()}${x.slice(8, 17)}${x[17]!.toUpperCase()}${x.slice(18)}`, + slug: `chronocat-${x}`, + description, + version, + thumbnail: './chronocat.png', + authors: [ + { + name: 'Team Chrononeko', + link: 'https://github.com/chrononeko', + }, + ], + repository: { + repo: `chrononeko/${distName}`, + branch: 'master', + }, + platform: ['win32', 'linux', 'darwin'], + dependencies: [], + injects: { + main: './src/main.js', + }, + } + + await writeFile(join(distPath, 'manifest.json'), JSON.stringify(manifest)) + + await cp( + resolve(__dirname, '../packages/docs/static/chronocat.png'), + join(distPath, 'chronocat.png'), + ) + }), +)