Skip to content

Commit 81a45f5

Browse files
committed
Fix domain generator for Nx 20
1 parent e5efde3 commit 81a45f5

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ 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`;
@@ -69,23 +69,21 @@ export default async function (tree: Tree, options: DomainOptions) {
6969
const libNameAndDirectory = options.directory
7070
? `${options.directory}/${libName}`
7171
: 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`;
7972

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-
// }
73+
const libFolderPath = `libs/${libNameAndDirectory}/domain`;
74+
const libSrcFolder = `${libFolderPath}/src`;
75+
const libLibFolder = `${libSrcFolder}/lib`;
76+
77+
/*if (options.ngrx && !options.addApp) {
78+
throw new Error(
79+
`The 'ngrx' option may only be used when the 'addApp' option is used.`
80+
);
81+
}*/
8582

8683
await libraryGenerator(tree, {
87-
name: `libs/${libNameAndDirectory}/domain`,
88-
// directory: libNameAndDirectory,
84+
// name: `libs/${libNameAndDirectory}/domain`,
85+
name: 'domain',
86+
directory: libFolderPath,
8987
tags: `domain:${libName},type:domain-logic`,
9088
prefix: libName,
9189
publishable: options.type === 'publishable',
@@ -114,8 +112,8 @@ export default async function (tree: Tree, options: DomainOptions) {
114112

115113
if (options.addApp) {
116114
await applicationGenerator(tree, {
117-
name: options.appDirectory ? `apps/${options.appDirectory}/${appName}` : `apps/${appName}`,
118-
// directory: options.appDirectory,
115+
name: appNameAndDirectory,
116+
directory: appNameAndDirectory,
119117
tags: `domain:${appName},type:app`,
120118
style: 'scss',
121119
standalone: options.standalone
@@ -125,7 +123,7 @@ export default async function (tree: Tree, options: DomainOptions) {
125123
const wsConfig = readNxJson(tree);
126124
const npmScope = getNpmScope(tree);
127125
// const wsConfig = readWorkspaceConfiguration(tree);
128-
126+
129127
if (options.addApp && options.standalone) {
130128
convertToStandaloneApp(tree, {
131129
name: options.name,
@@ -146,7 +144,7 @@ export default async function (tree: Tree, options: DomainOptions) {
146144
);
147145

148146
await generateStore(tree, {
149-
project: appNameAndDirectoryDasherized,
147+
project: appNameSlug,
150148
root: true,
151149
minimal: true,
152150
module: 'app.module.ts',
@@ -177,7 +175,7 @@ export default async function (tree: Tree, options: DomainOptions) {
177175
libName,
178176
!options.ngrx
179177
);
180-
178+
181179
await formatFiles(tree);
182180
return () => {
183181
installPackagesTask(tree);

libs/ddd/src/generators/utils/delete-default-component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { dasherize } from '@nx/devkit/src/utils/string-utils';
33
import * as path from 'path';
44

55
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));
6+
const dirToDel = path.join('libs', directory, dasherize(libName), 'src', 'lib', dasherize(libName));
77
let deleted = false;
88
if (tree.exists(dirToDel)) {
99
tree.delete(dirToDel);
@@ -17,4 +17,4 @@ export function deleteDefaultComponent(tree: Tree, directory: string, libName: s
1717
tree.write(index, (rest || []).join('\n'));
1818
}
1919

20-
}
20+
}

0 commit comments

Comments
 (0)