Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const match = options.name.match(/(.*)\-([a-z0-9]+)/);
if (match && match[1] && match[2]) {
const parent = match[1];
child = match[2];
// tslint:disable-next-line:no-console
console.log(`detected subpage, will insert '${child}' as sub page of '${parent}'`);
routingModuleLocation = options.extension
? `extensions/${options.extension}/pages/${parent}/${parent}-page.module.ts`
: `pages/${parent}/${parent}-page.module.ts`;
}
else {
routingModuleLocation = options.extension
? `extensions/${options.extension}/pages/${options.extension}-routing.module.ts`
: 'pages/app-routing.module.ts';
}
const routingModule = core_1.normalize(`${project_1.buildDefaultPath(project)}/${routingModuleLocation}`);
return Object.assign({}, options, { routingModule,
child });
}
function addRouteToRoutingModule(options) {
const match = options.name.match(/(.*)\-([a-z0-9]+)/);
if (match && match[1] && match[2]) {
const parent = match[1];
child = match[2];
// tslint:disable-next-line:no-console
console.log(`detected subpage, will insert '${child}' as sub page of '${parent}'`);
routingModuleLocation = options.extension
? `extensions/${options.extension}/pages/${parent}/${parent}-page.module.ts`
: `pages/${parent}/${parent}-page.module.ts`;
} else {
routingModuleLocation = options.extension
? `extensions/${options.extension}/pages/${options.extension}-routing.module.ts`
: 'pages/app-routing.module.ts';
}
const routingModule = normalize(`${buildDefaultPath(project)}/${routingModuleLocation}`);
return {
...options,
routingModule,
child,
};
}
function applyNameAndPath(artifact, host, options) {
let path = options.path;
let name = options.name;
const project = project_1.getProject(host, options.project);
// remove possible added path from root
if (name && name.startsWith('src/app/')) {
name = name.substr(8);
}
const parsedPath = parse_name_1.parseName(path || project_1.buildDefaultPath(project), name);
name = parsedPath.name;
if (artifact) {
name = name.replace(new RegExp(`\-?${artifact}$`), '');
}
if (!options.restricted) {
path = parsedPath.path;
}
if (options.artifactFolder) {
// add artifact folder
const containingFolder = `/${artifact}s`;
if (!options.flat && !path.endsWith(containingFolder)) {
path += containingFolder;
}
}
validation_1.validateName(name);
return Object.assign({}, options, { name,
context.schematic.description.path :
dirname(context.schematic.description.path);
const schematicFilesUrl = './files';
const schematicFilesPath = 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((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
return (host: Tree, context: SchematicContext) => {
if (!options.project) {
throw new SchematicsException('Option (project) is required.');
}
const id = getProjectName(options, getWorkspace(host));
const project = getProject(host, id);
if (options.path === undefined) {
options.path = buildDefaultPath(project);
}
options.module = findModuleFromOptions(host, options);
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
validateName(options.name);
console.log(options);
const templateSource = apply(url('./_files'), [
template({
...strings,
...options,
}),
options = applyNameAndPath('extension', host, options);
options = determineArtifactName('extension', host, options);
const operations: Rule[] = [];
operations.push(
mergeWith(
apply(url('./files'), [
template({
...strings,
...options,
}),
move(options.path),
])
)
);
const projectRoot = buildDefaultPath(getProject(host, options.project));
const artifactName = strings.classify(options.name) + 'ExportsModule';
const moduleImportPath = `${projectRoot}/extensions/${strings.dasherize(options.name)}/exports/${strings.dasherize(
options.name
)}-exports.module`;
const sharedModuleOptions = {
module: `${projectRoot}/shared/shared.module.ts`,
artifactName,
moduleImportPath,
};
operations.push(addExportToNgModule(sharedModuleOptions));
operations.push(addImportToNgModule(sharedModuleOptions));
const appModuleOptions = {
module: `${projectRoot}/app.module.ts`,
artifactName,
export function ng2ProcessTree(
tree: Tree,
_context: SchematicContext,
_options: any,
newCode: string,
newMarkup: string,
newImports: [string, string][] = []) {
if (!_options.project) {
throw new SchematicsException('Option (project) is required.');
}
const project = getProject(tree, _options.project);
if (_options.path === undefined) {
_options.path = buildDefaultPath(project);
}
_options.module = findModuleFromOptions(tree, _options);
const codeAction = tree.actions.filter(r => r.path.endsWith('.component.ts'))[0];
const markupActions = tree.actions.filter(r => r.path.endsWith('.component.html'));
const codeSource = readIntoSourceFile(tree, codeAction.path);
const nodes = getSourceNodes(codeSource);
const classNodes = nodes.filter(r => findNodes(r, ts.SyntaxKind.ClassDeclaration).length);
const classDecl = findNodes(classNodes[0], ts.SyntaxKind.ClassDeclaration)[0] as ts.ClassDeclaration;
let inlineTemplate = false;
let template: ts.PropertyAssignment;
const changes = newImports.map(([a, b]) => insertImport(codeSource, codeAction.path, a, b));
const recorder = tree.beginUpdate(codeAction.path);
if (classDecl.decorators) {
const decorator = classDecl.decorators[0];
return (tree: Tree, _context: SchematicContext) => {
if (!_options.project) {
throw new SchematicsException('Option (project) is required.');
}
const project = getProject(tree, _options.project);
if (_options.path === undefined) {
_options.path = buildDefaultPath(project);
}
_options.module = findModuleFromOptions(tree, _options);
const parsedPath = parseName(dirname(normalize(_options.module)), 'not applicable');
_options.metaname = parsedPath.name;
_options.metapath = parsedPath.path;
const metaConfigExists = tree.exists('/src/app/app-chart-config.ts');
if (metaConfigExists) {
return tree;
}
const templateSource = apply(url('./files'), [
applyTemplates({