-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-bin.js
executable file
·62 lines (44 loc) · 1.46 KB
/
package-bin.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
#!/usr/bin/env node
const uWriteFile = function (param1, param2) {
if (!require('fs').existsSync(require('path').dirname(param1))){
require('fs').mkdirSync(require('path').dirname(param1));
}
require('fs').writeFileSync(param1, param2)
};
const mod = {
// CONTROL
ControlScanStart(args, watch) {
const configPath = (function() {
const custom = require('path').join(process.cwd(), 'rollup-config.js');
if (require('fs').existsSync(custom)) {
return custom;
}
const compiled = require('path').join(process.cwd(), '__compiled/rollup-config.js');
uWriteFile(compiled, `const OLSKRollupScaffold = require('${ require('path').join(__dirname, 'main.js') }');\n\nexport default OLSKRollupScaffold.OLSKRollupScaffoldScanStart(process.cwd());`);
return compiled;
})();
require('child_process').spawn('rollup', [].concat.apply([], [
watch ? ['-w'] : [],
'-c', configPath,
args.length
? args
: [],
]), {
stdio: 'inherit',
env: Object.assign(process.env, {
OLSK_ROLLUP_SCAFFOLD_CI: args.includes('--ci'),
}),
});
},
// LIFECYCLE
LifecycleScriptDidLoad() {
if (process.argv[1].endsWith('olsk-rollup-watch')) {
return mod.ControlScanStart(process.argv.slice(2), true);
};
if (process.argv[1].endsWith('olsk-rollup') && process.argv[2] === 'watch') {
return mod.ControlScanStart(process.argv.slice(3), true);
};
mod.ControlScanStart(process.argv.slice(2));
},
};
mod.LifecycleScriptDidLoad();