Skip to content

Commit

Permalink
🧱 Fix Build
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Jun 16, 2024
1 parent 94683e3 commit 81ce3e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
apt update && apt install -y nodejs
run: |
npm i
npm run build -- --install --compress --obfuscate --pkg --clean
npm run build -- --install --compress --obfuscate --pkg --clean --sing
- name: Node.js ${{ matrix.node-version }}
if: matrix.arch == 'x64'
Expand Down
51 changes: 26 additions & 25 deletions release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import babel from "@babel/core"
import { formatBytes } from 'bytes-formatter'
import { exec } from 'child_process'
import { Presets, SingleBar } from 'cli-progress'
import { createHash, createSign, createVerify, sign } from 'crypto'
import { createHash, createSign, createVerify } from 'crypto'
import { build } from 'esbuild'
import { createWriteStream, existsSync } from 'fs'
import { exists } from 'fs-extra'
Expand All @@ -27,8 +27,6 @@ interface BuildInfo {
hashSHA?: string
}

type BuildManifest = Record<string, BuildInfo>

interface BuildConstructor {
/**
* Directory of Typescript Resources
Expand Down Expand Up @@ -111,7 +109,7 @@ class Build {
await this.obfuscate()
await this.install()
await this.clear()
await this.convertToCJS(`${this.options.outBuild}/node_modules`, `${this.options.outBuild}/node_modules`)
await this.convertToCJS(`${this.options.outBuild}/node_modules`, `${this.options.outBuild}/node_modules`, this.options.outBuild)
await this.compress({ directory: `${this.options.outBuild}/node_modules`, outBuild: `${this.options.outBuild}/node_modules` })
await this.pkgbuild()
await this.sign()
Expand All @@ -127,25 +125,25 @@ class Build {
const sucess = await execProcess(`cd ${this.options.source} && npm i && npm run build`)
if (!sucess) throw new Error(`Ocorreu um erro ao tentar buildar o projeto ${this.options.source}`)

const pathBuild = join(this.options.source, '/build/esm/src')
const pathBuild = join(this.options.source, '/build/esm')
const files = await glob(`${pathBuild}/**/*.js`)

console.log('Convertendo em cjs...')
await this.convertToCJS(files, this.options.outBuild)
await this.convertToCJS(files, this.options.outBuild, pathBuild)
}

async convertToCJS(files: string[] | string, output: string) {
async convertToCJS(files: string[] | string, output: string, homePath: string) {
if (typeof files === 'string') files = await glob(`${files}/**/*.js`)

this.progressBar.start(files.length, 0)
for (const file of files) {
try {
if ((await stat(file)).isDirectory()) { this.progressBar.increment(); continue }

const filePath = dirname(file).split('esm/')[1]
const fileName = basename(file)
const outputPath = `${output}/${filePath}`
const outputFile = join(outputPath, fileName)
const filePath = dirname(path.normalize(file.replace(`${homePath}/`, ''))) // src/functions
const fileName = basename(file) // port.js
const outputPath = join(output, filePath) // build/core/src/functions
const outputFile = join(outputPath, fileName) // build/core/src/functions/port.js
const data = await readFile(file, { encoding: 'utf-8' })
const result = await babel.transformAsync(data, {
presets: ["@babel/preset-env", "@babel/preset-typescript"],
Expand Down Expand Up @@ -193,23 +191,21 @@ class Build {

if (!existsSync(newPath)) await mkdir(newPath, { recursive: true })

const result = await minify({ [filePath]: fileContent.toString('utf-8') }, {
const result = await minify({ [filePath]: fileContent.toString('utf-8') }, {
compress: true,
module: true,
module: false,
ecma: 5,
toplevel: true,
parse: {
bare_returns: true
},
mangle: true,
format: {
braces: true,
comments: 'some',
keep_quoted_props: true,
wrap_iife: true
},
nameCache: {},
keep_classnames: true,
keep_fnames: true
ascii_only: true,
}
})
.catch((err) => {
console.log(filePath)
console.log(err)
return { code: fileContent.toString('utf-8') }
})

if (result.code === undefined) { this.progressBar.increment(length); continue }

Expand Down Expand Up @@ -455,6 +451,7 @@ const archs = ['arm64', 'x64'];
{ command: 'obfuscate', alias: ['-f'], rank: 6 },
{ command: 'esbuild', alias: ['-esb'], rank: 7 },
{ command: 'pkg', alias: [''], rank: 7 },
{ command: 'sing', alias: ['-sn'], rank: 8 },
]

for (const arg of args.filter((arg) => arg.includes('-'))) {
Expand Down Expand Up @@ -643,9 +640,13 @@ release [options] <input>
buildFunctions.push(() => build.esbuild())
break
}
case 'sing' : {
buildFunctions.push(async () => { await build.sign(); await build.singCheck() })
break
}
}
}
buildFunctions.push(() => build.saveManifest())
if (newArgs.find((arg) => arg.command === 'pkg')?.command !== undefined) buildFunctions.push(() => build.saveManifest())
exec.push(async () => await execQueue(buildFunctions))
}

Expand Down

0 comments on commit 81ce3e1

Please sign in to comment.