|
1 | 1 | #! /usr/bin/env node
|
2 | 2 | const path = require('path');
|
3 |
| -import { build } from './build'; |
4 |
| -import { startWatch } from './start-watch'; |
5 |
| -import { runAngularCli } from './run-angular-cli'; |
| 3 | +import {build} from './build'; |
| 4 | +import {startWatch} from './start-watch'; |
| 5 | +import {runAngularCli} from './run-angular-cli'; |
6 | 6 |
|
7 |
| -let configFile = path.resolve(process.argv[2]); |
| 7 | +const supportedFlags = ['-no-watch', '-no-serve']; |
| 8 | +let args = process.argv.slice(2); |
| 9 | +let flags = []; |
| 10 | +args = args.reduce((accr, value) => { |
| 11 | + supportedFlags.indexOf(value) > -1 ? flags.push(value) : accr.push(value); |
| 12 | + return accr; |
| 13 | +}, []); |
| 14 | + |
| 15 | +const runWatch = flags.indexOf('-no-watch') === -1; |
| 16 | +const runAngularCliServe = flags.indexOf('-no-serve') === -1; |
| 17 | + |
| 18 | +const configFilePath = args[0] || 'angular-playground.json'; |
| 19 | + |
| 20 | +let configFile = path.resolve(configFilePath); |
8 | 21 | let config;
|
9 |
| -if (configFile) { |
| 22 | +try { |
10 | 23 | config = require(configFile.replace(/.json$/, ''));
|
11 |
| -} else { |
12 |
| - config = { |
13 |
| - sourceRoot: './' |
14 |
| - } |
| 24 | +} catch(e) { |
| 25 | + process.stdout.write(`[angular-playground]: \x1b[31mFailed to load config file ${configFile}\x1b[0m\n`); |
| 26 | + process.exit(1); |
15 | 27 | }
|
16 | 28 |
|
17 | 29 | build(config.sourceRoot);
|
18 |
| -startWatch(config, () => build(config.sourceRoot)); |
19 |
| -if (config.angularCli) { |
| 30 | +if (runWatch) { |
| 31 | + startWatch(config, () => build(config.sourceRoot)); |
| 32 | +} |
| 33 | +if (runAngularCliServe && config.angularCli) { |
20 | 34 | runAngularCli(config.angularCli);
|
21 | 35 | }
|
0 commit comments