1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const schematics_1 = require("@angular-devkit/schematics");
|
11 | const add_declaration_to_ng_module_1 = require("../utility/add-declaration-to-ng-module");
|
12 | const find_module_1 = require("../utility/find-module");
|
13 | const parse_name_1 = require("../utility/parse-name");
|
14 | const validation_1 = require("../utility/validation");
|
15 | const workspace_1 = require("../utility/workspace");
|
16 | function buildSelector(options, projectPrefix) {
|
17 | let selector = options.name;
|
18 | if (options.prefix) {
|
19 | selector = `${options.prefix}-${selector}`;
|
20 | }
|
21 | else if (options.prefix === undefined && projectPrefix) {
|
22 | selector = `${projectPrefix}-${selector}`;
|
23 | }
|
24 | return schematics_1.strings.camelize(selector);
|
25 | }
|
26 | function default_1(options) {
|
27 | return async (host) => {
|
28 | const workspace = await (0, workspace_1.getWorkspace)(host);
|
29 | const project = workspace.projects.get(options.project);
|
30 | if (!project) {
|
31 | throw new schematics_1.SchematicsException(`Project "${options.project}" does not exist.`);
|
32 | }
|
33 | if (options.path === undefined) {
|
34 | options.path = (0, workspace_1.buildDefaultPath)(project);
|
35 | }
|
36 | options.module = (0, find_module_1.findModuleFromOptions)(host, options);
|
37 | const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
|
38 | options.name = parsedPath.name;
|
39 | options.path = parsedPath.path;
|
40 | options.selector = options.selector || buildSelector(options, project.prefix || '');
|
41 | (0, validation_1.validateHtmlSelector)(options.selector);
|
42 | const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
43 | options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
|
44 | (0, schematics_1.applyTemplates)({
|
45 | ...schematics_1.strings,
|
46 | 'if-flat': (s) => (options.flat ? '' : s),
|
47 | ...options,
|
48 | }),
|
49 | (0, schematics_1.move)(parsedPath.path),
|
50 | ]);
|
51 | return (0, schematics_1.chain)([
|
52 | (0, add_declaration_to_ng_module_1.addDeclarationToNgModule)({
|
53 | type: 'directive',
|
54 | ...options,
|
55 | }),
|
56 | (0, schematics_1.mergeWith)(templateSource),
|
57 | ]);
|
58 | };
|
59 | }
|
60 | exports.default = default_1;
|