Skip to content

Commit

Permalink
🧱 Fix Build
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Apr 22, 2024
1 parent 320bc66 commit eba1fac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
57 changes: 38 additions & 19 deletions release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +32,8 @@ async function carregarDados (options: {
}

async function compress (): Promise<void> {
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)
Expand All @@ -55,20 +59,15 @@ async function compress (): Promise<void> {
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')
})
Expand All @@ -83,14 +82,12 @@ async function compress (): Promise<void> {

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) {
Expand All @@ -103,12 +100,34 @@ async function compress (): Promise<void> {
}
}

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()
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"rollup.config.ts", "compress.ts"
"rollup.config.ts", "compress.ts", "./release.ts"
]
}

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"skipDefaultLibCheck": true,
"skipLibCheck": true
},
"include": ["./src/**/*", "./release.ts"],
"include": ["./src/**/*"],
"exclude": [""]
}

0 comments on commit eba1fac

Please sign in to comment.