How to use the @schematics/angular/utility/config.getWorkspace function in @schematics/angular

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 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 / utils / build-component.ts View on Github external
return (host: Tree, context: FileSystemSchematicContext) => {
    const workspace = getWorkspace(host);
    const project = getProjectFromWorkspace(workspace, options.project);
    const defaultZorroComponentOptions = getDefaultComponentOptions(project);
    let modulePrefix = '';
    // TODO(devversion): Remove if we drop support for older CLI versions.
    // This handles an unreported breaking change from the @angular-devkit/schematics. Previously
    // the description path resolved to the factory file, but starting from 6.2.0, it resolves
    // to the factory directory.
    const schematicPath = statSync(context.schematic.description.path).isDirectory() ?
      context.schematic.description.path :
      dirname(context.schematic.description.path);

    const schematicFilesUrl = './files';
    const schematicFilesPath = resolve(schematicPath, schematicFilesUrl);

    options.style = options.style || Style.Css;
    // Add the default component option values to the options if an option is not explicitly
github SoCreate / angular-playground / packages / angular-playground / schematics / src / utils / project.ts View on Github external
export function getProject(
  host: Tree,
  options: { project?: string | undefined; path?: string | undefined },
  typeFilter: 'application' | 'library' | null = null,
): WorkspaceProject {
  const workspace = getWorkspace(host);

  if (!options.project) {
    const projectNames = Object.keys(workspace.projects);
    // can have no projects if created with `ng new  --createApplication=false`
    if (projectNames.length === 0) {
      throw new Error('Your app must have at least 1 project to use Playground.');
    }
    // if type filter is not set, use first project
    let firstFilteredProject = projectNames[0];
    if (typeFilter) {
      // apply filter
      for (const projectName in workspace.projects) {
        if (workspace.projects[projectName].projectType === typeFilter) {
          firstFilteredProject = projectName;
          break;
        }
github manfredsteyer / ngx-build-plus / lib / schematics / externals / index.ts View on Github external
function getProject(tree: Tree, options: any) {
  const workspace = getWorkspace(tree);
  if (!options.project) {
    options.project = Object.keys(workspace.projects)[0];
  }
  const project = workspace.projects[options.project];

  // compensate for lacking sourceRoot property
  // e. g. when project was migrated to ng7, sourceRoot is lacking
  if (!project.sourceRoot && !project.root) {
    project.sourceRoot = 'src';
  }
  else if (!project.sourceRoot) {
    project.sourceRoot = path.join(project.root, 'src');
  }

  return project;
}
github manfredsteyer / ngx-build-plus / lib / schematics / externals / index.ts View on Github external
function addScriptsToProject(tree: Tree, options: any): Rule {
  const workspace = getWorkspace(tree);
  if (!options.project) {
    options.project = Object.keys(workspace.projects)[0];
  }
  const project = workspace.projects[options.project];
  
  if (!project.architect || !project.architect.build || !project.architect.build.options) {
    return noop();
  }

  const buildOptions = project.architect.build.options as BrowserBuilderBaseOptions;

  if (!buildOptions) return noop();
  
  if (!buildOptions.scripts) {
    buildOptions.scripts = [];
  }
github DevExpress / devextreme-schematics / src / view / index.ts View on Github external
function getProjectName(host: Tree, options: any) {
  const projectName = options.project;
  const workspace = getWorkspace(host);
  const projects = Object.keys(workspace.projects);

  return projectName && projects.indexOf(projectName) ? projectName : projects[0];
}
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 BenjaminDobler / ngtron / schematics / ng-add / index.js View on Github external
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"
github NG-ZORRO / ng-zorro-antd / schematics / ng-generate / side-menu / index.ts View on Github external
return (host: Tree) => {
    const workspace = getWorkspace(host);
    const project = getProjectFromWorkspace(workspace, options.project);
    const prefix = options.prefix || project.prefix;
    return chain([
      mergeWith(
        apply(
          url('./files/src'), [
            applyTemplates({
              ...strings,
              ...options,
              prefix
            }),
            move(project.sourceRoot as string),
            forEach((fileEntry: FileEntry) => {
              if (host.exists(fileEntry.path)) {
                host.overwrite(fileEntry.path, fileEntry.content);
              }
github angular / components / src / material / 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 projectIndexFiles = getProjectIndexFiles(project);

    if (!projectIndexFiles.length) {
      throw new SchematicsException('No project index HTML file could be found.');
    }

    projectIndexFiles.forEach(indexFilePath => addBodyClass(host, indexFilePath, 'mat-typography'));

    return host;
  };
}