From c64d86769e25b31b60b2e9c598d032bc67753ff2 Mon Sep 17 00:00:00 2001 From: Brent Schmidt Date: Mon, 3 Oct 2022 16:48:31 -0400 Subject: [PATCH] refactor(@angular-devkit/schematics): Delete 'rename' rule - Based on discussion in closed PR #23673, delete `rename` rule. --- .../schematics/src/rules/rename.ts | 25 ------- .../schematics/src/rules/rename_spec.ts | 74 ------------------- .../schematics/src/rules/template.ts | 15 ++-- 3 files changed, 10 insertions(+), 104 deletions(-) delete mode 100644 packages/angular_devkit/schematics/src/rules/rename.ts delete mode 100644 packages/angular_devkit/schematics/src/rules/rename_spec.ts diff --git a/packages/angular_devkit/schematics/src/rules/rename.ts b/packages/angular_devkit/schematics/src/rules/rename.ts deleted file mode 100644 index ff04b5580197..000000000000 --- a/packages/angular_devkit/schematics/src/rules/rename.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import { normalize } from '@angular-devkit/core'; -import { Rule } from '../engine/interface'; -import { FilePredicate } from '../tree/interface'; -import { forEach } from './base'; - -export function rename(match: FilePredicate, to: FilePredicate): Rule { - return forEach((entry) => { - if (match(entry.path, entry)) { - return { - content: entry.content, - path: normalize(to(entry.path, entry)), - }; - } else { - return entry; - } - }); -} diff --git a/packages/angular_devkit/schematics/src/rules/rename_spec.ts b/packages/angular_devkit/schematics/src/rules/rename_spec.ts deleted file mode 100644 index 1d72125d8326..000000000000 --- a/packages/angular_devkit/schematics/src/rules/rename_spec.ts +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -/* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { of as observableOf } from 'rxjs'; -import { SchematicContext } from '../engine/interface'; -import { HostTree } from '../tree/host-tree'; -import { callRule } from './call'; -import { rename } from './rename'; - -const context: SchematicContext = null!; - -describe('rename', () => { - it('works', (done) => { - const tree = new HostTree(); - tree.create('a/b/file1', 'hello world'); - tree.create('a/b/file2', 'hello world'); - tree.create('a/c/file3', 'hello world'); - - let i = 0; - - // Rename all files that contain 'b' to 'hello'. - callRule( - rename( - (x) => !!x.match(/b/), - () => 'hello' + i++, - ), - observableOf(tree), - context, - ) - .toPromise() - .then((result) => { - expect(result.exists('a/b/file1')).toBe(false); - expect(result.exists('a/b/file2')).toBe(false); - expect(result.exists('hello0')).toBe(true); - expect(result.exists('hello1')).toBe(true); - expect(result.exists('a/c/file3')).toBe(true); - }) - .then(done, done.fail); - }); - - it('works (2)', (done) => { - const tree = new HostTree(); - tree.create('a/b/file1', 'hello world'); - tree.create('a/b/file2', 'hello world'); - tree.create('a/c/file3', 'hello world'); - - let i = 0; - - // Rename all files that contain 'b' to 'hello'. - callRule( - rename( - (x) => !!x.match(/b/), - (x) => x + i++, - ), - observableOf(tree), - context, - ) - .toPromise() - .then((result) => { - expect(result.exists('a/b/file1')).toBe(false); - expect(result.exists('a/b/file2')).toBe(false); - expect(result.exists('a/b/file10')).toBe(true); - expect(result.exists('a/b/file21')).toBe(true); - expect(result.exists('a/c/file3')).toBe(true); - }) - .then(done, done.fail); - }); -}); diff --git a/packages/angular_devkit/schematics/src/rules/template.ts b/packages/angular_devkit/schematics/src/rules/template.ts index bc5b3258f358..a45bcbb494b1 100644 --- a/packages/angular_devkit/schematics/src/rules/template.ts +++ b/packages/angular_devkit/schematics/src/rules/template.ts @@ -11,7 +11,6 @@ import { TextDecoder } from 'util'; import { FileOperator, Rule } from '../engine/interface'; import { FileEntry } from '../tree/interface'; import { chain, composeFileOperators, forEach, when } from './base'; -import { rename } from './rename'; export const TEMPLATE_FILENAME_RE = /\.template$/; @@ -157,10 +156,16 @@ export function pathTemplate(options: T): Rule { * Remove every `.template` suffix from file names. */ export function renameTemplateFiles(): Rule { - return rename( - (path) => !!path.match(TEMPLATE_FILENAME_RE), - (path) => path.replace(TEMPLATE_FILENAME_RE, ''), - ); + return forEach((entry) => { + if (entry.path.match(TEMPLATE_FILENAME_RE)) { + return { + content: entry.content, + path: normalize(entry.path.replace(TEMPLATE_FILENAME_RE, '')), + }; + } else { + return entry; + } + }); } export function template(options: T): Rule {