diff --git a/release.ts b/release.ts index 10c2550d..bb6ca295 100644 --- a/release.ts +++ b/release.ts @@ -5,6 +5,8 @@ import { minify } from 'terser' import { SingleBar, Presets } from 'cli-progress' import { exec } from '@yao-pkg/pkg' import { obfuscate } from 'javascript-obfuscator' +import { Loggings } from 'loggings' +import { formatBytes } from './src/functions/Format' async function carregarDados (options: { diretorio: string @@ -30,6 +32,8 @@ async function carregarDados (options: { } async function compress (): Promise { + const seed = Math.random() + const core = new Loggings() const progressBar = new SingleBar({}, Presets.rect) const files = await carregarDados({ diretorio: 'dist' }) progressBar.start(Object.entries(files).length, 0) @@ -55,20 +59,15 @@ async function compress (): Promise { ascii_only: true, beautify: false, comments: false - }, - sourceMap: true + } }) .then((result) => { if (typeof result.code !== 'string') return const response = obfuscate(fileContent, { - compact: false, - controlFlowFlattening: true, - controlFlowFlatteningThreshold: 1, - numbersToExpressions: true, - simplify: true, - stringArrayShuffle: true, - splitStrings: true, - stringArrayThreshold: 1 + optionsPreset: 'medium-obfuscation', + log: true, + seed, + disableConsoleOutput: false }) writeFileSync(`${newPath}/${fileName}`, response.getObfuscatedCode(), 'utf8') }) @@ -83,14 +82,12 @@ async function compress (): Promise { progressBar.stop() - const args = ['.', '--no-bytecode', '--public-packages', '"*"', '--public'] - const platforms = ['linux'] - const archs = ['x64'] + const args = ['.', '--no-bytecode', '--compress', 'Brotli', '--public-packages', '"*"', '--public'] + const platforms = ['alpine', 'linux', 'linuxstatic'] + const archs = ['x64', 'arm64'] const nodeVersion = '20' const allBuild: string[] = [] - args.push('-t') - if (os.platform() !== 'win32') { for (const platform of platforms) { for (const arch of archs) { @@ -103,12 +100,34 @@ async function compress (): Promise { } } - args.push(allBuild.join(',')) - console.log(os.platform()) - console.log(args) + for (const build of allBuild) { + const startTime = Date.now() + const nameSplit = build.split('-') + const buildName = build.split('-') + buildName.splice(0, 1) + const buildType = nameSplit[1] === 'win' + ? `./release/paymentbot-[${buildName.join('-')}].exe` + : `./release/paymentbot-[${buildName.join('-')}]` - await exec(args) + const newArg: string[] = [] + newArg.push(...args) + newArg.push('-t', build, '-o', buildType) + await exec(newArg) + + const endTime = Date.now() + const timeSpent = (endTime - startTime) / 1000 + 's' + core.info(`Build | ${nameSplit[1]}-${nameSplit[2]} | ${timeSpent}`) + + const file = readFileSync(buildType) + writeFileSync(`${buildType}.json`, JSON.stringify({ + fileName: buildType.replace('./release/', ''), + platform: nameSplit[1], + arch: nameSplit[2], + size: formatBytes(file.byteLength), + timeBuild: timeSpent + }, null, 4)) + } } void compress() diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 222d79b3..4061102f 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "include": [ - "rollup.config.ts", "compress.ts" + "rollup.config.ts", "compress.ts", "./release.ts" ] } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 273f8a90..011f3cad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,6 +28,6 @@ "skipDefaultLibCheck": true, "skipLibCheck": true }, - "include": ["./src/**/*", "./release.ts"], + "include": ["./src/**/*"], "exclude": [""] } \ No newline at end of file