Skip to content

Commit

Permalink
fix(devkit): generateFiles should rename paths recursively (#4784)
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman authored Feb 18, 2021
1 parent 9107c88 commit 4522a90
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions packages/devkit/src/generators/generate-files.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Tree } from '@nrwl/devkit';
import { createTree } from '@nrwl/devkit/testing';
import { join } from 'path';
import { generateFiles } from './generate-files';

describe('generateFiles', () => {
let tree: Tree;

beforeEach(() => {
tree = createTree();
});

it('should generate files from template in a directory', () => {
const target = './tools/target';
const name = 'my-project';
const projectName = 'my-project-api';

generateFiles(tree, join(__dirname, '../tests/generate-files'), target, {
dot: '.',
name,
projectName,
tmpl: '',
});

expect(tree.exists(`${target}/${name}.service.ts`)).toBeTruthy();
expect(tree.exists(`${target}/src/common-util.ts`)).toBeTruthy();
expect(
tree.exists(`${target}/src/${projectName}/create-${name}.input.ts`)
).toBeTruthy();
expect(
tree.exists(
`${target}/src/${projectName}/${name}/${projectName}.${name}.model.ts`
)
).toBeTruthy();
expect(
tree.exists(`${target}/src/${projectName}/output/.gitkeep`)
).toBeTruthy();
expect(tree.exists(`${target}/src/${name}.module.ts`)).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion packages/devkit/src/generators/generate-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function replaceSegmentsInPath(
substitutions: { [k: string]: any }
) {
Object.entries(substitutions).forEach(([t, r]) => {
filePath = filePath.replace(`__${t}__`, r);
filePath = filePath.split(`__${t}__`).join(r);
});
return filePath;
}
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 4522a90

Please sign in to comment.