UNPKG

1.91 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10const schematics_1 = require("@angular-devkit/schematics");
11const add_declaration_to_ng_module_1 = require("../utility/add-declaration-to-ng-module");
12const find_module_1 = require("../utility/find-module");
13const parse_name_1 = require("../utility/parse-name");
14const validation_1 = require("../utility/validation");
15const workspace_1 = require("../utility/workspace");
16function default_1(options) {
17 return async (host) => {
18 options.path ??= await (0, workspace_1.createDefaultPath)(host, options.project);
19 options.module = (0, find_module_1.findModuleFromOptions)(host, options);
20 const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
21 options.name = parsedPath.name;
22 options.path = parsedPath.path;
23 (0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
24 const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
25 options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
26 (0, schematics_1.applyTemplates)({
27 ...schematics_1.strings,
28 'if-flat': (s) => (options.flat ? '' : s),
29 ...options,
30 }),
31 (0, schematics_1.move)(parsedPath.path),
32 ]);
33 return (0, schematics_1.chain)([
34 (0, add_declaration_to_ng_module_1.addDeclarationToNgModule)({
35 type: 'pipe',
36 ...options,
37 }),
38 (0, schematics_1.mergeWith)(templateSource),
39 ]);
40 };
41}
42exports.default = default_1;