UNPKG

1.55 kBJavaScriptView Raw
1let fs = require('fs');
2let rimraf = require('rimraf');
3let path = require('path');
4let execSync = require('child_process').execSync;
5let {staticsPath, projectConf} = require('../lib/scripts/util/config');
6let hooks = {};
7
8if (fs.existsSync(`${process.cwd()}/tools/buildHooks.js`)) {
9 hooks = require(`${process.cwd()}/tools/buildHooks.js`);
10}
11
12// TODO node_modules/jarb/lib/scripts/webpackBuild.js should be moved to a BIN
13
14rimraf.sync('./docs');
15rimraf.sync('./dist');
16
17let build = [
18 'jsdoc -c ./jsdocs.conf.json -u ./tutorials -t ./node_modules/ink-docstrap/template -R readme.md -r ./src -d docs',
19 'node node_modules/jarb/lib/scripts/webpackBuild.js',
20 'if test -e ./dist/bundle.css; then cssnano ./dist/bundle.css ./dist/bundle.css; else echo \'no css file to minify\'; fi'
21];
22
23hooks.onBuildStart && hooks.onBuildStart();
24
25// sync file for all commands to run the build
26build.forEach((cmd) => {
27 let child = execSync(cmd, {stdio: [0, 1, 2]});
28});
29
30console.log('Build done!');
31let indexHTML = fs.readFileSync(path.join(`${staticsPath}/app_index.html`), 'utf8');
32
33let bodyInnerHTML = projectConf.bodyHTML || '<div id=\'app\'></div>';
34
35indexHTML = indexHTML.replace('{bodyHTML}', bodyInnerHTML);
36
37fs.writeFileSync('./dist/index.html', indexHTML);
38
39let baseDir = process.cwd();
40
41// A custom file might also be present...
42if (fs.existsSync(`${baseDir}/src/dist.html`)) {
43 let indexHTML = fs.readFileSync(`${baseDir}/src/dist.html`, 'utf8');
44 fs.writeFileSync('./dist/index.html', indexHTML);
45}
46
47hooks.onBuildComplete && hooks.onBuildComplete();