2018-11-05 12:21:27 -05:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
// Imports
|
|
|
|
const {extend, parse} = require('cjson');
|
|
|
|
const {readFileSync, writeFileSync} = require('fs');
|
|
|
|
const {join, resolve} = require('path');
|
|
|
|
const {exec, set} = require('shelljs');
|
|
|
|
|
|
|
|
set('-e');
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
const ROOT_DIR = resolve(__dirname, '..');
|
2019-04-19 08:42:56 -04:00
|
|
|
const NG_JSON = join(ROOT_DIR, 'angular.json');
|
2018-11-05 12:21:27 -05:00
|
|
|
const NG_COMPILER_OPTS = {
|
|
|
|
angularCompilerOptions: {
|
|
|
|
// Related Jira issue: FW-737
|
|
|
|
allowEmptyCodegenFiles: true,
|
2019-04-02 14:53:49 -04:00
|
|
|
enableIvy: true,
|
2018-11-05 12:21:27 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Run
|
|
|
|
_main(process.argv.slice(2));
|
|
|
|
|
|
|
|
// Functions - Definitions
|
2019-04-02 14:53:49 -04:00
|
|
|
function _main() {
|
2019-04-19 08:42:56 -04:00
|
|
|
// 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);
|
|
|
|
|
2019-04-02 14:53:49 -04:00
|
|
|
// Enable Ivy in TS config.
|
2019-04-19 08:42:56 -04:00
|
|
|
console.log(`\nModifying \`${tsConfigPath}\`...`);
|
|
|
|
const oldTsConfigStr = readFileSync(tsConfigPath, 'utf8');
|
2018-11-05 12:21:27 -05:00
|
|
|
const oldTsConfigObj = parse(oldTsConfigStr);
|
|
|
|
const newTsConfigObj = extend(true, oldTsConfigObj, NG_COMPILER_OPTS);
|
2019-04-30 19:24:13 -04:00
|
|
|
const newTsConfigStr = `${JSON.stringify(newTsConfigObj, null, 2)}\n`;
|
2019-04-02 14:53:49 -04:00
|
|
|
console.log(`\nNew config: ${newTsConfigStr}`);
|
2019-04-19 08:42:56 -04:00
|
|
|
writeFileSync(tsConfigPath, newTsConfigStr);
|
2018-11-05 12:21:27 -05:00
|
|
|
|
2019-04-02 14:53:49 -04:00
|
|
|
// Run ngcc.
|
|
|
|
const ngccArgs = '--loglevel debug --properties es2015 module';
|
|
|
|
console.log(`\nRunning ngcc (with args: ${ngccArgs})...`);
|
|
|
|
exec(`yarn ivy-ngcc ${ngccArgs}`);
|
2018-11-05 12:21:27 -05:00
|
|
|
|
2019-04-02 14:53:49 -04:00
|
|
|
// Done.
|
|
|
|
console.log('\nReady to build with Ivy!');
|
|
|
|
console.log('(To switch back to ViewEngine (with packages from npm), undo the changes in ' +
|
2019-04-19 08:42:56 -04:00
|
|
|
`\`${tsConfigPath}\` and run \`yarn aio-use-npm && yarn example-use-npm\`.)`);
|
2018-11-05 12:21:27 -05:00
|
|
|
}
|