-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(devkit): generateFiles should rename paths recursively
- Loading branch information
Showing
8 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Tree } from '@nrwl/devkit'; | ||
import { createTree } from '@nrwl/devkit/testing'; | ||
import { join } from 'path'; | ||
import { generateFiles } from './generate-files'; | ||
|
||
function recursiveTree( | ||
tree: Tree, | ||
root: string, | ||
path: string = '', | ||
paths = [] | ||
): string[] { | ||
const full = join(root, path); | ||
|
||
if (!tree.exists(full)) { | ||
return undefined; | ||
} | ||
|
||
if (!tree.isFile(full)) { | ||
const children = tree.children(full); | ||
|
||
return children.reduce((acc, curr) => { | ||
return recursiveTree(tree, root, join(path, curr), paths); | ||
}, []); | ||
} | ||
paths.push(path); | ||
|
||
return paths.sort(); | ||
} | ||
|
||
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(recursiveTree(tree, target)).toEqual([ | ||
`${name}.service.ts`, | ||
`src/common-util.ts`, | ||
`src/${projectName}/create-${name}.input.ts`, | ||
`src/${projectName}/${name}/${projectName}.${name}.model.ts`, | ||
`src/${projectName}/output/.gitkeep`, | ||
`src/${name}.module.ts`, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.