diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index d963c33..50c1d96 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -2,16 +2,14 @@ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs name: Build - on: push: branches: [ "workspace" ] pull_request: branches: [ "workspace" ] - jobs: prepare: - name: Find paths + name: Building Packages runs-on: ubuntu-latest outputs: paths: ${{ steps.paths.outputs.paths }} @@ -19,53 +17,11 @@ jobs: - name: Clone repo uses: actions/checkout@v4 - - - uses: actions/github-script@v7 - name: List paths - id: paths + - uses: oven-sh/setup-bun@v2 with: - script: | - const fs = require('fs') - const path = require('path') - const process = require('process') - const paths = [] - - paths.push(...getProjects('plugins')) - paths.push(...getProjects('packages')) - - paths.push('core') - console.log(paths) - - core.setOutput('paths', paths) - - function getProjects(dirname) { - const pathName = path.join(process.cwd(), dirname) - const files = fs.readdirSync(pathName) - const directories = files.filter((file) => fs.statSync(path.join(pathName, file)).isDirectory()).map((dir) => `${dirname}/${dir}`) - - return directories - } - build: - name: Build ${{ matrix.path }} - runs-on: ubuntu-latest - needs: prepare - strategy: - matrix: - node-version: [20.11.1] - path: ${{ fromJson(needs.prepare.outputs.paths) }} - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - steps: - - uses: actions/checkout@v4 - - uses: oven-sh/setup-bun@v2 - with: - bun-version: latest - - run: | - cd ${{ matrix.path }} && - bun i && - # Verifica se o script "build" existe antes de rodar - if bun run | grep -q "build"; then - bun run build - else - echo "Script 'build' não encontrado. Continuando..." - fi && - bun build ./src/app.ts --bundle --platform=node --target=bun --outfile=build.js + bun-version: latest + - run: | + bun i && + openssl genpkey -algorithm RSA -out privateKey.pem -pkeyopt rsa_keygen_bits:4096 && + openssl rsa -pubout -in privateKey.pem -out publicKey.pem && + bun run build.ts \ No newline at end of file diff --git a/build.ts b/build.ts index e523245..8cd7ed8 100644 --- a/build.ts +++ b/build.ts @@ -1,9 +1,10 @@ import { exec as execChild } from 'child_process' import { existsSync } from 'fs' import { mkdir } from 'fs/promises' +import { glob } from 'glob' import { createSign, createVerify } from 'node:crypto' import { readFileSync } from 'node:fs' -import { readFile, writeFile } from 'node:fs/promises' +import { readFile, rm, writeFile } from 'node:fs/promises' import { join } from 'path' type PluginBuilderOptions = { @@ -47,13 +48,19 @@ class PluginBuilder { this.signatureLength = options?.signatureLength ?? this.signatureLength } - async build () { + async build (): Promise<'file' | 'directory'> { await this.exec('bun install') if (this.hasBuildScript) await this.exec('bun run build') if (!existsSync(this.outputDirectory)) await mkdir(this.outputDirectory, { recursive: true }) - await this.exec(`bun build ${this.buildArgs.join(' ')} --outfile=${this.outputFilePath}`) + try { + await this.exec(`bun build ${this.buildArgs.join(' ')} --outfile=${this.outputFilePath}`) + return 'file' + } catch { + await this.exec(`bun build ${this.buildArgs.join(' ')} --outdir=${this.outputFilePath}`) + return 'directory' + } } async sign (privateKeyPath: string): Promise { @@ -106,18 +113,20 @@ class PluginBuilder { } } -// 'plugins/base' -await Promise.all( - ['plugins/tickets'].map(async (path) => { - const builder = new PluginBuilder({ - directory: join(process.cwd(), path), - entryFile: 'src/app.ts', - signatureLength: 256, - outputDirectory: join(process.cwd(), 'release'), - }) +const projects = await glob(['plugins/*', 'packages/*', 'core'], { cwd: process.cwd() }) - await builder.build() +await rm('releases', { recursive: true }) +for (const project of projects) { + const builder = new PluginBuilder({ + directory: join(process.cwd(), project), + entryFile: 'src/app.ts', + signatureLength: 256, + outputDirectory: join(process.cwd(), 'release'), + }) + + const buildType = await builder.build() + if (buildType === 'file') { await builder.sign(join(process.cwd(), 'privateKey.pem')) await builder.singCheck(join(process.cwd(), 'publicKey.pem')) - }) -) \ No newline at end of file + } +} \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index 368a8a1..c574e35 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 8baeebd..85b914d 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "typescript-eslint": "^8.17.0" }, "dependencies": { + "@types/glob": "^8.1.0", "country-code-to-flag-emoji": "^1.3.3", "prompts": "^2.4.2" } diff --git a/packages/worker/package.json b/packages/worker/package.json index 033d71b..731849f 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -1,5 +1,6 @@ { "name": "worker", + "version": "1.0.0", "types": "src/app.ts", "module": "src/app.ts", "type": "module",