forked from bangle-io/banger-editor
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
83 lines (70 loc) · 1.78 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
78
79
80
81
82
83
let fs = require('fs');
let path = require('path');
const buildOptions = {
tsOptions: {
types: [],
noUnusedLocals: false,
lib: ['ES2019', 'dom', 'scripthost'],
allowSyntheticDefaultImports: true,
jsx: 'react',
target: 'es2018',
},
};
async function readPackages() {
const yarnWorkspacesListOutput = require('child_process')
.execSync(`yarn workspaces list --json`)
.toString()
.split('\n')
.filter(Boolean);
let result = await Promise.all(
yarnWorkspacesListOutput
.map((r) => JSON.parse(r))
.map(async (r) => {
const _path = path.join(
path.resolve(__dirname, r.location),
'package.json',
);
const file = fs.readFileSync(_path, 'utf-8');
const packageJSON = JSON.parse(file);
return { ...r, packageJSON };
}),
);
return result;
}
let projectDir = __dirname;
function joinP(...args) {
return path.join(projectDir, ...args);
}
function mainFile(pkg) {
let index = joinP(pkg, 'src', 'index.ts');
if (fs.existsSync(index)) {
return index;
}
throw new Error("Couldn't find a main file for " + pkg);
}
async function build() {
console.info('Building...');
let t0 = Date.now();
const list = (await readPackages()).filter((r) => {
return !r.packageJSON.private;
});
// await require('buildtool-bangle').watch(
// list.map((obj) => {
// return mainFile(obj.location);
// }),
// [],
// {
// ...buildOptions,
// include: ['**/src/**/*'],
// },
// );
await require('buildtool-bangle').build(
list.map((obj) => {
console.log('Working on ', obj.location);
return mainFile(obj.location);
}),
buildOptions,
);
console.info(`Done in ${((Date.now() - t0) / 1000).toFixed(2)}s`);
}
build();