|
1 | 1 | import * as child_process from 'child_process'; |
2 | 2 | import {blue, yellow} from 'chalk'; |
| 3 | +import {getGlobalVariable} from './env'; |
| 4 | +import {rimraf, writeFile} from './fs'; |
3 | 5 | const treeKill = require('tree-kill'); |
4 | 6 |
|
5 | 7 |
|
@@ -75,7 +77,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce |
75 | 77 | _processes = _processes.filter(p => p !== childProcess); |
76 | 78 |
|
77 | 79 | if (!error) { |
78 | | - resolve(stdout); |
| 80 | + resolve({ stdout }); |
79 | 81 | } else { |
80 | 82 | err.message += `${error}...\n\nSTDOUT:\n${stdout}\n`; |
81 | 83 | reject(err); |
@@ -134,9 +136,26 @@ export function silentExecAndWaitForOutputToMatch(cmd: string, args: string[], m |
134 | 136 | return _exec({ silent: true, waitForMatch: match }, cmd, args); |
135 | 137 | } |
136 | 138 |
|
| 139 | + |
| 140 | +let npmInstalledEject = false; |
137 | 141 | export function ng(...args: string[]) { |
138 | 142 | // Auto-add --no-progress to commands that build the app, otherwise we get thousands of lines. |
139 | 143 | if (['build', 'serve', 'test', 'e2e', 'xi18n'].indexOf(args[0]) != -1) { |
| 144 | + // If we have the --eject, use webpack for the test. |
| 145 | + const argv = getGlobalVariable('argv'); |
| 146 | + if (args[0] == 'build' && argv.eject) { |
| 147 | + return silentNg('eject', ...args.slice(1), '--force') |
| 148 | + .then(() => { |
| 149 | + if (!npmInstalledEject) { |
| 150 | + npmInstalledEject = true; |
| 151 | + // We need to run npm install on the first eject. |
| 152 | + return silentNpm('install'); |
| 153 | + } |
| 154 | + }) |
| 155 | + .then(() => rimraf('dist')) |
| 156 | + .then(() => _exec({silent: true}, 'node_modules/.bin/webpack', [])); |
| 157 | + } |
| 158 | + |
140 | 159 | return silentNg(...args, '--no-progress'); |
141 | 160 | } else { |
142 | 161 | return _exec({}, 'ng', args); |
|
0 commit comments