-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun-build-deepmap.js
47 lines (44 loc) · 1.2 KB
/
run-build-deepmap.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
const fs = require('fs');
const path = require('path');
const packageJSON = require('./src/utils/DeepMap/package.json');
const format = process.argv[2];
const watch = process.argv[3] === '--watch';
if (!format || !(format in { esm: true, cjs: true })) {
throw 'Invalid format supplied';
}
require('esbuild')
.build({
entryPoints: [path.resolve(__dirname, 'src/utils/DeepMap/index.ts')],
bundle: true,
plugins: [],
define: {},
watch: watch
? {
onRebuild(error, result) {
if (error) console.error('watch build failed:', error);
else console.log('watch build succeeded:', result);
},
}
: null,
external: [],
format: format,
bundle: true,
platform: 'browser',
outfile: path.resolve(
__dirname,
`dist-deepmap/index${format === 'esm' ? '.esm' : ''}.js`,
),
})
.then(() => {
try {
fs.writeFileSync(
path.resolve(__dirname, './dist-deepmap/package.json'),
JSON.stringify(packageJSON, null, 2),
'utf8',
);
} catch (ex) {
console.error('Cannot find or write dist-deepmap/package.json');
console.error(ex);
}
})
.catch(() => process.exit(1));