@nstudio/schematics
Version:
Cross-platform (xplat) tools for Nx workspaces.
54 lines • 3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const path_1 = require("path");
const fs = require("fs");
const utils_1 = require("../../utils");
function updateNativeScriptApps(tree, context) {
const appsDir = tree.getDir('apps');
const appFolders = appsDir.subdirs;
const cwd = process.cwd();
const mainPath = path_1.join(cwd, 'node_modules/@nstudio/schematics/src/app.nativescript/_files/app/main.ts');
// console.log('webpackConfigPath:', webpackConfigPath);
let mainFile = fs.readFileSync(mainPath, 'UTF-8');
const webpackConfigPath = path_1.join(cwd, 'node_modules/@nstudio/schematics/src/app.nativescript/_files/webpack.config.js');
// console.log('webpackConfigPath:', webpackConfigPath);
const webpackConfig = fs.readFileSync(webpackConfigPath, 'UTF-8');
// update {N} apps and configs
for (const dir of appFolders) {
// console.log(dir);
if (dir.indexOf('nativescript-') === 0 || dir.indexOf('-nativescript') === 0) {
const appDir = `${appsDir.path}/${dir}`;
// console.log('appDir:', appDir);
utils_1.createOrUpdate(tree, `${appDir}/webpack.config.js`, webpackConfig);
utils_1.createOrUpdate(tree, `${appDir}/app/main.ts`, mainFile);
// update {N} app deps
const packagePath = `${appDir}/package.json`;
const packageJson = utils_1.getJsonFromFile(tree, packagePath);
if (packageJson) {
packageJson.dependencies = packageJson.dependencies || {};
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies = Object.assign({}, packageJson.devDependencies, { "@angular/compiler-cli": "~7.2.0", "@ngtools/webpack": "~7.2.0", "nativescript-dev-webpack": "~0.20.0", "terser-webpack-plugin": "file:../../node_modules/terser-webpack-plugin" });
// console.log('path:',path);
// console.log('packageJson overwrite:', JSON.stringify(packageJson));
tree = utils_1.updateJsonFile(tree, packagePath, packageJson);
}
}
}
return tree;
}
function updateRootPackage(tree, context) {
return utils_1.updateJsonInTree("package.json", json => {
json.scripts = json.scripts || {};
json.dependencies = json.dependencies || {};
json.dependencies = Object.assign({}, json.dependencies, { "nativescript-angular": "~7.2.0", "tns-core-modules": "~5.2.0" });
json.devDependencies = json.devDependencies || {};
json.devDependencies = Object.assign({}, json.devDependencies, { "terser-webpack-plugin": "~1.2.0", "tns-platform-declarations": "~5.2.0" });
return json;
})(tree, context);
}
function default_1() {
return schematics_1.chain([updateNativeScriptApps, updateRootPackage]);
}
exports.default = default_1;
//# sourceMappingURL=update-7-3-2.js.map