How to use the @angular/cdk/schematics.getProjectFromWorkspace function in @angular/cdk

To help you get started, we’ve selected a few @angular/cdk 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 angular / components / src / lib / schematics / ng-add / index.spec.ts View on Github external
it('should create a custom theme file if no SCSS file could be found', () => {
    // TODO(devversion): do not re-create test app here.
    appTree = createTestApp(runner, {style: 'css'});

    const tree = runner.runSchematic('ng-add-setup-project', {theme: 'custom'}, appTree);
    const workspace = getWorkspace(tree);
    const project = getProjectFromWorkspace(workspace);
    const expectedStylesPath = normalize(`/${project.root}/src/custom-theme.scss`);

    expect(tree.files).toContain(expectedStylesPath, 'Expected a custom theme file to be created');
    expectProjectStyleFile(project, 'projects/material/src/custom-theme.scss');
  });
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-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 NG-ZORRO / ng-zorro-antd / schematics / ng-add / setup-project / add-animations-module.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.log();
        return console.log(chalk.yellow(`Could not set up "${chalk.blue(browserAnimationsModuleName)}" ` +
          `because "${chalk.blue(noopAnimationsModuleName)}" is already imported. Please manually ` +
          `set up browser animations.`));
      }
      addModuleImportToRootModule(host, browserAnimationsModuleName,
        animationsModulePath, project);
    } else if (!hasNgModuleImport(host, appModulePath, browserAnimationsModuleName)) {
      addModuleImportToRootModule(host, noopAnimationsModuleName,
        animationsModulePath, project);
    }
github NG-ZORRO / ng-zorro-antd / schematics / ng-add / index.spec.ts View on Github external
it('should add custom theme', async () => {
    appTree = await createTestApp(runner, {style: 'less'});
    const tree = await runner.runSchematicAsync('ng-add-setup-project', {theme: true}, appTree).toPromise();
    const workspace = getWorkspace(tree);
    const project = getProjectFromWorkspace(workspace);

    const customThemePath = normalize(join(project.sourceRoot, 'styles.less'));
    const buffer = tree.read(customThemePath);
    const themeContent = buffer!.toString();

    expect(themeContent).toContain(`@import "../node_modules/ng-zorro-antd/ng-zorro-antd.less`);
    expect(themeContent).toContain(`@ant-prefix: ant;`);
    expect(themeContent).toContain(`@primary-color: @blue-6;`);
    expect(getProjectTargetOptions(project, 'build').styles)
    .toContain('projects/ng-zorro/src/styles.less');
  });
github kamiazya / ngx-speech-recognition / projects / ngx-speech-recognition / schematics / ng-add / index.spec.ts View on Github external
it('addNgxFaceApiJsModule works', async () => {
    const runner = new SchematicTestRunner('schematics', collectionPath);
    const tree = await runner.runSchematicAsync('ng-add', {}, createTestApp()).toPromise();

    const workspace = getWorkspace(tree);
    const project = getProjectFromWorkspace(workspace);
    const appModulePath = getAppModulePath(tree, getProjectMainFile(project));

    if (appModulePath) {
      const appModuleContent = getFileContent(tree, appModulePath);
      expect(appModuleContent).toMatch(`${NGX_SPEECH_RECOGNITION_MODULE_NAME}.forRoot`);
    }
  });
});
github NG-ZORRO / ng-zorro-antd / schematics / ng-add / setup-project / theming.ts View on Github external
return function (host: Tree): Tree {
    const workspace = getWorkspace(host);
    const project = getProjectFromWorkspace(workspace, options.project) as WorkspaceProject;

    if (options.theme) {
      insertCustomTheme(project, options.project, host, workspace);
    } else {
      insertCompiledTheme(project, host, workspace);
    }

    return host;
  };
}
github positive-js / mosaic / packages / mosaic / schematics / ng-add / theming / theming.ts View on Github external
return function(host: Tree): Tree {
        const workspace = getWorkspace(host);
        const project = getProjectFromWorkspace(workspace, options.project);
        const themeName = options.theme || 'indigo-pink';

        if (themeName === 'custom') {
            insertCustomTheme(project, options.project, host, workspace);
        } else {
            insertPrebuiltTheme(project, host, themeName, workspace);
        }

        return host;
    };
}
github angular / components / src / lib / schematics / ng-add / index.spec.ts View on Github external
function overwriteTargetBuilder(tree: Tree, targetName: string, newBuilder: string) {
      const workspace = getWorkspace(tree);
      const project = getProjectFromWorkspace(workspace);
      const targetConfig = project.architect && project.architect[targetName] ||
                           project.targets && project.targets[targetName];
      targetConfig['builder'] = newBuilder;
      tree.overwrite('/angular.json', JSON.stringify(workspace, null, 2));
    }
github akveo / nebular / src / framework / theme / schematics / ng-add / register-theme / index.ts View on Github external
return (tree: Tree) => {
    const workspace = getWorkspace(tree);
    const project = getProjectFromWorkspace(workspace, options.project);

    const themePath = `./node_modules/@nebular/theme/styles/prebuilt/${options.theme}.css`;

    addStyleToTarget(project, 'build', tree, themePath, workspace);

    return tree;
  }
}