UNPKG

@nstudio/schematics

Version:

Cross-platform (xplat) tools for Nx workspaces.

100 lines 4.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const utils_1 = require("../utils"); function default_1(options) { if (!options.name) { throw new schematics_1.SchematicsException(utils_1.missingArgument('name', 'Provide a name for your NativeScript app.', 'ng g app.nativescript sample')); } if (options.setupSandbox) { // always setup routing with sandbox options.routing = true; } return schematics_1.chain([ utils_1.prerun(options), // adjust naming convention utils_1.applyAppNamingConvention(options, 'nativescript'), // create app files (tree, context) => addAppFiles(options, options.name)(tree, context), // add sample feature (tree, context) => options.sample || options.routing ? addAppFiles(options, options.name, options.sample ? 'sample' : 'routing')(tree, context) : schematics_1.noop()(tree, context), // add app resources (tree, context) => // inside closure to ensure it uses the modifed options.name from applyAppNamingConvention schematics_1.schematic('app-resources', { path: `apps/${options.name}/app`, })(tree, context), // add root package dependencies (tree) => utils_1.addRootDeps(tree, { nativescript: true }), utils_1.addInstall, addNsCli(options.addCliDependency), // add start/clean scripts (tree) => { const scripts = {}; const platformApp = options.name.replace('-', '.'); // standard apps don't have hmr on by default since results can vary // more reliable to leave off by default for now // however, sandbox setup due to its simplicity uses hmr by default let hmr = options.setupSandbox ? ' --hmr' : ''; scripts[`clean`] = `npx rimraf -- hooks node_modules package-lock.json && npm i`; scripts[`start.${platformApp}.ios`] = `cd apps/${options.name} && tns run ios --emulator --bundle${hmr}`; scripts[`start.${platformApp}.android`] = `cd apps/${options.name} && tns run android --emulator --bundle${hmr}`; scripts[`start.${platformApp}.preview`] = `cd apps/${options.name} && tns preview --bundle${hmr}`; scripts[`clean.${platformApp}`] = `cd apps/${options.name} && npx rimraf -- hooks node_modules platforms package-lock.json && npm i && npx rimraf -- package-lock.json`; return utils_1.updatePackageScripts(tree, scripts); }, (tree) => { const projects = {}; projects[`${options.name}`] = { "root": `apps/${options.name}/`, "sourceRoot": `apps/${options.name}/app`, "projectType": "application", "prefix": utils_1.getPrefix(), "schematics": { "@schematics/angular:component": { "styleext": "scss" } } }; return utils_1.updateAngularProjects(tree, projects); }, (tree) => { const projects = {}; projects[`${options.name}`] = { tags: [] }; return utils_1.updateNxProjects(tree, projects); } ]); } exports.default = default_1; function addAppFiles(options, appPath, extra = '') { extra = extra ? `${extra}_` : ''; const appname = utils_1.getAppName(options, 'nativescript'); return schematics_1.branchAndMerge(schematics_1.mergeWith(schematics_1.apply(schematics_1.url(`./_${extra}files`), [ schematics_1.template(Object.assign({}, options, { appname, utils: utils_1.stringUtils, npmScope: utils_1.getNpmScope(), prefix: utils_1.getPrefix(), dot: '.' })), schematics_1.move(`apps/${appPath}`) ]))); } /** * Add {N} CLI to devDependencies */ function addNsCli(add) { if (!add) { return schematics_1.noop(); } return (tree) => { const packagePath = "package.json"; const packageJson = utils_1.getJsonFromFile(tree, packagePath); if (!packageJson) { return tree; } packageJson.devDependencies = utils_1.setDependency(packageJson.devDependencies, { name: 'nativescript', version: "^5.0.0", type: "devDependency" }); return utils_1.updateJsonFile(tree, packagePath, packageJson); }; } //# sourceMappingURL=index.js.map