UNPKG

@nstudio/schematics

Version:

Cross-platform (xplat) tools for Nx workspaces.

71 lines 3.69 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.missingNameArgument('Provide a name for your Ionic app.', 'ng g app.ionic sample')); } return schematics_1.chain([ utils_1.prerun(options), // adjust naming convention utils_1.applyAppNamingConvention(options, 'ionic'), // create app files (tree, context) => addAppFiles(options, options.name)(tree, context), // add root package dependencies (tree) => utils_1.addRootDeps(tree, { ionic: true }), // add start/clean scripts (tree) => { const scripts = {}; const platformApp = options.name.replace('-', '.'); // ensure convenient clean script is added for workspace scripts[`clean`] = `npx rimraf -- hooks node_modules package-lock.json && npm i`; // add convenient ionic scripts scripts[`build.${platformApp}`] = `cd apps/${options.name} && npm run build:web`; scripts[`prepare.${platformApp}`] = `npm run clean && npm run clean.${platformApp} && npm run build.${platformApp}`; scripts[`prepare.${platformApp}.ios`] = `npm run prepare.${platformApp} && cd apps/${options.name} && npm run cap.add.ios`; scripts[`prepare.${platformApp}.android`] = `npm run prepare.${platformApp} && cd apps/${options.name} && npm run cap.add.android`; scripts[`open.${platformApp}.ios`] = `cd apps/${options.name} && npm run cap.ios`; scripts[`open.${platformApp}.android`] = `cd apps/${options.name} && npm run cap.android`; scripts[`sync.${platformApp}`] = `cd apps/${options.name} && npm run cap.copy`; scripts[`start.${platformApp}`] = `cd apps/${options.name} && npm start`; scripts[`clean.${platformApp}`] = `cd apps/${options.name} && npx rimraf -- hooks node_modules platforms www plugins ios android package-lock.json && npm i && rimraf -- package-lock.json`; return utils_1.updatePackageScripts(tree, scripts); }, (tree) => { const projects = {}; projects[`${options.name}`] = { "root": `apps/${options.name}/`, "sourceRoot": `apps/${options.name}/src`, "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); }, options.skipFormat ? schematics_1.noop() : utils_1.formatFiles(options) ]); } exports.default = default_1; function addAppFiles(options, appPath, sample = '') { sample = ''; const appname = utils_1.getAppName(options, 'ionic'); return schematics_1.branchAndMerge(schematics_1.mergeWith(schematics_1.apply(schematics_1.url(`./_${sample}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