Icard/angular-clarity-master(work.../node_modules/@schematics/angular/component/index.js

76 lines
11 KiB
JavaScript

"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const add_declaration_to_ng_module_1 = require("../utility/add-declaration-to-ng-module");
const find_module_1 = require("../utility/find-module");
const parse_name_1 = require("../utility/parse-name");
const validation_1 = require("../utility/validation");
const workspace_1 = require("../utility/workspace");
const schema_1 = require("./schema");
function buildSelector(options, projectPrefix) {
let selector = schematics_1.strings.dasherize(options.name);
if (options.prefix) {
selector = `${options.prefix}-${selector}`;
}
else if (options.prefix === undefined && projectPrefix) {
selector = `${projectPrefix}-${selector}`;
}
return selector;
}
function default_1(options) {
return async (host) => {
const workspace = await (0, workspace_1.getWorkspace)(host);
const project = workspace.projects.get(options.project);
if (!project) {
throw new schematics_1.SchematicsException(`Project "${options.project}" does not exist.`);
}
if (options.path === undefined) {
options.path = (0, workspace_1.buildDefaultPath)(project);
}
options.module = (0, find_module_1.findModuleFromOptions)(host, options);
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
options.selector =
options.selector || buildSelector(options, (project && project.prefix) || '');
(0, validation_1.validateHtmlSelector)(options.selector);
const skipStyleFile = options.inlineStyle || options.style === schema_1.Style.None;
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
skipStyleFile ? (0, schematics_1.filter)((path) => !path.endsWith('.__style__.template')) : (0, schematics_1.noop)(),
options.inlineTemplate ? (0, schematics_1.filter)((path) => !path.endsWith('.html.template')) : (0, schematics_1.noop)(),
(0, schematics_1.applyTemplates)({
...schematics_1.strings,
'if-flat': (s) => (options.flat ? '' : s),
...options,
}),
!options.type
? (0, schematics_1.forEach)(((file) => {
return file.path.includes('..')
? {
content: file.content,
path: file.path.replace('..', '.'),
}
: file;
}))
: (0, schematics_1.noop)(),
(0, schematics_1.move)(parsedPath.path),
]);
return (0, schematics_1.chain)([
(0, add_declaration_to_ng_module_1.addDeclarationToNgModule)({
type: 'component',
...options,
}),
(0, schematics_1.mergeWith)(templateSource),
]);
};
}
exports.default = default_1;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zY2hlbWF0aWNzL2FuZ3VsYXIvY29tcG9uZW50L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7O0FBRUgsMkRBZW9DO0FBQ3BDLDBGQUFtRjtBQUNuRix3REFBK0Q7QUFDL0Qsc0RBQWtEO0FBQ2xELHNEQUE2RDtBQUM3RCxvREFBc0U7QUFDdEUscUNBQTZEO0FBRTdELFNBQVMsYUFBYSxDQUFDLE9BQXlCLEVBQUUsYUFBcUI7SUFDckUsSUFBSSxRQUFRLEdBQUcsb0JBQU8sQ0FBQyxTQUFTLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQy9DLElBQUksT0FBTyxDQUFDLE1BQU0sRUFBRTtRQUNsQixRQUFRLEdBQUcsR0FBRyxPQUFPLENBQUMsTUFBTSxJQUFJLFFBQVEsRUFBRSxDQUFDO0tBQzVDO1NBQU0sSUFBSSxPQUFPLENBQUMsTUFBTSxLQUFLLFNBQVMsSUFBSSxhQUFhLEVBQUU7UUFDeEQsUUFBUSxHQUFHLEdBQUcsYUFBYSxJQUFJLFFBQVEsRUFBRSxDQUFDO0tBQzNDO0lBRUQsT0FBTyxRQUFRLENBQUM7QUFDbEIsQ0FBQztBQUVELG1CQUF5QixPQUF5QjtJQUNoRCxPQ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uY29udGVudCxcbiAgICAgICAgICAgICAgICAgIHBhdGg6IGZpbGUucGF0aC5yZXBsYWNlKCcuLicsICcuJyksXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICA6IGZpbGU7XG4gICAgICAgICAgfSkgYXMgRmlsZU9wZXJhdG9yKVxuICAgICAgICA6IG5vb3AoKSxcbiAgICAgIG1vdmUocGFyc2VkUGF0aC5wYXRoKSxcbiAgICBdKTtcblxuICAgIHJldHVybiBjaGFpbihbXG4gICAgICBhZGREZWNsYXJhdGlvblRvTmdNb2R1bGUoe1xuICAgICAgICB0eXBlOiAnY29tcG9uZW50JyxcbiAgICAgICAgLi4ub3B0aW9ucyxcbiAgICAgIH0pLFxuICAgICAgbWVyZ2VXaXRoKHRlbXBsYXRlU291cmNlKSxcbiAgICBdKTtcbiAgfTtcbn1cbiJdfQ==