UNPKG

@nstudio/schematics

Version:

Cross-platform (xplat) tools for Nx workspaces.

60 lines 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const tasks_1 = require("@angular-devkit/schematics/tasks"); 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 Nest app.', 'ng g app.nest sample')); } const appPath = `nest-${options.name}`; return schematics_1.chain([ utils_1.prerun(options), // adjust naming convention utils_1.applyAppNamingConvention(options, 'nest'), // create app files (tree, context) => addAppFiles(options, appPath)(tree, context), // add root package dependencies (tree) => utils_1.addRootDeps(tree, { nest: true }), // add npm scripts (tree) => { const platformApp = options.name.replace('-', '.'); const packageConfig = utils_1.getJsonFromFile(tree, "package.json"); const scripts = packageConfig.scripts || {}; scripts[`serve.${platformApp}`] = `ts-node -P apps/${options.name}/tsconfig.json apps/${options.name}/src/main.ts`; scripts[`start.${platformApp}`] = `npm-run-all -p serve.${platformApp}`; scripts[`build.${platformApp}`] = `tsc -p apps/${options.name}`; scripts[`test.${platformApp}`] = `jest --config=apps/${options.name}/jest.json`; scripts[`test.${platformApp}.coverage`] = `jest --config=apps/${options.name}/jest.json --coverage --coverageDirectory=coverage`; scripts[`test.${platformApp}.watch`] = `jest --config=apps/${options.name}/jest.json --watch`; scripts[`test.${platformApp}.e2e`] = `jest --config=apps/${options.name}/e2e/jest-e2e.json --forceExit`; scripts[`test.${platformApp}.e2e.watch`] = `jest --config=apps/${options.name}/e2e/jest-e2e.json --watch`; return utils_1.updatePackageScripts(tree, scripts); }, // nx.json (tree) => { const projects = {}; projects[`${options.name}`] = { tags: [] }; return utils_1.updateNxProjects(tree, projects); }, addInstall, utils_1.addPostinstallers(), options.skipFormat ? schematics_1.noop() : utils_1.formatFiles(options) ]); } exports.default = default_1; function addInstall(host, context) { context.addTask(new tasks_1.NodePackageInstallTask()); return host; } function addAppFiles(options, appPath, sample = "") { sample = ""; const appname = utils_1.getAppName(options, 'nest'); 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