Skip to content

Commit

Permalink
📦 Using the global build system
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Dec 17, 2024
1 parent e7a8c66 commit 74330c2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 67 deletions.
60 changes: 8 additions & 52 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,26 @@
# 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 }}
steps:

- 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
39 changes: 24 additions & 15 deletions build.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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'))
})
)
}
}
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
1 change: 1 addition & 0 deletions packages/worker/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "worker",
"version": "1.0.0",
"types": "src/app.ts",
"module": "src/app.ts",
"type": "module",
Expand Down

0 comments on commit 74330c2

Please sign in to comment.