1 | let fs = require('fs');
|
2 | let rimraf = require('rimraf');
|
3 | let path = require('path');
|
4 | let execSync = require('child_process').execSync;
|
5 | let {staticsPath, projectConf} = require('../lib/scripts/util/config');
|
6 | let hooks = {};
|
7 |
|
8 | if (fs.existsSync(`${process.cwd()}/tools/buildHooks.js`)) {
|
9 | hooks = require(`${process.cwd()}/tools/buildHooks.js`);
|
10 | }
|
11 |
|
12 |
|
13 |
|
14 | rimraf.sync('./docs');
|
15 | rimraf.sync('./dist');
|
16 |
|
17 | let 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 |
|
23 | hooks.onBuildStart && hooks.onBuildStart();
|
24 |
|
25 |
|
26 | build.forEach((cmd) => {
|
27 | let child = execSync(cmd, {stdio: [0, 1, 2]});
|
28 | });
|
29 |
|
30 | console.log('Build done!');
|
31 | let indexHTML = fs.readFileSync(path.join(`${staticsPath}/app_index.html`), 'utf8');
|
32 |
|
33 | let bodyInnerHTML = projectConf.bodyHTML || '<div id=\'app\'></div>';
|
34 |
|
35 | indexHTML = indexHTML.replace('{bodyHTML}', bodyInnerHTML);
|
36 |
|
37 | fs.writeFileSync('./dist/index.html', indexHTML);
|
38 |
|
39 | let baseDir = process.cwd();
|
40 |
|
41 |
|
42 | if (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 |
|
47 | hooks.onBuildComplete && hooks.onBuildComplete();
|