forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: remove duplicate ngc compilation logic (angular#9175)
Abstracts away the logic for compiling with ngc that was duplicated between the `build-package.ts` and `compile-entry-point.ts`.
- Loading branch information
Showing
3 changed files
with
28 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {resolve as resolvePath} from 'path'; | ||
import {spawn} from 'child_process'; | ||
import {red} from 'chalk'; | ||
|
||
/** | ||
* Spawns a child process that compiles using ngc. | ||
* @param flags Command-line flags to be passed to ngc. | ||
* @returns Promise that resolves/rejects when the child process exits. | ||
*/ | ||
export function ngcCompile(flags: string[]) { | ||
return new Promise((resolve, reject) => { | ||
const ngcPath = resolvePath('./node_modules/.bin/ngc'); | ||
const childProcess = spawn(ngcPath, flags, {shell: true}); | ||
|
||
// Pipe stdout and stderr from the child process. | ||
childProcess.stdout.on('data', (data: string|Buffer) => console.log(`${data}`)); | ||
childProcess.stderr.on('data', (data: string|Buffer) => console.error(red(`${data}`))); | ||
childProcess.on('exit', (exitCode: number) => exitCode === 0 ? resolve() : reject()); | ||
}); | ||
} |