ng-afelio
Version:
Extended Angular CLI
43 lines (42 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
const parse_name_1 = require("@schematics/angular/utility/parse-name");
const workspace_1 = require("@schematics/angular/utility/workspace");
const barrel_1 = require("../util/barrel");
const validation_1 = require("../util/validation");
function default_1(options) {
return async (host) => {
if (!options.project) {
throw new schematics_1.SchematicsException('Option (project) is required.');
}
const workspace = await (0, workspace_1.getWorkspace)(host);
const project = workspace.projects.get(options.project);
if (project && options.path === undefined) {
options.path = (0, workspace_1.buildDefaultPath)(project);
}
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
options.name = parsedPath.name;
options.path = (0, barrel_1.relativeCwdFromRelativeProjectPath)(parsedPath.path);
(0, validation_1.validateName)(options.name);
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
options.guards ? (0, schematics_1.noop)() : (0, schematics_1.filter)(p => !p.includes('/guards/')),
options.pipes ? (0, schematics_1.noop)() : (0, schematics_1.filter)(p => !p.includes('/pipes/')),
options.stores ? (0, schematics_1.noop)() : (0, schematics_1.filter)(p => !p.includes('/stores/')),
options.directives ? (0, schematics_1.noop)() : (0, schematics_1.filter)(p => !p.includes('/directives/')),
(0, schematics_1.template)({
...core_1.strings,
'if-flat': (s) => (options.flat ? '' : s),
...options,
}),
(0, schematics_1.move)(options.path),
]);
return (0, schematics_1.chain)([
(0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
(0, schematics_1.mergeWith)(templateSource),
])),
]);
};
}
exports.default = default_1;