Skip to content

Commit

Permalink
Fix domain generator for Nx 20
Browse files Browse the repository at this point in the history
  • Loading branch information
L-X-T committed Nov 3, 2024
1 parent e5efde3 commit 81a45f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
46 changes: 22 additions & 24 deletions libs/ddd/src/generators/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ function convertToStandaloneApp(
export default async function (tree: Tree, options: DomainOptions) {
const appName = strings.dasherize(options.name);
const appNameAndDirectory = options.appDirectory
? `${options.appDirectory}/${appName}`
: appName;
const appNameAndDirectoryDasherized = strings
.dasherize(appNameAndDirectory)
? `apps/${options.appDirectory}/${appName}`
: `apps/${appName}`;
const appNameSlug = strings
.dasherize(appName)
.split('/')
.join('-');
const appFolderPath = `apps/${appNameAndDirectory}`;
const appFolderPath = `${appNameAndDirectory}`;
const appSrcFolder = `${appFolderPath}/src`;
const appModuleFolder = `${appFolderPath}/src/app`;
const appModuleFilepath = `${appModuleFolder}/app.module.ts`;
Expand All @@ -69,23 +69,21 @@ export default async function (tree: Tree, options: DomainOptions) {
const libNameAndDirectory = options.directory
? `${options.directory}/${libName}`
: libName;
const libNameAndDirectoryDasherized = strings
.dasherize(libNameAndDirectory)
.split('/')
.join('-');
const libFolderPath = `libs/${libNameAndDirectory}`;
const libLibFolder = `${libFolderPath}/domain/src/lib`;
const libSrcFolder = `${libFolderPath}/domain/src`;

// if (options.ngrx && !options.addApp) {
// throw new Error(
// `The 'ngrx' option may only be used when the 'addApp' option is used.`
// );
// }
const libFolderPath = `libs/${libNameAndDirectory}/domain`;
const libSrcFolder = `${libFolderPath}/src`;
const libLibFolder = `${libSrcFolder}/lib`;

/*if (options.ngrx && !options.addApp) {
throw new Error(
`The 'ngrx' option may only be used when the 'addApp' option is used.`
);
}*/

await libraryGenerator(tree, {
name: `libs/${libNameAndDirectory}/domain`,
// directory: libNameAndDirectory,
// name: `libs/${libNameAndDirectory}/domain`,
name: 'domain',
directory: libFolderPath,
tags: `domain:${libName},type:domain-logic`,
prefix: libName,
publishable: options.type === 'publishable',
Expand Down Expand Up @@ -114,8 +112,8 @@ export default async function (tree: Tree, options: DomainOptions) {

if (options.addApp) {
await applicationGenerator(tree, {
name: options.appDirectory ? `apps/${options.appDirectory}/${appName}` : `apps/${appName}`,
// directory: options.appDirectory,
name: appNameAndDirectory,
directory: appNameAndDirectory,
tags: `domain:${appName},type:app`,
style: 'scss',
standalone: options.standalone
Expand All @@ -125,7 +123,7 @@ export default async function (tree: Tree, options: DomainOptions) {
const wsConfig = readNxJson(tree);
const npmScope = getNpmScope(tree);
// const wsConfig = readWorkspaceConfiguration(tree);

if (options.addApp && options.standalone) {
convertToStandaloneApp(tree, {
name: options.name,
Expand All @@ -146,7 +144,7 @@ export default async function (tree: Tree, options: DomainOptions) {
);

await generateStore(tree, {
project: appNameAndDirectoryDasherized,
project: appNameSlug,
root: true,
minimal: true,
module: 'app.module.ts',
Expand Down Expand Up @@ -177,7 +175,7 @@ export default async function (tree: Tree, options: DomainOptions) {
libName,
!options.ngrx
);

await formatFiles(tree);
return () => {
installPackagesTask(tree);
Expand Down
4 changes: 2 additions & 2 deletions libs/ddd/src/generators/utils/delete-default-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { dasherize } from '@nx/devkit/src/utils/string-utils';
import * as path from 'path';

export function deleteDefaultComponent(tree: Tree, directory: string, libName: string, prefix: string, deleteIndex = true): void {
const dirToDel = path.join('libs', directory, dasherize(libName), 'src', 'lib', dasherize(directory + '-' + libName));
const dirToDel = path.join('libs', directory, dasherize(libName), 'src', 'lib', dasherize(libName));
let deleted = false;
if (tree.exists(dirToDel)) {
tree.delete(dirToDel);
Expand All @@ -17,4 +17,4 @@ export function deleteDefaultComponent(tree: Tree, directory: string, libName: s
tree.write(index, (rest || []).join('\n'));
}

}
}

0 comments on commit 81a45f5

Please sign in to comment.