UNPKG

1.67 kBJavaScriptView Raw
1/* eslint-disable global-require,import/no-dynamic-require */
2const fs = require('fs-extra');
3const path = require('path');
4const ora = require('ora');
5const installProfilePackage = require('../lib/install-profile-pkg');
6const assertPkg = require('../lib/package-json').assert;
7const notice = require('../lib/notice');
8const packageOptions = require('../lib/pkgOptions');
9const serve = require('../lib/serve');
10
11const spinner = ora();
12
13/**
14 * Clean dist directory
15 */
16const clean = () => {
17 const distDir = path.join(process.cwd(), 'dist');
18
19 fs.emptyDirSync(distDir);
20 fs.rmdirSync(distDir);
21};
22
23/**
24 * Build distribution
25 * @param pkg
26 */
27const 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 * Build site
39 */
40const build = async () => {
41 /**
42 * Check for or add build profile and install if needed
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 * Build distribution
52 */
53 await buildDistribution(pkg);
54};
55
56exports.command = 'build';
57exports.desc = 'Build & package a site for deployment';
58exports.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};