Last active
October 6, 2020 02:54
-
-
Save nivrith/ba14bbace56caee6b22d5c031f2ae991 to your computer and use it in GitHub Desktop.
TS Node Script to Pass Custom command-line Args to Angular serve process
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
import * as yargs from 'yargs'; | |
import { spawn } from 'child_process'; | |
import { DEFAULT_APP_ENV } from './app-env'; | |
const parseNgArgs = () => process.argv.filter((arg, index) => index > 1 && Object.keys(DEFAULT_APP_ENV).every(key => !arg.includes(key))); | |
const ngArgs = parseNgArgs(); | |
const argv = { ...DEFAULT_APP_ENV, ...yargs.argv}; | |
const childProcess = spawn('yarn', ['start', ...ngArgs], { | |
stdio: 'inherit', | |
env: { ...process.env, APP_ENV: JSON.stringify(argv) }, | |
shell: true, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment