"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 }); exports.buildComponent = void 0; const core_1 = require("@angular-devkit/core"); const schematics_1 = require("@angular-devkit/schematics"); const schema_1 = require("@schematics/angular/component/schema"); const change_1 = require("@schematics/angular/utility/change"); const workspace_1 = require("@schematics/angular/utility/workspace"); const find_module_1 = require("@schematics/angular/utility/find-module"); const parse_name_1 = require("@schematics/angular/utility/parse-name"); const validation_1 = require("@schematics/angular/utility/validation"); const workspace_models_1 = require("@schematics/angular/utility/workspace-models"); const ast_utils_1 = require("@schematics/angular/utility/ast-utils"); const fs_1 = require("fs"); const path_1 = require("path"); const ts = require("typescript"); const get_project_1 = require("./get-project"); const schematic_options_1 = require("./schematic-options"); /** * Build a default project path for generating. * @param project The project to build the path for. */ function buildDefaultPath(project) { const root = project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/`; const projectDirName = project.extensions.projectType === workspace_models_1.ProjectType.Application ? 'app' : 'lib'; return `${root}${projectDirName}`; } /** * List of style extensions which are CSS compatible. All supported CLI style extensions can be * found here: angular/angular-cli/main/packages/schematics/angular/ng-new/schema.json#L118-L122 */ const supportedCssExtensions = ['css', 'scss', 'less']; function readIntoSourceFile(host, modulePath) { const text = host.read(modulePath); if (text === null) { throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`); } return ts.createSourceFile(modulePath, text.toString('utf-8'), ts.ScriptTarget.Latest, true); } function addDeclarationToNgModule(options) { return (host) => { if (options.skipImport || options.standalone || !options.module) { return host; } const modulePath = options.module; let source = readIntoSourceFile(host, modulePath); const componentPath = `/${options.path}/` + (options.flat ? '' : core_1.strings.dasherize(options.name) + '/') + core_1.strings.dasherize(options.name) + '.component'; const relativePath = (0, find_module_1.buildRelativePath)(modulePath, componentPath); const classifiedName = core_1.strings.classify(`${options.name}Component`); const declarationChanges = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, relativePath); const declarationRecorder = host.beginUpdate(modulePath); for (const change of declarationChanges) { if (change instanceof change_1.InsertChange) { declarationRecorder.insertLeft(change.pos, change.toAdd); } } host.commitUpdate(declarationRecorder); if (options.export) { // Need to refresh the AST because we overwrote the file in the host. source = readIntoSourceFile(host, modulePath); const exportRecorder = host.beginUpdate(modulePath); const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Component`), relativePath); for (const change of exportChanges) { if (change instanceof change_1.InsertChange) { exportRecorder.insertLeft(change.pos, change.toAdd); } } host.commitUpdate(exportRecorder); } return host; }; } function buildSelector(options, projectPrefix) { let selector = core_1.strings.dasherize(options.name); if (options.prefix) { selector = `${options.prefix}-${selector}`; } else if (options.prefix === undefined && projectPrefix) { selector = `${projectPrefix}-${selector}`; } return selector; } /** * Indents the text content with the amount of specified spaces. The spaces will be added after * every line-break. This utility function can be used inside of EJS templates to properly * include the additional files. */ function indentTextContent(text, numSpaces) { // In the Material project there should be only LF line-endings, but the schematic files // are not being linted and therefore there can be also CRLF or just CR line-endings. return text.replace(/(\r\n|\r|\n)/g, `$1${' '.repeat(numSpaces)}`); } /** * Rule that copies and interpolates the files that belong to this schematic context. Additionally * a list of file paths can be passed to this rule in order to expose them inside the EJS * template context. * * This allows inlining the external template or stylesheet files in EJS without having * to manually duplicate the file content. */ function buildComponent(options, additionalFiles = {}) { return async (host, ctx) => { const context = ctx; const workspace = await (0, workspace_1.getWorkspace)(host); const project = (0, get_project_1.getProjectFromWorkspace)(workspace, options.project); const defaultComponentOptions = (0, schematic_options_1.getDefaultComponentOptions)(project); // TODO(devversion): Remove if we drop support for older CLI versions. // This handles an unreported breaking change from the @angular-devkit/schematics. Previously // the description path resolved to the factory file, but starting from 6.2.0, it resolves // to the factory directory. const schematicPath = (0, fs_1.statSync)(context.schematic.description.path).isDirectory() ? context.schematic.description.path : (0, path_1.dirname)(context.schematic.description.path); const schematicFilesUrl = './files'; const schematicFilesPath = (0, path_1.resolve)(schematicPath, schematicFilesUrl); // Add the default component option values to the options if an option is not explicitly // specified but a default component option is available. Object.keys(options) .filter(key => options[key] == null && defaultComponentOptions[key]) .forEach(key => (options[key] = defaultComponentOptions[key])); if (options.path === undefined) { options.path = buildDefaultPath(project); } options.standalone = await (0, schematic_options_1.isStandaloneSchematic)(host, options); if (!options.standalone) { 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.prefix); (0, validation_1.validateHtmlSelector)(options.selector); // In case the specified style extension is not part of the supported CSS supersets, // we generate the stylesheets with the "css" extension. This ensures that we don't // accidentally generate invalid stylesheets (e.g. drag-drop-comp.styl) which will // break the Angular CLI project. See: https://github.com/angular/components/issues/15164 if (!supportedCssExtensions.includes(options.style)) { options.style = schema_1.Style.Css; } // Object that will be used as context for the EJS templates. const baseTemplateContext = { ...core_1.strings, 'if-flat': (s) => (options.flat ? '' : s), ...options, }; // Key-value object that includes the specified additional files with their loaded content. // The resolved contents can be used inside EJS templates. const resolvedFiles = {}; for (let key in additionalFiles) { if (additionalFiles[key]) { const fileContent = (0, fs_1.readFileSync)((0, path_1.join)(schematicFilesPath, additionalFiles[key]), 'utf-8'); // Interpolate the additional files with the base EJS template context. resolvedFiles[key] = (0, core_1.template)(fileContent)(baseTemplateContext); } } const templateSource = (0, schematics_1.apply)((0, schematics_1.url)(schematicFilesUrl), [ options.skipTests ? (0, schematics_1.filter)(path => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(), options.inlineStyle ? (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)(), // Treat the template options as any, because the type definition for the template options // is made unnecessarily explicit. Every type of object can be used in the EJS template. (0, schematics_1.applyTemplates)({ indentTextContent, resolvedFiles, ...baseTemplateContext }), // TODO(devversion): figure out why we cannot just remove the first parameter // See for example: angular-cli#schematics/angular/component/index.ts#L160 (0, schematics_1.move)(null, parsedPath.path), ]); return () => (0, schematics_1.chain)([ (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([addDeclarationToNgModule(options), (0, schematics_1.mergeWith)(templateSource)])), ])(host, context); }; } exports.buildComponent = buildComponent; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQtY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9zY2hlbWF0aWNzL3V0aWxzL2J1aWxkLWNvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOzs7QUFFSCwrQ0FBMEY7QUFDMUYsMkRBYW9DO0FBRXBDLGlFQUF1RjtBQUN2RiwrREFBZ0U7QUFDaEUscUVBQW1FO0FBQ25FLHlFQUFpRztBQUNqRyx1RUFBaUU7QUFDakUsdUVBQTRFO0FBQzVFLG1GQUF5RTtBQUN6RSxxRUFBZ0c7QUFDaEcsMkJBQTBDO0FBQzFDLCtCQUE0QztBQUM1QyxpQ0FBaUM7QUFDakMsK0NBQXNEO0FBQ3RELDJEQUFzRjtBQUV0Rjs7O0dBR0c7QUFDSCxTQUFTLGdCQUFnQixDQUFDLE9BQXFDO0lBQzdELE1BQU0sSUFBSSxHQUFHLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDLElBQUksT0FBTyxDQUFDLFVBQVUsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLE9BQU8sQ0FBQyxJQUFJLE9BQU8sQ0FBQztJQUV0RixNQUFNLGNBQWMsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLFdBQVcsS0FBSyw4QkFBVyxDQUFDLFdBQVcsQ0FBQyxDQUFDLENBQUMsS0F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