Skip to content

Commit 44bc51a

Browse files
committed
feat(prefix): allow user to bypass "feature-" prefix
1 parent 3214f34 commit 44bc51a

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

libs/ddd/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,32 @@ Add domains and features interactively:
3838
```
3939
ng g @angular-architects/ddd:domain
4040
> ? What is the name of the domain? booking
41-
? Would you like to add an associated application? (y/N) No
41+
> ? Would you like to add an associated application? (y/N) No
4242
4343
ng g @angular-architects/ddd:domain
4444
> ? What is the name of the domain? boarding
45-
? Would you like to add an associated application? (y/N) No
45+
> ? Would you like to add an associated application? (y/N) No
4646
4747
ng g @angular-architects/ddd:feature
4848
> ? What is the name of the library? search
4949
> ? What is the name of the associated domain? booking
50+
> ? Would you like to add the "feature-" prefix? (Y/n) Yes
5051
> ? Is this feature lazy loaded? (y/N) No
5152
> [Optional] What is the associated application? (Leave blank if none) flight-app
5253
> [Optional] What is the name of the entity to create for this feature? (Leave blank if none) flight
5354
5455
ng g @angular-architects/ddd:feature
5556
> ? What is the name of the library? cancel
5657
> ? What is the name of the associated domain? booking
58+
> ? Would you like to add the "feature-" prefix? (Y/n) Yes
5759
> ? Is this feature lazy loaded? (y/N) No
5860
> [Optional] What is the associated application? (Leave blank if none) flight-app
5961
> [Optional] What is the name of the entity to create for this feature? (Leave blank if none)
6062
6163
ng g @angular-architects/ddd:feature
6264
> ? What is the name of the library? manage
6365
> ? What is the name of the associated domain? boarding
66+
> ? Would you like to add the "feature-" prefix? (Y/n) Yes
6467
> ? Is this feature lazy loaded? (y/N) No
6568
> [Optional] What is the associated application? (Leave blank if none) flight-app
6669
> [Optional] What is the name of the entity to create for this feature? (Leave blank if none)

libs/ddd/src/schematics/feature/index.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ function readIntoSourceFile(host: Tree, modulePath: string): ts.SourceFile {
2121
}
2222

2323
function addImport(
24-
modulePath: string,
25-
ngModuleToImportPath: string,
26-
ngModuleToImportName: string,
24+
modulePath: string,
25+
ngModuleToImportPath: string,
26+
ngModuleToImportName: string,
2727
optional = false): Rule {
28-
28+
2929
return (host: Tree) => {
3030

3131
if (optional && !host.exists(modulePath)) {
@@ -35,9 +35,9 @@ function addImport(
3535
const source = readIntoSourceFile(host, modulePath);
3636

3737
const changes = addImportToModule(
38-
source,
39-
modulePath,
40-
ngModuleToImportName,
38+
source,
39+
modulePath,
40+
ngModuleToImportName,
4141
ngModuleToImportPath)
4242

4343
const declarationRecorder = host.beginUpdate(modulePath);
@@ -51,16 +51,16 @@ function addImport(
5151
}
5252

5353
function addDeclaration(
54-
modulePath: string,
55-
componentToImportPath: string,
54+
modulePath: string,
55+
componentToImportPath: string,
5656
componentToImportName: string): Rule {
57-
57+
5858
return (host: Tree) => {
5959

6060
const source = readIntoSourceFile(host, modulePath);
6161

6262
const changes = addDeclarationToModule(
63-
source,
63+
source,
6464
modulePath,
6565
componentToImportName,
6666
componentToImportPath);
@@ -76,16 +76,16 @@ function addDeclaration(
7676
}
7777

7878
function addExport(
79-
modulePath: string,
80-
componentToImportPath: string,
79+
modulePath: string,
80+
componentToImportPath: string,
8181
componentToImportName: string): Rule {
82-
82+
8383
return (host: Tree) => {
8484

8585
const source = readIntoSourceFile(host, modulePath);
8686

8787
const changes = addExportToModule(
88-
source,
88+
source,
8989
modulePath,
9090
componentToImportName,
9191
componentToImportPath);
@@ -103,7 +103,7 @@ function addExport(
103103
function addTsExport(filePath: string, filesToExport: string[]): Rule {
104104
return (host: Tree) => {
105105
let content = host.read(filePath) + '\n';
106-
106+
107107
for(const file of filesToExport) {
108108
content += `export * from '${file}';\n`;
109109
}
@@ -131,24 +131,22 @@ export default function(options: FeatureOptions): Rule {
131131

132132
const workspaceName = readWorkspaceName(host);
133133

134-
const domainName = strings.dasherize(options.domain);
135-
const domainFolderName = domainName;
134+
const domainFolderName = strings.dasherize(options.domain);
136135
const domainPath = `libs/${domainFolderName}/domain/src/lib`;
137-
const domainModulePath = `${domainPath}/${domainFolderName}-domain.module.ts`;
138136
const domainModuleClassName = strings.classify(options.domain) + "DomainModule";
139137
const domainImportPath = `${workspaceName}/${domainFolderName}/domain`;
140138
const domainIndexPath = `libs/${domainFolderName}/domain/src/index.ts`;
141139

142140
const featureName = strings.dasherize(options.name);
143-
const featureFolderName = 'feature-' + featureName;
141+
const featureFolderName = (options.prefix ? 'feature-' : '') + featureName;
144142
const featurePath = `libs/${domainFolderName}/${featureFolderName}/src/lib`;
145143
const featureModulePath = `${featurePath}/${domainFolderName}-${featureFolderName}.module.ts`;
146144
const featureModuleClassName = strings.classify(`${options.domain}-${featureFolderName}Module`);
147145
const featureImportPath = `${workspaceName}/${domainFolderName}/${featureFolderName}`;
148146
const featureIndexPath = `libs/${domainFolderName}/${featureFolderName}/src/index.ts`;
149147

150148
const entityName = options.entity ? strings.dasherize(options.entity) : '';
151-
149+
152150
const featureComponentImportPath = `./${featureName}.component`;
153151
const featureComponentClassName = strings.classify(`${featureName}Component`);
154152

@@ -183,14 +181,14 @@ export default function(options: FeatureOptions): Rule {
183181
prefix: options.domain,
184182
}),
185183
addImport(featureModulePath, domainImportPath, domainModuleClassName),
186-
(!options.lazy && host.exists(appModulePath)) ?
184+
(!options.lazy && host.exists(appModulePath)) ?
187185
chain([
188186
addImport(appModulePath, featureImportPath, featureModuleClassName, true),
189187
addImport(appModulePath, '@angular/common/http', 'HttpClientModule', true)
190188
]) :
191189
noop(),
192190
mergeWith(domainTemplates),
193-
(options.entity) ?
191+
(options.entity) ?
194192
addTsExport(domainIndexPath, [
195193
`./lib/entities/${entityName}`,
196194
`./lib/infrastructure/${entityName}.data.service`

libs/ddd/src/schematics/feature/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
"x-prompt": "What is the name of the associated domain?",
1818
"description": "Domain name"
1919
},
20+
"prefix": {
21+
"type": "boolean",
22+
"description": "Apply the \"feature-\" prefix?",
23+
"x-prompt": "Would you like to add the \"feature-\" prefix?",
24+
"default": true
25+
},
2026
"lazy": {
2127
"type": "boolean",
2228
"description": "Is this feature module lazy loaded?",

libs/ddd/src/schematics/feature/schema.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ export interface FeatureOptions {
1515
*/
1616
domain: string;
1717
/**
18-
* app name
18+
* Apply the "feature-" prefix?
1919
*/
20-
app?: string;
20+
prefix?: boolean;
2121
/**
2222
* Is this feature module lazy loaded?
2323
*/
2424
lazy?: boolean;
25+
/**
26+
* app name
27+
*/
28+
app?: string;
2529
/**
2630
* Optional entity to create for this feature
2731
*/

0 commit comments

Comments
 (0)