generated from capacitor-community/.github
-
Notifications
You must be signed in to change notification settings - Fork 59
/
build.js
53 lines (49 loc) · 1.45 KB
/
build.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
41
42
43
44
45
46
47
48
49
50
51
52
53
/* 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('./', 'src', 'electron-platform-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 buildCliScrpts() {
await esbuild.build({
entryPoints: ['src/cli-scripts/index.ts'],
bundle: true,
outfile: 'dist/cli-scripts/cap-scripts.js',
platform: 'node',
target: 'node16',
minify: true,
external: ['child_process', 'fs', 'path', 'fs-extra', 'crypto', 'chalk', 'ora'],
});
}
async function buildPlatformCore() {
await esbuild.build({
entryPoints: ['src/electron-platform/index.ts'],
bundle: true,
outfile: 'dist/core/index.js',
platform: 'node',
target: 'node16',
minify: true,
external: ['electron', 'fs', 'path', 'mime-types', 'events'],
});
}
(async () => {
try {
await buildPlatformCore();
await buildCliScrpts();
await packTemplate();
console.log('\nPlatform Build Complete.\n');
} catch (e) {
console.error(e);
process.exit(1);
}
})();