@angular-devkit/schematics#noop TypeScript Examples

The following examples show how to use @angular-devkit/schematics#noop. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: workspace.ts    From source-map-analyzer with MIT License 6 votes vote down vote up
export function updateWorkspace(
    updaterOrWorkspace:
      | workspaces.WorkspaceDefinition
      | ((workspace: workspaces.WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>),
  ): Rule {
    return async (tree: Tree) => {
      const host = createHost(tree);
  
      if (typeof updaterOrWorkspace === 'function') {
        const { workspace } = await workspaces.readWorkspace('/', host);
  
        const result = await updaterOrWorkspace(workspace);
  
        await workspaces.writeWorkspace(workspace, host);
  
        return result || noop;
      } else {
        await workspaces.writeWorkspace(updaterOrWorkspace, host);
  
        return noop;
      }
    };
  }
Example #2
Source File: schematic.ts    From nx-plugins with MIT License 5 votes vote down vote up
function addDependenciesFromPulumiProjectToPackageJson(
  adapter: BaseAdapter
): Rule {
  return (host: Tree): Rule => {
    const pulumiPackageJson = host.read(
      join(adapter.project.root, 'infrastructure', 'package.json')
    );
    if (!pulumiPackageJson) {
      throw new Error('Can not find generated pulumi package.json');
    }
    const pulumiCloudProviderDependencies = JSON.parse(
      pulumiPackageJson.toString()
    ).dependencies;
    const packageJson = readJsonInTree(host, 'package.json');
    const dependencyList: { name: string; version: string }[] = [];

    for (const name in pulumiCloudProviderDependencies) {
      const version = pulumiCloudProviderDependencies[name];
      if (version) {
        if (!packageJson.dependencies[name]) {
          dependencyList.push({
            name,
            version,
          });
        }
      }
    }

    dependencyList.push(...adapter.addRequiredDependencies());

    if (!dependencyList.length) {
      return noop();
    }

    return addDepsToPackageJson(
      dependencyList.reduce((dictionary, value) => {
        dictionary[value.name] = value.version;
        return dictionary;
      }, {}),
      {}
    );
  };
}
Example #3
Source File: index.ts    From fab-menu with MIT License 5 votes vote down vote up
export default function(options: any): Rule {
  return chain([
    options && options.skipPackageJson ? noop() : addPackageJsonDependencies(),
    options && options.skipPackageJson ? noop() : installPackageJsonDependencies(),
    options && options.skipModuleImport ? noop() : addModuleToImports(options),
    options && options.skipPolyfill ? noop() : addLibAssetsToAssets(options)
  ]);
}
Example #4
Source File: index.ts    From open-source with MIT License 5 votes vote down vote up
export default function (options: ComponentOptions): Rule {
   return async (host: Tree) => {
     const workspace = await getWorkspace(host);
     const project = workspace.projects.get(options.project as string);

     if (options.path === undefined && project) {
       options.path = buildDefaultPath(project);
     }

     if (options.prefix === undefined && project) {
       options.prefix = project.prefix || '';
     }

     options.module = findModuleFromOptions(host, options);

     const parsedPath = parseName(options.path as string, options.name);
     options.name = parsedPath.name;
     options.path = parsedPath.path;
     options.selector =
       options.selector || buildSelector(options, (project && project.prefix) || '');

     validateName(options.name);
     validateHtmlSelector(options.selector);

     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,
       }),
       !options.type
         ? forEach(((file) => {
             return file.path.includes('..')
               ? {
                   content: file.content,
                   path: file.path.replace('..', '.'),
                 }
               : file;
           }) as FileOperator)
         : noop(),
       move(parsedPath.path),
     ]);

     return chain([
       addDeclarationToNgModule(options),
       mergeWith(templateSource),
       options.lintFix ? applyLintFix(options.path) : noop(),
     ]);
   };
 }
Example #5
Source File: index.ts    From open-source with MIT License 5 votes vote down vote up
export default function (options: ModuleOptions): Rule {
  return async (host: Tree) => {
    const workspace = await getWorkspace(host);
    const project = workspace.projects.get(options.project as string);

    if (options.path === undefined) {
      options.path = await createDefaultPath(host, options.project as string);
    }

    if (options.module) {
      options.module = findModuleFromOptions(host, options);
    }

    if (options.prefix === undefined) {
      options.prefix = project?.prefix || '';
    }

    const parsedPath = parseName(options.path, options.name);
    options.name = parsedPath.name;
    options.path = parsedPath.path;

    const templateSource = apply(url('./files'), [
      applyTemplates({
        ...strings,
        'if-flat': (s: string) => (options.flat ? '' : s),
        ...options,
      }),
      move(parsedPath.path),
    ]);
    const moduleDasherized = strings.dasherize(options.name);
    const controlDasherized = strings.dasherize(options.controlName);
    const controlPath = `${options.path}/${
      !options.flat ? `${moduleDasherized}/` : ''
    }${options.controlPath}${options.flat ? `/${controlDasherized}` : ''}`;

    const controlOptions: ControlOptions = {
      project: options.project,
      path: controlPath,
      name: controlDasherized,
      type: options.type,
      id: options.id || 'CONTROL',
      instance: options.instance || 'Control',
      flat: options.flat,
      prefix: options.prefix,
      prefixInterface: options.prefixInterface,
      prefixClass: options.prefixClass,
    };

    return chain([
      mergeWith(templateSource),
      schematic('control', controlOptions),
      options.lintFix ? applyLintFix(options.path) : noop(),
    ]);
  };
}