1 |
|
2 | const fs = require('fs-extra');
|
3 | const path = require('path');
|
4 | const ora = require('ora');
|
5 | const installProfilePackage = require('../lib/install-profile-pkg');
|
6 | const assertPkg = require('../lib/package-json').assert;
|
7 | const notice = require('../lib/notice');
|
8 | const packageOptions = require('../lib/pkgOptions');
|
9 | const serve = require('../lib/serve');
|
10 |
|
11 | const spinner = ora();
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | const clean = () => {
|
17 | const distDir = path.join(process.cwd(), 'dist');
|
18 |
|
19 | fs.emptyDirSync(distDir);
|
20 | fs.rmdirSync(distDir);
|
21 | };
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | const buildDistribution = (pkg) => new Promise((resolve, reject) => {
|
28 | const buildssr = require('linc-build-ssr');
|
29 |
|
30 | return buildssr({}, pkg, (err) => {
|
31 | if (err) return reject(err);
|
32 |
|
33 | return resolve();
|
34 | });
|
35 | });
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | const build = async () => {
|
41 | |
42 |
|
43 |
|
44 | const pkg = await packageOptions(['buildProfile']);
|
45 |
|
46 | spinner.start('Installing profile package. Please wait...');
|
47 | await installProfilePackage(pkg.linc.buildProfile);
|
48 | spinner.succeed('Installed profile package.');
|
49 |
|
50 | |
51 |
|
52 |
|
53 | await buildDistribution(pkg);
|
54 | };
|
55 |
|
56 | exports.command = 'build';
|
57 | exports.desc = 'Build & package a site for deployment';
|
58 | exports.handler = (argv) => {
|
59 | assertPkg();
|
60 |
|
61 | notice();
|
62 |
|
63 | clean();
|
64 |
|
65 | build()
|
66 | .then(() => {
|
67 | if (!argv.s) serve();
|
68 |
|
69 | console.log('Done.');
|
70 | })
|
71 | .catch(err => {
|
72 | console.log(err);
|
73 | });
|
74 | };
|