build(docs-infra): make tsconfig path detection in `switch-to-ivy` more robust (#29989)

In light of #29926, that will change the path of `tsconfig.app.json`,
this commit switches from a hard-coded `tsconfig.app.json` path to
looking it up in `angular.json` (to be more future-proof).

PR Close #29989
This commit is contained in:
George Kalpakas 2019-04-19 15:42:56 +03:00 committed by Ben Lesh
parent 11eef85133
commit 5650e3847b
1 changed files with 9 additions and 5 deletions

View File

@ -10,7 +10,7 @@ set('-e');
// Constants
const ROOT_DIR = resolve(__dirname, '..');
const TS_CONFIG_PATH = join(ROOT_DIR, 'src/tsconfig.app.json');
const NG_JSON = join(ROOT_DIR, 'angular.json');
const NG_COMPILER_OPTS = {
angularCompilerOptions: {
// Related Jira issue: FW-737
@ -24,14 +24,18 @@ _main(process.argv.slice(2));
// Functions - Definitions
function _main() {
// Detect path to `tsconfig.app.json`.
const ngConfig = parse(readFileSync(NG_JSON, 'utf8'));
const tsConfigPath = join(ROOT_DIR, ngConfig.projects.site.architect.build.options.tsConfig);
// Enable Ivy in TS config.
console.log(`\nModifying \`${TS_CONFIG_PATH}\`...`);
const oldTsConfigStr = readFileSync(TS_CONFIG_PATH, 'utf8');
console.log(`\nModifying \`${tsConfigPath}\`...`);
const oldTsConfigStr = readFileSync(tsConfigPath, 'utf8');
const oldTsConfigObj = parse(oldTsConfigStr);
const newTsConfigObj = extend(true, oldTsConfigObj, NG_COMPILER_OPTS);
const newTsConfigStr = JSON.stringify(newTsConfigObj, null, 2);
console.log(`\nNew config: ${newTsConfigStr}`);
writeFileSync(TS_CONFIG_PATH, newTsConfigStr);
writeFileSync(tsConfigPath, newTsConfigStr);
// Run ngcc.
const ngccArgs = '--loglevel debug --properties es2015 module';
@ -41,5 +45,5 @@ function _main() {
// Done.
console.log('\nReady to build with Ivy!');
console.log('(To switch back to ViewEngine (with packages from npm), undo the changes in ' +
`\`${TS_CONFIG_PATH}\` and run \`yarn aio-use-npm && yarn example-use-npm\`.)`);
`\`${tsConfigPath}\` and run \`yarn aio-use-npm && yarn example-use-npm\`.)`);
}