76 lines
11 KiB
JavaScript
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zY2hlbWF0aWNzL2FuZ3VsYXIvY29tcG9uZW50L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7O0FBRUgsMkRBZW9DO0FBQ3BDLDBGQUFtRjtBQUNuRix3REFBK0Q7QUFDL0Qsc0RBQWtEO0FBQ2xELHNEQUE2RDtBQUM3RCxvREFBc0U7QUFDdEUscUNBQTZEO0FBRTdELFNBQVMsYUFBYSxDQUFDLE9BQ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