-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
77 lines (67 loc) · 1.85 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as esbuild from 'esbuild';
import fs from 'fs';
const options = { watch: false };
let args = process.argv.slice(2);
args = args.map(arg => arg.toLowerCase());
if (args.includes('watch')) {
options.watch = true;
args.splice(args.indexOf('watch'), 1);
}
const buildInstructions = [];
fs.readdirSync('./src').forEach(file => {
if (file.indexOf('_') !== 0) {
if (args.length === 0 || args.includes(file.substring(0, file.length - 3))) {
const fileUncompressed = async function() {
const config = {
entryPoints: [`./src/${file}`],
bundle: true,
logLevel: 'info',
globalName: 'cm6',
sourcemap: 'external',
outfile: `./dist/${file}`,
};
if (options.watch) {
let ctx = await esbuild.context(config);
await ctx.watch();
console.log(`Watching ${file}...`);
} else {
await esbuild.build(config);
}
}
const fileMinified = async function() {
const config = {
entryPoints: [`./src/${file}`],
minify: true,
bundle: true,
logLevel: 'info',
globalName: 'cm6',
sourcemap: 'external',
outfile: `./dist/${file.replace('.js', '.min.js')}`,
};
if (options.watch) {
let ctx = await esbuild.context(config);
await ctx.watch();
console.log(`Watching ${file}...`);
} else {
await esbuild.build(config);
}
}
buildInstructions.push(fileUncompressed);
buildInstructions.push(fileMinified);
}
}
});
const run = async function() {
console.time('⚡ \x1b[32mDone in');
for (const buildInstruction of buildInstructions) {
if (options.watch) {
buildInstruction();
} else {
await buildInstruction();
}
}
console.log(`\n⚡ \x1b[32mBuilt: ${buildInstructions.length / 2} languages (${buildInstructions.length * 2} files)\x1b[0m`);
console.timeEnd('⚡ \x1b[32mDone in');
console.log('\x1b[0m');
}
run();