Repository navigation
Expand file tree
/
Copy pathbuild.js
More file actions
70 lines (63 loc) · 2.03 KB
/
Copy pathbuild.js
File metadata and controls
70 lines (63 loc) · 2.03 KB
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
#!/usr/bin/env node
const esbuild = require('esbuild');
const fs = require('fs');
const path = require('path');
const ROOT = __dirname;
const ENTRY_DIR = path.join(ROOT, 'src', 'indstream');
const ENTRIES_DIR = path.join(ENTRY_DIR, 'entries');
const OUT_DIR = path.join(ROOT, 'providers');
const EXTERNAL_MODULES = ['cheerio-without-node-native', 'react-native-cheerio', 'cheerio', 'crypto-js', 'axios'];
function entryList() {
const list = [{ entry: path.join(ENTRY_DIR, 'index.js'), out: path.join(OUT_DIR, 'indstream.js') }];
if (fs.existsSync(ENTRIES_DIR)) {
fs.readdirSync(ENTRIES_DIR).forEach(function (file) {
if (file.endsWith('.js')) {
const id = file.replace(/\.js$/, '');
list.push({ entry: path.join(ENTRIES_DIR, file), out: path.join(OUT_DIR, id + '.js') });
}
});
}
return list;
}
async function main() {
const args = process.argv.slice(2);
const jobs = entryList();
if (args.includes('--watch')) {
// Watch the combined entry only; full rebuild via npm run build.
const context = await esbuild.context({
entryPoints: [jobs[0].entry],
bundle: true,
outfile: jobs[0].out,
format: 'cjs',
platform: 'neutral',
target: 'es2016',
minify: args.includes('--minify'),
sourcemap: false,
external: EXTERNAL_MODULES,
logLevel: 'warning',
});
await context.watch();
console.log('Watching src/indstream/index.js -> providers/indstream.js');
return;
}
for (const job of jobs) {
await esbuild.build({
entryPoints: [job.entry],
bundle: true,
outfile: job.out,
format: 'cjs',
platform: 'neutral',
target: 'es2016',
minify: args.includes('--minify'),
sourcemap: false,
external: EXTERNAL_MODULES,
logLevel: 'warning',
});
const stats = fs.statSync(job.out);
console.log('Built ' + path.relative(ROOT, job.out) + ' (' + (stats.size / 1024).toFixed(1) + ' KB)');
}
}
main().catch(function (err) {
console.error('Build failed:', err);
process.exit(1);
});