@nstudio/schematics
Version:
Cross-platform (xplat) tools for Nx workspaces.
68 lines • 3.35 kB
JavaScript
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.missingNameArgument('Provide a name for your NativeScript app.', 'ng g app.nativescript sample'));
}
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 }),
// add start/clean scripts
(tree) => {
const scripts = {};
const platformApp = options.name.replace('-', '.');
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`;
scripts[`start.${platformApp}.android`] = `cd apps/${options.name} && tns run android --emulator --bundle`;
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}`)
])));
}
//# sourceMappingURL=index.js.map
;