return async (host: Tree) => { const appProject = options.relatedAppName; const workspace = await getWorkspace(host); const project = workspace.projects.get(appProject); if (!project) { throw new SchematicsException(`Project name "${appProject}" doesn't not exist.`); } const root = join(normalize(project.root), 'e2e'); project.targets.add({ name: 'e2e', builder: Builders.Protractor, options: { protractorConfig: `${root}/protractor.conf.js`, devServerTarget: `${options.relatedAppName}:serve`, }, configurations: { production: { devServerTarget: `${options.relatedAppName}:serve:production`, }, }, }); const lintTarget = project.targets.get('lint'); if (lintTarget && lintTarget.options && Array.isArray(lintTarget.options.tsConfig)) { lintTarget.options.tsConfig = lintTarget.options.tsConfig.concat(`${root}/tsconfig.json`); } return chain([ updateWorkspace(workspace), mergeWith( apply(url('./files'), [ applyTemplates({ utils: strings, ...options, relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(root), }), move(root), ])), ]); };
return (host: Tree, context: SchematicContext) => { if (!options.name) { throw new SchematicsException(`Invalid options, "name" is required.`); } validateProjectName(options.name); let newProjectRoot = ''; try { const workspace = getWorkspace(host); newProjectRoot = workspace.newProjectRoot || ''; } catch { } const appDir = `${newProjectRoot}/${options.name}`; // If the project already has some deps installed, Bazel should use existing // versions. const existingVersions = { Angular: findVersion(options.name, '@angular/core', host), RxJs: findVersion(options.name, 'rxjs', host), }; Object.keys(existingVersions).forEach((name: 'Angular' | 'RxJs') => { const version = existingVersions[name] as string; if (version) { context.logger.info(`Bazel will reuse existing version for ${name}: ${version}`); } }); const workspaceVersions = { 'ANGULAR_VERSION': existingVersions.Angular || clean(latestVersions.Angular), 'RXJS_VERSION': existingVersions.RxJs || clean(latestVersions.RxJs), // TODO(kyliau): Consider moving this to latest-versions.ts 'RULES_SASS_VERSION': '1.15.1', }; return mergeWith(apply(url('./files'), [ applyTemplates({ utils: strings, ...options, 'dot': '.', ...workspaceVersions, }), move(appDir), ])); };
export default function (options: Schema): Rule { const path = 'packages/' + options.name .replace(/^@/, '') .replace(/-/g, '_'); // Verify if we need to create a full project, or just add a new schematic. const source = apply(url('./project-files'), [ template({ ...options as object, dot: '.', path, }), ]); return chain([ mergeWith(source), addPackageToMonorepo(options, path), ]); }
return (host: Tree) => { const workspace = getWorkspace(host); if (!options.project) { throw new SchematicsException('Option (project) is required.'); } const project = workspace.projects[options.project]; 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; options.selector = options.selector || buildSelector(options, project.prefix); validateName(options.name); validateHtmlSelector(options.selector); const templateSource = apply(url('./files'), [ options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')), options.inlineStyle ? filter(path => !path.endsWith('.__styleext__')) : noop(), options.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(), template({ ...strings, 'if-flat': (s: string) => options.flat ? '' : s, ...options, }), move(parsedPath.path), ]); return chain([ branchAndMerge(chain([ addDeclarationToNgModule(options), mergeWith(templateSource), ])), options.lintFix ? applyLintFix(options.path) : noop(), ]); };
return (host: Tree, context: SchematicContext) => { const name = options.name || getWorkspace(host).defaultProject; if (!name) { throw new Error('Please provide a name for Bazel workspace'); } validateProjectName(name); // If the project already has some deps installed, Bazel should use existing // versions. const existingVersions = { Angular: findVersion('@angular/core', host), RxJs: findVersion('rxjs', host), }; Object.keys(existingVersions).forEach((name: 'Angular' | 'RxJs') => { const version = existingVersions[name] as string; if (version) { context.logger.info(`Bazel will reuse existing version for ${name}: ${version}`); } }); const workspaceVersions = { 'RULES_NODEJS_VERSION': '0.16.5', 'RULES_TYPESCRIPT_VERSION': '0.22.1', 'ANGULAR_VERSION': existingVersions.Angular || clean(latestVersions.Angular), 'RXJS_VERSION': existingVersions.RxJs || clean(latestVersions.RxJs), // TODO(kyliau): Consider moving this to latest-versions.ts 'RULES_SASS_VERSION': '1.15.1', }; return mergeWith(apply(url('./files'), [ applyTemplates({ utils: strings, name, 'dot': '.', ...workspaceVersions, routing: hasRoutingModule(host), sass: hasSassStylesheet(host), }), ])); };
return (host: Tree, context: SchematicContext) => { if (options.module) { options.module = findModuleFromOptions(host, options); } const templateSource = apply(url('./files'), [ options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')), template({ ...stringUtils, 'if-flat': (s: string) => stringUtils.group( options.flat ? '' : s, options.group ? 'reducers' : '' ), ...(options as object), dot: () => '.', }), move(sourceDir), ]); return chain([ branchAndMerge( chain([ filter(path => !path.includes('node_modules')), addReducerToState(options), ]) ), branchAndMerge( chain([ filter( path => path.endsWith('.module.ts') && !path.endsWith('-routing.module.ts') ), addReducerImportToNgModule(options), mergeWith(templateSource), ]) ), ])(host, context); };
return async (host: Tree) => { const workspace = await getWorkspace(host); const project = workspace.projects.get(options.project as string); if (!project) { throw new SchematicsException(`Invalid project name (${options.project})`); } 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; options.selector = options.selector || buildSelector(options, project.prefix || ''); validateHtmlSelector(options.selector); // todo remove these when we remove the deprecations options.skipTests = options.skipTests || !options.spec; const templateSource = apply(url('./files'), [ options.skipTests ? filter(path => !path.endsWith('.spec.ts.template')) : noop(), applyTemplates({ ...strings, 'if-flat': (s: string) => options.flat ? '' : s, ...options, }), move(parsedPath.path), ]); return chain([ addDeclarationToNgModule(options), mergeWith(templateSource), options.lintFix ? applyLintFix(options.path) : noop(), ]); };
return async (host: Tree) => { if (options.path === undefined) { options.path = await createDefaultPath(host, options.project as string); } const parsedPath = parseName(options.path, options.name); options.name = parsedPath.name; options.path = parsedPath.path; const templateSource = apply(url('./files'), [ applyTemplates({ ...strings, ...options, }), move(parsedPath.path), ]); return chain([ mergeWith(templateSource), options.lintFix ? applyLintFix(options.path) : noop(), ]); };
return (host: Tree) => { let newProjectRoot = ''; try { const workspace = getWorkspace(host); newProjectRoot = workspace.newProjectRoot || ''; } catch { } const srcDir = `${newProjectRoot}/${options.name}/src`; return mergeWith( apply( url('./files'), [ applyTemplates({ utils: strings, ...options, 'dot': '.', }), move(srcDir), ]), MergeStrategy.Overwrite); };
return (host: Tree) => { validateProjectName(options.name); const workspace = getWorkspace(host); const appDir = options.projectRoot !== undefined ? options.projectRoot : `${workspace.newProjectRoot}/${options.name}`; return chain([ addAppToWorkspaceFile(options, workspace), mergeWith( apply(url('./files'), [ template({ utils: strings, ...options, 'dot': '.', appDir, }), move(appDir), ])), ]); };