(
options: ComponentOptions,
additionalFiles: {[key: string]: string} = {},
)
| 152 | * to manually duplicate the file content. |
| 153 | */ |
| 154 | export function buildComponent( |
| 155 | options: ComponentOptions, |
| 156 | additionalFiles: {[key: string]: string} = {}, |
| 157 | ): Rule { |
| 158 | return async (host, ctx) => { |
| 159 | const context = ctx as FileSystemSchematicContext; |
| 160 | const workspace = await readWorkspace(host); |
| 161 | const project = getProjectFromWorkspace(workspace, options.project); |
| 162 | const defaultComponentOptions = getDefaultComponentOptions(project); |
| 163 | |
| 164 | // TODO(devversion): Remove if we drop support for older CLI versions. |
| 165 | // This handles an unreported breaking change from the @angular-devkit/schematics. Previously |
| 166 | // the description path resolved to the factory file, but starting from 6.2.0, it resolves |
| 167 | // to the factory directory. |
| 168 | const schematicPath = statSync(context.schematic.description.path).isDirectory() |
| 169 | ? context.schematic.description.path |
| 170 | : dirname(context.schematic.description.path); |
| 171 | |
| 172 | const schematicFilesUrl = './files'; |
| 173 | const schematicFilesPath = resolve(schematicPath, schematicFilesUrl); |
| 174 | |
| 175 | // Add the default component option values to the options if an option is not explicitly |
| 176 | // specified but a default component option is available. |
| 177 | Object.keys(options) |
| 178 | .filter( |
| 179 | key => |
| 180 | options[key as keyof ComponentOptions] == null && |
| 181 | defaultComponentOptions[key as keyof ComponentOptions], |
| 182 | ) |
| 183 | .forEach( |
| 184 | key => |
| 185 | ((options as any)[key] = (defaultComponentOptions as ComponentOptions)[ |
| 186 | key as keyof ComponentOptions |
| 187 | ]), |
| 188 | ); |
| 189 | |
| 190 | if (options.path === undefined) { |
| 191 | options.path = buildDefaultPath(project); |
| 192 | } |
| 193 | |
| 194 | options.standalone = await isStandaloneSchematic(host, options); |
| 195 | |
| 196 | if (!options.standalone) { |
| 197 | // TODO: Remove ext option when the Angular CLI looks for both candidate locations. |
| 198 | options.module = findModuleFromOptions(host, {...options, moduleExt: 'module.ts'}); |
| 199 | } |
| 200 | |
| 201 | const parsedPath = parseName(options.path!, options.name); |
| 202 | |
| 203 | options.name = parsedPath.name; |
| 204 | options.path = parsedPath.path; |
| 205 | options.selector = options.selector || buildSelector(options, project.prefix); |
| 206 | |
| 207 | validateHtmlSelector(options.selector!); |
| 208 | |
| 209 | // In case the specified style extension is not part of the supported CSS supersets, |
| 210 | // we generate the stylesheets with the "css" extension. This ensures that we don't |
| 211 | // accidentally generate invalid stylesheets (e.g. drag-drop-comp.styl) which will |
no test coverage detected