@angular-devkit/schematics#MergeStrategy TypeScript Examples

The following examples show how to use @angular-devkit/schematics#MergeStrategy. 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: 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 #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 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);
        });
      },
    ]);
  };
}