Skip to content

Commit 7c6380e

Browse files
committed
feat(Nx20): fix generators to work in Nx20 where 'directory' is required option
1 parent 80fd32e commit 7c6380e

File tree

7 files changed

+92
-91
lines changed

7 files changed

+92
-91
lines changed

libs/ddd/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ ng g @angular-architects/ddd:feature search --domain booking --entity flight --s
8686

8787
Don't mix Standalone Components and traditional ones within the same domain.
8888

89+
**Since version 19**, standalone **defaults to true**.
90+
8991
## Generated Structure
9092

9193
The included schematics generate a folder for each domain. This folder contains feature libs as well as a library with the domain logic:

libs/ddd/src/generators/api/index.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,34 @@ import { deleteDefaultComponent } from '../utils/delete-default-component';
88
export default async function (tree: Tree, options: ApiOptions) {
99
validateInputs(options);
1010

11-
const libName = options.name
12-
? `api-${strings.dasherize(options.name)}`
13-
: 'api';
14-
15-
const domain = options.shared ? 'shared' : options.domain;
16-
const libDirectory = options.directory
17-
? `${domain}/${options.directory}`
18-
: domain;
11+
const libName = options.name ? `api-${strings.dasherize(options.name)}` : 'api';
12+
const libDirectory = options.directory ? strings.dasherize(options.directory) : libName;
13+
const domainName = options.shared ? 'shared' : options.domain;
1914
const isPublishableLib = options.type === 'publishable';
2015

16+
// additions for Nx20 by LXT
17+
const finalName = domainName + '-' + libName;
18+
const finalDirectory = `libs/${domainName}/${libDirectory}`;
19+
2120
await libraryGenerator(tree, {
22-
name: `libs/${libDirectory}/${libName}`,
23-
tags: `domain:${domain},domain:${domain}/${libName},type:api`,
24-
prefix: options.name,
21+
name: finalName,
22+
prefix: finalName,
23+
directory: finalDirectory,
24+
tags: `domain:${domainName},domain:${domainName}/${libName},type:api`,
2525
publishable: isPublishableLib,
2626
buildable: options.type === 'buildable',
27-
// directory: libDirectory,
2827
importPath: options.importPath,
2928
standalone: options.standalone,
3029
});
3130

3231
deleteDefaultComponent(
3332
tree,
34-
libDirectory,
35-
libName,
36-
options.name
33+
finalDirectory,
34+
finalName
3735
);
3836

3937
console.info(
40-
`\nHINT: Don\'t forget to extend the rules in your .eslintrc to allow selected domains to access this API.\nFor this, add the tag domain:${domain}/${libName} to the respective domains' rule sets.\n `
38+
`\nHINT: Don\'t forget to extend the rules in your "eslint.config.js" to allow selected domains to access this API.\nFor this, add the tag domain:${domainName}/${libName} to the respective domains' rule sets.\n `
4139
);
4240

4341
await formatFiles(tree);

libs/ddd/src/generators/domain/index.ts

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,40 +54,39 @@ function convertToStandaloneApp(
5454
export default async function (tree: Tree, options: DomainOptions) {
5555
const appName = strings.dasherize(options.name);
5656
const appNameAndDirectory = options.appDirectory
57-
? `${options.appDirectory}/${appName}`
58-
: appName;
59-
const appNameAndDirectoryDasherized = strings
60-
.dasherize(appNameAndDirectory)
57+
? `apps/${options.appDirectory}/${appName}`
58+
: `apps/${appName}`;
59+
const appNameSlug = strings
60+
.dasherize(appName)
6161
.split('/')
6262
.join('-');
63-
const appFolderPath = `apps/${appNameAndDirectory}`;
63+
const appFolderPath = `${appNameAndDirectory}`;
6464
const appSrcFolder = `${appFolderPath}/src`;
6565
const appModuleFolder = `${appFolderPath}/src/app`;
6666
const appModuleFilepath = `${appModuleFolder}/app.module.ts`;
6767

68-
const libName = strings.dasherize(options.name);
69-
const libNameAndDirectory = options.directory
70-
? `${options.directory}/${libName}`
71-
: libName;
72-
const libNameAndDirectoryDasherized = strings
73-
.dasherize(libNameAndDirectory)
74-
.split('/')
75-
.join('-');
76-
const libFolderPath = `libs/${libNameAndDirectory}`;
77-
const libLibFolder = `${libFolderPath}/domain/src/lib`;
78-
const libSrcFolder = `${libFolderPath}/domain/src`;
68+
// additions for Nx20 by LXT
69+
const domainName = strings.dasherize(options.name);
70+
const domainNameAndDirectory = options.directory
71+
? `${options.directory}/${domainName}`
72+
: domainName;
73+
74+
const finalName = domainName + '-domain';
75+
const finalDirectory = `libs/${domainNameAndDirectory}/domain`;
76+
const libSrcFolder = `${finalDirectory}/src`;
77+
const libLibFolder = `${libSrcFolder}/lib`;
7978

80-
// if (options.ngrx && !options.addApp) {
81-
// throw new Error(
82-
// `The 'ngrx' option may only be used when the 'addApp' option is used.`
83-
// );
84-
// }
79+
/*if (options.ngrx && !options.addApp) {
80+
throw new Error(
81+
`The 'ngrx' option may only be used when the 'addApp' option is used.`
82+
);
83+
}*/
8584

8685
await libraryGenerator(tree, {
87-
name: `libs/${libNameAndDirectory}/domain`,
88-
// directory: libNameAndDirectory,
89-
tags: `domain:${libName},type:domain-logic`,
90-
prefix: libName,
86+
name: finalName,
87+
prefix: finalName,
88+
directory: finalDirectory,
89+
tags: `domain:${domainName},type:domain-logic`,
9190
publishable: options.type === 'publishable',
9291
buildable: options.type === 'buildable',
9392
importPath: options.importPath,
@@ -96,8 +95,8 @@ export default async function (tree: Tree, options: DomainOptions) {
9695

9796
updateDepConst(tree, (depConst) => {
9897
depConst.push({
99-
sourceTag: `domain:${libName}`,
100-
onlyDependOnLibsWithTags: [`domain:${libName}`, 'domain:shared'],
98+
sourceTag: `domain:${domainName}`,
99+
onlyDependOnLibsWithTags: [`domain:${domainName}`, 'domain:shared'],
101100
});
102101
});
103102

@@ -114,8 +113,8 @@ export default async function (tree: Tree, options: DomainOptions) {
114113

115114
if (options.addApp) {
116115
await applicationGenerator(tree, {
117-
name: options.appDirectory ? `apps/${options.appDirectory}/${appName}` : `apps/${appName}`,
118-
// directory: options.appDirectory,
116+
name: appName,
117+
directory: appNameAndDirectory,
119118
tags: `domain:${appName},type:app`,
120119
style: 'scss',
121120
standalone: options.standalone
@@ -125,7 +124,7 @@ export default async function (tree: Tree, options: DomainOptions) {
125124
const wsConfig = readNxJson(tree);
126125
const npmScope = getNpmScope(tree);
127126
// const wsConfig = readWorkspaceConfiguration(tree);
128-
127+
129128
if (options.addApp && options.standalone) {
130129
convertToStandaloneApp(tree, {
131130
name: options.name,
@@ -146,7 +145,7 @@ export default async function (tree: Tree, options: DomainOptions) {
146145
);
147146

148147
await generateStore(tree, {
149-
project: appNameAndDirectoryDasherized,
148+
project: appNameSlug,
150149
root: true,
151150
minimal: true,
152151
module: 'app.module.ts',
@@ -170,14 +169,14 @@ export default async function (tree: Tree, options: DomainOptions) {
170169

171170
}
172171

172+
// fixed by LXT
173173
deleteDefaultComponent(
174174
tree,
175-
libNameAndDirectory,
176-
'domain',
177-
libName,
175+
finalDirectory,
176+
finalName,
178177
!options.ngrx
179178
);
180-
179+
181180
await formatFiles(tree);
182181
return () => {
183182
installPackagesTask(tree);

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ export default async function (tree: Tree, options: FeatureOptions) {
5656
const appDirectoryAndName = appDirectory
5757
? `${appDirectory}/${appName}`
5858
: appName;
59-
const appDirectoryAndNameDasherized = `${appDirectoryAndName}`
59+
/*const appDirectoryAndNameDasherized = `${appDirectoryAndName}`
6060
.split('/')
61-
.join('-');
61+
.join('-');*/
6262
const domainNameAndDirectoryPath = `libs/${domainNameAndDirectory}`;
6363
const domainFolderPath = `${domainNameAndDirectoryPath}/domain`;
6464
const domainLibFolderPath = `${domainFolderPath}/src/lib`;
@@ -80,7 +80,7 @@ export default async function (tree: Tree, options: FeatureOptions) {
8080
const featureModuleClassName = strings.classify(
8181
`${domainNameAndDirectoryDasherized}-${featureFolderName}Module`
8282
);
83-
const featureImportPath = `${workspaceName}/${domainNameAndDirectory}/${featureFolderName}`;
83+
const featureImportPath = `${workspaceName}/${featureFolderName}`; // /${domainNameAndDirectory}/ removed by LXT
8484
const featureIndexPath = `${domainNameAndDirectoryPath}/${featureDirectoryAndFolderName}/src/index.ts`;
8585
const entityName = options.entity ? strings.dasherize(options.entity) : '';
8686
const featureComponentImportPath = `./${featureDirectoryAndNameDasherized}.component`;
@@ -102,15 +102,17 @@ export default async function (tree: Tree, options: FeatureOptions) {
102102
);
103103
}
104104

105-
const dir = featureDirectory
106-
? `${domainNameAndDirectory}/${featureDirectory}`
107-
: `${domainNameAndDirectory}`;
105+
// additions for Nx20 by LXT
106+
const finalName = domainName + '-' + featureFolderName;
107+
const finalDirectory = featureDirectory
108+
? `libs/${domainNameAndDirectory}/${featureDirectory}`
109+
: `libs/${domainNameAndDirectory}/${featureFolderName}`;
108110

109111
await libraryGenerator(tree, {
110-
name: `libs/${dir}/${featureFolderName}`,
111-
// directory: dir,
112+
name: finalName,
113+
prefix: finalName,
114+
directory: finalDirectory,
112115
tags: `domain:${domainName},type:feature`,
113-
prefix: domainNameAndDirectoryDasherized,
114116
publishable: options.type === 'publishable',
115117
buildable: options.type === 'buildable',
116118
importPath: options.importPath,
@@ -176,9 +178,8 @@ export default async function (tree: Tree, options: FeatureOptions) {
176178

177179
deleteDefaultComponent(
178180
tree,
179-
dir,
180-
featureFolderName,
181-
domainNameAndDirectoryDasherized
181+
finalDirectory,
182+
finalName
182183
);
183184

184185
await formatFiles(tree);

libs/ddd/src/generators/ui/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,29 @@ export default async function (tree: Tree, options: UiOptions) {
99
validateInputs(options);
1010

1111
const libName = `ui-${strings.dasherize(options.name)}`;
12-
const domain = options.shared ? 'shared' : options.domain;
13-
const libDirectory = options.directory
14-
? `${domain}/${options.directory}`
15-
: domain;
12+
const libDirectory = options.directory ? strings.dasherize(options.directory) : libName;
13+
const domainName = options.shared ? 'shared' : options.domain;
1614
const isPublishableLib = options.type === 'publishable';
1715

16+
// additions for Nx20 by LXT
17+
const finalName = domainName + '-' + libName;
18+
const finalDirectory = `libs/${domainName}/${libDirectory}`;
19+
1820
await libraryGenerator(tree, {
19-
name: `libs/${libDirectory}/${libName}`,
20-
tags: `domain:${domain},type:ui`,
21-
prefix: options.name,
21+
name: finalName,
22+
prefix: finalName,
23+
directory: finalDirectory,
24+
tags: `domain:${domainName},type:ui`,
2225
publishable: isPublishableLib,
2326
buildable: options.type === 'buildable',
24-
// directory: libDirectory,
2527
importPath: options.importPath,
2628
standalone: options.standalone,
2729
});
2830

2931
deleteDefaultComponent(
3032
tree,
31-
libDirectory,
32-
libName,
33-
options.name
33+
finalDirectory,
34+
finalName
3435
);
3536

3637
await formatFiles(tree);

libs/ddd/src/generators/util/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,29 @@ export default async function (tree: Tree, options: UtilOptions) {
99
validateInputs(options);
1010

1111
const libName = `util-${strings.dasherize(options.name)}`;
12-
const domain = options.shared ? 'shared' : options.domain;
13-
const libDirectory = options.directory
14-
? `${domain}/${options.directory}`
15-
: domain;
12+
const libDirectory = options.directory ? strings.dasherize(options.directory) : libName;
13+
const domainName = options.shared ? 'shared' : options.domain;
1614
const isPublishableLib = options.type === 'publishable';
1715

16+
// additions for Nx20 by LXT
17+
const finalName = domainName + '-' + libName;
18+
const finalDirectory = `libs/${domainName}/${libDirectory}`;
19+
1820
await libraryGenerator(tree, {
19-
name: `libs/${libDirectory}/${libName}`,
20-
tags: `domain:${domain},type:util`,
21-
prefix: options.name,
21+
name: finalName,
22+
prefix: finalName,
23+
directory: finalDirectory,
24+
tags: `domain:${domainName},type:util`,
2225
publishable: isPublishableLib,
2326
buildable: options.type === 'buildable',
24-
// directory: libDirectory,
2527
importPath: options.importPath,
2628
standalone: options.standalone,
2729
});
2830

2931
deleteDefaultComponent(
3032
tree,
31-
libDirectory,
32-
libName,
33-
options.name
33+
finalDirectory,
34+
finalName
3435
);
3536

3637
await formatFiles(tree);
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { Tree } from '@nx/devkit';
2-
import { dasherize } from '@nx/devkit/src/utils/string-utils';
32
import * as path from 'path';
43

5-
export function deleteDefaultComponent(tree: Tree, directory: string, libName: string, prefix: string, deleteIndex = true): void {
6-
const dirToDel = path.join('libs', directory, dasherize(libName), 'src', 'lib', dasherize(directory + '-' + libName));
4+
export function deleteDefaultComponent(tree: Tree, finalDirectory: string, finalName: string, deleteIndex = true): void {
5+
const dirToDel = path.join(finalDirectory, 'src', 'lib', finalName);
6+
//console.log('dirToDel', dirToDel);
77
let deleted = false;
88
if (tree.exists(dirToDel)) {
99
tree.delete(dirToDel);
1010
deleted = true;
1111
}
1212

13-
const index = path.join('libs', directory, dasherize(libName), 'src', 'index.ts');
13+
const index = path.join(finalDirectory, 'src', 'index.ts');
1414
if (deleteIndex && deleted && tree.exists(index)) {
1515
const contents = tree.read(index, 'utf-8');
1616
const rest = contents.split('\n').slice(1);
1717
tree.write(index, (rest || []).join('\n'));
1818
}
19-
20-
}
19+
}

0 commit comments

Comments
 (0)