Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (tree: Tree) => {
// tslint:disable-next-line:no-non-null-assertion
const modulePath = getAppModulePath(tree, getProject(tree, options.project)!.architect!.build!.options!.main);
if (options.animations) {
if (hasModuleImport(tree, modulePath, noopAnimationsModuleName)) {
return console.warn(chalk.red(`Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
`because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please manually ` +
`set up browser animations.`));
}
addImportToRootModule(tree, browserAnimationsModuleName,
'@angular/platform-browser/animations', modulePath);
console.log(chalk.green(`✅️ Added ${browserAnimationsModuleName} to root module.`));
} else if (!hasModuleImport(tree, modulePath, browserAnimationsModuleName)) {
addImportToRootModule(tree, noopAnimationsModuleName,
'@angular/platform-browser/animations', modulePath);
console.log(chalk.green(`✅️ Added ${noopAnimationsModuleName} to root module.`));
}
return tree;
function determineRoutingModule(host, options) {
const project = project_1.getProject(host, options.project);
let routingModuleLocation;
let child;
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';
export function applyNameAndPath(
artifact: string,
host: Tree,
options: {
project?: string;
name?: string;
path?: string;
restricted?: boolean;
flat?: boolean;
artifactFolder?: boolean;
}
) {
let path = options.path;
let name = options.name;
const project = getProject(host, options.project);
// remove possible added path from root
if (name && name.startsWith('src/app/')) {
name = name.substr(8);
}
const parsedPath = parseName(path || buildDefaultPath(project), name);
name = parsedPath.name;
if (artifact) {
name = name.replace(new RegExp(`\-?${artifact}$`), '');
}
if (!options.restricted) {
path = parsedPath.path;
}
if (options.artifactFolder) {
function detectExtension(artifact, host, options) {
const project = project_1.getProject(host, options.project);
let extension = options.extension;
const regex = /extensions\/([a-z][a-z0-9-]+)/;
const requestDestination = core_1.normalize(`${options.path}/${options.name}`);
if (regex.test(requestDestination)) {
extension = requestDestination.match(regex)[1];
}
let path = options.path;
if (options.restricted) {
if (!extension) {
let rootLocation;
if (artifact === 'cms') {
rootLocation = 'shared/';
}
else if (['page', 'extension'].includes(artifact)) {
rootLocation = '';
}
return (host, context) => {
if (!options.project) {
throw new SchematicsException('Option (project) is required.');
}
const project = getProject(host, options.project);
if (options.path === undefined) {
options.path = buildDefaultPath(project);
}
options.module = findRoutingModuleFromOptions(host, options);
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
options.selector = options.selector ? options.selector : buildSelector(options, project.prefix);
validateName(options.name);
validateHtmlSelector(options.selector);
const templateSource = apply(url('./files'), [
return (tree, _context) => {
const workspace = config_1.getWorkspace(tree);
const project = project_1.getProject(tree, options.project);
const projectName = options.project;
if (!project.sourceRoot && !project.root) {
project.sourceRoot = "src";
}
else if (!project.sourceRoot) {
project.sourceRoot = path.join(project.root, "src");
}
const architect = workspace.projects[projectName].architect;
if (!architect)
throw new Error(`expected node projects/${projectName}/architect in angular.json`);
architect["build-electron"] = {
builder: "@richapps/ngtron:build",
options: {
browserTarget: projectName + ":build",
electronMain: project.sourceRoot + "/electron.ts"
}
export function getProjectObject(tree: Tree, projectName: string) {
const workspace = getWorkspace(tree);
const project = getProject(workspace, projectName);
if (!project) {
throw new SchematicsException(`Couldn't find project "${projectName}" in the workspace!`);
}
return project;
}
return (host: Tree, context: SchematicContext) => {
const project = getProject(host, options.project);
return mergeWith(
apply(url(`./files`), [
template({
tmpl: ''
}),
move(project.root)
]));
}
}