@angular-devkit/schematics#filter TypeScript Examples

The following examples show how to use @angular-devkit/schematics#filter. 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: templates.ts    From cli with Apache License 2.0 6 votes vote down vote up
/**
 * Schematic rule that copies files into the Angular project.
 *
 * @export
 * @param {CoveoSchema} _options
 * @param {string} [workspaceRootPath='./']      The root path from which the applyTemplates function will start pasting files.
 *                                               The default value is "./" because the file structure is already defined within the ./files directories
 * @param {string} [templateFilePath='./files']  Path containing the files to copy into the Angular project
 * @returns {Rule}
 */
export function createFiles(
  _options: CoveoSchema,
  workspaceRootPath = './',
  templateFilePath = './files',
  customFilter = isNotNodeModuleFile
): Rule {
  return (tree: Tree, context: SchematicContext) => {
    const templateSource = apply(url(templateFilePath), [
      filter(customFilter),
      applyTemplates({
        ..._options,
      }),
      move(normalize(workspaceRootPath)),
      overwriteIfExists(tree),
    ]);

    const rule = mergeWith(templateSource);
    return rule(tree, context);
  };
}
Example #2
Source File: merge-source.rule.ts    From angular-miniprogram with MIT License 6 votes vote down vote up
export function mergeSourceRuleFactory(options: FormsHookOptions) {
  return (tree: Tree) => {
    const angularFormsSource = apply(
      url(path.relative(options.schematicPath, ANGULAR_COMMON_PATH)),
      [
        // todo 过滤掉所有i18n文件
        filter((path) => {
          return path.endsWith('.ts') && !path.startsWith('/test');
        }),
        filter((path) => {
          return !path.endsWith('.spec.ts');
        }),
        // filter((path) => {
        //   return !path.includes('i18n/');
        // }),
        // filter((path) => {
        //   return !filterFileList.some((item) => path.includes(item));
        // }),
        move(SCHEMATICS_COMMON_LIBRARY_PATH),
      ]
    );
    return chain([mergeWith(angularFormsSource, MergeStrategy.Overwrite)]);
  };
}
Example #3
Source File: merge-source.rule.ts    From angular-miniprogram with MIT License 6 votes vote down vote up
export function mergeSourceRuleFactory(options: FormsHookOptions) {
  return (tree: Tree) => {
    const localSourceMap = new Map<string, Buffer>();
    for (let i = 0; i < SCHEMATICS_FORMS_LIBRARY_HOOK_FILE_LIST.length; i++) {
      const filePath = SCHEMATICS_FORMS_LIBRARY_HOOK_FILE_LIST[i];
      if (tree.exists(filePath)) {
        localSourceMap.set(filePath, tree.read(filePath));
      }
    }
    const angularFormsSource = apply(
      url(path.relative(options.schematicPath, ANGULAR_FORMS_PATH)),
      [
        filter((path) => {
          return path.endsWith('.ts') && !path.startsWith('/test');
        }),
        filter((path) => {
          return !path.endsWith('.spec.ts');
        }),
        move(SCHEMATICS_FORMS_LIBRARY_PATH),
      ]
    );
    return chain([
      mergeWith(angularFormsSource, MergeStrategy.Overwrite),
      (tree) => {
        localSourceMap.forEach((content, filePath) => {
          tree.overwrite(filePath, content);
        });
      },
    ]);
  };
}
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(),
     ]);
   };
 }