UNPKG

1.89 kBPlain TextView Raw
1import { ui, spinner, Command, Project, unwrap } from 'denali-cli';
2
3/**
4 * Compile your app
5 *
6 * @package commands
7 */
8export default class BuildCommand extends Command {
9
10 /* tslint:disable:completed-docs typedef */
11 static commandName = 'build';
12 static description = 'Compile your app';
13 static longDescription = unwrap`
14 Compiles your app based on your denali-build.js file, as well as any build-related addons.
15 `;
16
17 static flags = {
18 environment: {
19 description: 'The target environment to build for.',
20 default: process.env.NODE_ENV || 'development',
21 type: <any>'string'
22 },
23 output: {
24 description: 'The directory to build into',
25 default: 'dist',
26 type: <any>'string'
27 },
28 watch: {
29 description: 'Continuously watch the source files and rebuild on changes',
30 default: false,
31 type: <any>'boolean'
32 },
33 skipLint: {
34 description: 'Skip linting the app source files',
35 default: false,
36 type: <any>'boolean'
37 },
38 // TODO this should default to true if building for production
39 audit: {
40 description: 'Auditing your package.json for vulnerabilites',
41 default: false,
42 type: <any>'boolean'
43 },
44 printSlowTrees: {
45 description: 'Print out an analysis of the build process, showing the slowest nodes.',
46 default: false,
47 type: <any>'boolean'
48 }
49 };
50
51 runsInApp = true;
52
53 async run(argv: any) {
54 let project = new Project({
55 environment: argv.environment,
56 printSlowTrees: argv.printSlowTrees,
57 lint: !argv.skipLint,
58 audit: argv.audit
59 });
60
61 if (argv.watch) {
62 project.watch({
63 outputDir: <string>argv.output
64 });
65 } else {
66 try {
67 await project.build(argv.output);
68 } catch (error) {
69 await spinner.fail('Build failed');
70 ui.error(error.stack);
71 }
72 }
73 }
74
75}