Skip to content

Commit 9461f6e

Browse files
authored
feat: path option to add schematics (#251)
1 parent 286ddfe commit 9461f6e

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

projects/ngverse/schematics/add/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ export function add(options: Schema) {
2626
const prefix = options.prefix || project.prefix;
2727

2828
const rootPath = normalize(`${project.sourceRoot}/${projectType}`);
29-
30-
const applicationPath = normalize(join(rootPath, options.name));
29+
let path = './';
30+
if (options.path) {
31+
path = `./${options.path}`;
32+
}
33+
const applicationPath = normalize(join(rootPath, path, options.name));
3134
const elementName = getElementName(options.name);
3235

3336
const elementsPath = normalize(

projects/ngverse/schematics/add/index_spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,16 @@ describe('element', () => {
204204
appTree.readContent(getProjectPath(componentName, 'component.ts'))
205205
).toEqual(modifiedButton);
206206
});
207+
208+
fit('should put component properly when path provided', async () => {
209+
const componentName = 'button';
210+
211+
await testRunner.runSchematic(
212+
'add',
213+
{ name: componentName, project: PROJECT_NAME, path: 'ui' },
214+
appTree
215+
);
216+
const path = 'projects/demo/src/app/ui/button/button.component.ts';
217+
expect(appTree.readContent(path)).toEqual(BUTTON_COMPONENT_TS);
218+
});
207219
});

projects/ngverse/schematics/add/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"prefix": {
3333
"type": "string",
3434
"description": "The prefix of the element. if not provided, it will take prefix from the project, if it is also null it will be 'app'"
35+
},
36+
"path": {
37+
"type": "string",
38+
"description": "the path to put the generated element"
3539
}
3640
},
3741
"required": ["name"]

projects/ngverse/schematics/add/schema.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ export interface Schema {
99
includeTests?: string;
1010

1111
prefix?: string;
12+
13+
path?: string;
1214
}

0 commit comments

Comments
 (0)