UNPKG

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