Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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(optionName => options[optionName] == null && defaultComponentOptions[optionName])
.forEach(optionName => options[optionName] = defaultComponentOptions[optionName]);
if (options.path === undefined) {
// TODO(jelbourn): figure out if the need for this `as any` is a bug due to two different
// incompatible `WorkspaceProject` classes in @angular-devkit
options.path = buildDefaultPath(project as any);
}
options.module = findModuleFromOptions(host, options);
const parsedPath = parseName(options.path!, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
options.selector = options.selector || buildSelector(options, project.prefix);
validateName(options.name);
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!)) {
// TODO: Cast is necessary as we can't use the Style enum which has been introduced
// within CLI v7.3.0-rc.0. This would break the schematic for older CLI versions.
options.style = 'css' as Style;
function createPath(name: string) {
const pathParts = name.split('/');
name = pathParts.pop();
pathParts.push(strings.dasherize(name));
return parseName(`${ROOT}/${pathParts.join('/') }`, name);
}
return (host: Tree, _context: SchematicContext) => {
const workspace = getWorkspace(host);
const projectName = options.project || Object.keys(workspace.projects)[0];
const project = getProject(host, projectName);
if (options.path === undefined) {
options.path = buildDefaultPath(project);
}
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
template({
...strings,
'if-flat': (s: string) => (options.flat ? '' : s),
...options
}),
move(parsedPath.path)
]);
return chain([
branchAndMerge(
chain([
function setupOptions(options: MenuOptions, host: Tree): void {
const workspace = getWorkspace(host);
if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
}
const project = workspace.projects[options.project];
if (options.path === undefined) {
const projectDirName = project.projectType === 'application' ? 'app' : 'lib';
options.path = `/${project.root}/src/${projectDirName}`;
}
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
}
return (host: Tree, context: SchematicContext) => {
const rootPath = getRootPath(host, options);
smartPath(rootPath, options);
if (!options.path) {
options.path = `${rootPath}/shared/pipes`;
}
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
options.module = findModuleFromOptions(host, options);
const ngOptions = {
...options,
skipImport: true
};
return chain([
externalSchematic('@schematics/angular', 'pipe', ngOptions),
addNgModule(options)
])(host, context);
};
return (host: Tree, context: SchematicContext) => {
const rootPath = getRootPath(host, options);
smartPath(rootPath, options);
if (!options.path) {
options.path = `${rootPath}/shared/modules`;
}
const parsedPath = parseName(options.path, options.name);
options.path = parsedPath.path;
options.module = findModuleFromOptions(host, options);
const templateSource = apply(url('./files'), [
options.routing ? noop() : filter(path => !path.endsWith('-routing.module.ts')),
template({
...strings,
'if-flat': (s: string) => options.flat ? '' : s,
...options
}),
move(options.path)
]);
return chain([
return (host: Tree, context: SchematicContext) => {
const rootPath = getRootPath(host, options);
if (!options.path) {
options.path = `${rootPath}/services`;
}
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
return chain([
externalSchematic('@schematics/angular', 'service', options)
])(host, context);
};
}
const addNativeScriptFiles = (component: ComponentInfo) => {
const parsedTemplate = parseName('', component.templatePath);
const nsTemplateName = insertExtension(parsedTemplate.name, extensions.ns);
const { name: stylesheetName } = parseName('', component.stylesheetPath);
const nsStylesheetName = insertExtension(stylesheetName, extensions.ns);
const templateSource = apply(url('./_files'), [
template({
name: component.name,
path: parsedTemplate.path,
templateName: nsTemplateName,
stylesheetName: nsStylesheetName,
}),
]);
return mergeWith(templateSource);
};
return (host: Tree, context: SchematicContext) => {
if (options.path === undefined) {
options.path = getProjectPath(host, options);
}
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
const targetPath = options.flat
? options.path
: `${options.path}/${options.name}`;
const prefix = getProject(host, {}).prefix;
const selector = `${prefix}-${options.name}`;
const templateSource = apply(url('./files'), [
template({
...strings,
selector,
...options,
}),