Skip to content

Instantly share code, notes, and snippets.

@nivrith
Last active October 6, 2020 02:54
Show Gist options
  • Save nivrith/ba14bbace56caee6b22d5c031f2ae991 to your computer and use it in GitHub Desktop.
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
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