-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-platform.js
40 lines (37 loc) · 1.07 KB
/
build-platform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const esbuild = require('esbuild');
const { readdirSync } = require('fs');
const { join } = require('path');
const tar = require('tar');
async function packTemplate() {
const templateSrc = join('./', 'template');
const destTemplateFilePath = join('./', 'template.tar.gz');
const files = [];
readdirSync(templateSrc).forEach((file) => {
files.push(file);
});
await tar.create({ gzip: true, file: destTemplateFilePath, cwd: templateSrc }, files);
console.log(`Packed ${destTemplateFilePath}!`);
}
async function buildCliScripts() {
await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'dist/index.js',
platform: 'node',
target: 'node16',
minify: true,
external: ['child_process', 'fs', 'path', 'fs-extra', 'crypto', 'chalk', 'ora'],
});
}
(async () => {
try {
await buildCliScripts();
await packTemplate();
console.log('\nPlatform Build Complete.\n');
} catch (e) {
console.error(e);
process.exit(1);
}
})();