1 | import * as program from 'commander';
|
2 | import * as path from 'path';
|
3 | import * as shell from 'shelljs';
|
4 | import { Component } from './component';
|
5 | import { exit, isNutmegComponent, notifyOfUpdate, nutmegDir, tsconfigPath } from './utils';
|
6 |
|
7 | notifyOfUpdate();
|
8 |
|
9 | program.command('build <path>', 'compile a Web Component')
|
10 | .option('--analyzer', 'enable Webpack Bundle Analyzer')
|
11 | .option('--production', 'compile a Web Component for deployment')
|
12 | .parse(process.argv);
|
13 |
|
14 | const workingDir = path.resolve(process.cwd(), program.args[0]);
|
15 | const webpackConfigFile = path.resolve(nutmegDir, 'webpack.component.config.js');
|
16 | const tag = Component.tagFromPackage(workingDir);
|
17 | const productionFlag = program.production ? '--env.production' : '';
|
18 | const analyzerFlag = program.analyzer ? '--env.analyzer' : '';
|
19 | const tscCmd = `tsc --project ${tsconfigPath(workingDir)}`;
|
20 | const webpackCmd = `webpack --config ${webpackConfigFile} --env.tag=${tag} ${productionFlag} ${analyzerFlag} --env.workingDir=${workingDir}`;
|
21 |
|
22 | exit("Directory doesn't have a package.json with @nutmeg/seed as a dependancy.", !isNutmegComponent(workingDir));
|
23 |
|
24 | shell.exec(`npx ${tscCmd}`);
|
25 | shell.exec(`npx ${webpackCmd}`);
|