How to use @schematics/angular - 10 common examples

To help you get started, we’ve selected a few @schematics/angular examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github maciejtreder / ng-toolkit / schematics / utils / index.ts View on Github external
export function getServerDistFolder(tree: Tree, options: any): string {
    const cliConfig: any = JSON.parse(getFileContent(tree, `${options.directory}/angular.json`));
    // console.log(getFileContent(tree, `${options.directory}/angular.json`));
    const project: any = cliConfig.projects[options.project].architect;
    for (let property in project) {
        if (project.hasOwnProperty(property) && project[property].builder === '@angular-devkit/build-angular:server') {
            return project[property].options.outputPath;
        }
    }
    return '';
}
github nstudio / xplat / src / xplat-helper / index_spec.ts View on Github external
const files = tree.files;
    // console.log(files);

    // xplat helpers
    expect(files.indexOf('/xplat/nativescript/utils/@nativescript/core.ts')).toBeGreaterThanOrEqual(0);
    expect(files.indexOf('/xplat/nativescript/utils/@nativescript/ui.ts')).toBeGreaterThanOrEqual(0);
    expect(files.indexOf('/xplat/nativescript/utils/@nativescript/angular/core.ts')).toBeGreaterThanOrEqual(0);

    // should update tsconfig files
    let filePath = '/tsconfig.json';
    let fileContent = JSON.parse(getFileContent(tree, filePath));
    // console.log(fileContent);
    expect(fileContent.compilerOptions.paths['@nativescript/*'][0]).toBe('xplat/nativescript/utils/@nativescript/*');

    filePath = '/apps/nativescript-foo/tsconfig.json';
    fileContent = JSON.parse(getFileContent(tree, filePath));
    // console.log(fileContent);
    expect(fileContent.compilerOptions.paths['@nativescript/*'][0]).toBe('../../xplat/nativescript/utils/@nativescript/*');
  });
github nstudio / xplat / src / xplat-helper / index_spec.ts View on Github external
npmScope: 'testing',
      prefix: 'tt',
      platforms: 'web,nativescript'
    };

    appTree = schematicRunner.runSchematic('xplat', optionsXplat, appTree);
    const appOptions: AppWebOptions = {
      name: 'foo',
      prefix: 'tt',
      e2eTestRunner: 'cypress'
    };
    // console.log('appTree:', appTree);
    appTree = await schematicRunner.runSchematicAsync('app', appOptions, appTree).toPromise();
    
    const cypressJsonPath = '/apps/web-foo-e2e/cypress.json';
    let fileContent = getFileContent(appTree, cypressJsonPath);
    let cypressJson = JSON.parse(fileContent);
    expect(cypressJson.supportFile).toBe(false);

    const options: HelperOptions = { 
      name: 'applitools',
      platforms: 'web'
     };
    // console.log('appTree:', appTree);
    let tree;

    expect(
      () => (tree = schematicRunner.runSchematic('xplat-helper', options, appTree))
    ).toThrowError(
      `The xplat-helper "applitools" requires the --target flag.`
    );
  });
github akveo / nebular / src / framework / theme / schematics / ng-add / index.spec.ts View on Github external
it('should not add NoopAnimationsModule if BrowserAnimationsModule is set up', () => {
    const workspace = getWorkspace(appTree);
    const project = getProjectFromWorkspace(workspace);

    // Simulate the case where a developer uses `ng-add` on an Angular CLI project which already
    // explicitly uses the `BrowserAnimationsModule`. It would be wrong to forcibly change
    // to noop animations.
    const fileContent = addModuleImportToRootModule(appTree, 'BrowserAnimationsModule',
      '@angular/platform-browser/animations', project);
    runSetupSchematic({ animations: false });

    expect(fileContent).not.toContain('NoopAnimationsModule',
      'Expected the project app module to not import the "NoopAnimationsModule".');
  });
});
github NG-ZORRO / ng-zorro-antd / schematics / ng-add / setup-project / theming.ts View on Github external
// unnecessary path segments and windows backslash delimiters.
    const customThemePath = normalize(join(project.sourceRoot, defaultCustomThemeFilename));

    if (host.exists(customThemePath)) {
      console.log();
      console.warn(chalk.yellow(`Cannot create a custom NG-ZORRO theme because
          ${chalk.bold(customThemePath)} already exists. Skipping custom theme generation.`));
      return;
    }

    host.create(customThemePath, themeContent);
    addThemeStyleToTarget(project, 'build', host, customThemePath, workspace);
    return;
  }

  const insertion = new InsertChange(stylesPath, 0, themeContent);
  const recorder = host.beginUpdate(stylesPath);

  recorder.insertLeft(insertion.pos, insertion.toAdd);
  host.commitUpdate(recorder);
}
github ng-matero / ng-matero / schematics / ng-add / setup-project.ts View on Github external
return (host: Tree) => {
    const workspace = getWorkspace(host);
    const project = getProjectFromWorkspace(workspace, options.project);
    const appModulePath = getAppModulePath(host, getProjectMainFile(project));

    if (options.animations) {
      // In case the project explicitly uses the NoopAnimationsModule, we should print a warning
      // message that makes the user aware of the fact that we won't automatically set up
      // animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
      // is already configured, we would cause unexpected behavior and runtime exceptions.
      if (hasNgModuleImport(host, appModulePath, 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.`
          )
        );
      }
github positive-js / mosaic / packages / mosaic / schematics / ng-add / setup-project.ts View on Github external
return (host: Tree) => {

        const workspace = getWorkspace(host);
        const project = getProjectFromWorkspace(workspace, options.project);

        const appModulePath = getAppModulePath(host, getProjectMainFile(project));

        if (options.animations) {
            if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
                console.warn(chalk.red(`Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
                    `because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please manually ` +
                    `set up browser animations.`));

                return;
            }

            addModuleImportToRootModule(host, browserAnimationsModuleName,
                '@angular/platform-browser/animations', project);
        } else if (!hasNgModuleImport(host, appModulePath, browserAnimationsModuleName)) {
            // Do not add the NoopAnimationsModule module if the project already explicitly uses
            // the BrowserAnimationsModule.
            addModuleImportToRootModule(host, noopAnimationsModuleName,
github SAP / fundamental-ngx / libs / core / schematics / ng-add / index.ts View on Github external
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;
github intershop / intershop-pwa / schematics / src / page / factory.js View on Github external
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';
github intershop / intershop-pwa / schematics / src / page / factory.js View on Github external
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) {