Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libs/ddd/src/schematics/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ import {
addNgrxImportsToApp,
addNgRxToPackageJson,
} from '../rules';
import { readNxWorkspaceLayout } from '../utils';

export default function (options: DomainOptions): Rule {
const libFolder = strings.dasherize(options.name);
const { libsDir, appsDir } = readNxWorkspaceLayout();

const templateSource = apply(url('./files'), [
template({}),
move(`libs/${libFolder}/domain/src/lib`),
move(`${libsDir}/${libFolder}/domain/src/lib`),
]);

const appFolderName = strings.dasherize(options.name);
const appPath = `apps/${appFolderName}/src/app`;
const appPath = `${appsDir}/${appFolderName}/src/app`;
const appModulePath = `${appPath}/app.module.ts`;

if (options.ngrx && !options.addApp) {
Expand Down
16 changes: 9 additions & 7 deletions libs/ddd/src/schematics/feature/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,31 @@ import {
addNgrxImportsToDomain,
addNgRxToPackageJson,
} from '../rules';
import { readWorkspaceName } from '../utils';
import { readWorkspaceName, readWorkspaceLayout } from '../utils';

export default function (options: FeatureOptions): Rule {
return (host: Tree) => {
const workspaceName = readWorkspaceName(host);
const workspaceLayout = readWorkspaceLayout(host);

const { libsDir, appsDir } = workspaceLayout;
const domainFolderName = strings.dasherize(options.domain);
const domainPath = `libs/${domainFolderName}/domain/src/lib`;
const domainPath = `${libsDir}/${domainFolderName}/domain/src/lib`;
const domainModulePath = `${domainPath}/${domainFolderName}-domain.module.ts`;
const domainModuleClassName =
strings.classify(options.domain) + 'DomainModule';
const domainImportPath = `${workspaceName}/${domainFolderName}/domain`;
const domainIndexPath = `libs/${domainFolderName}/domain/src/index.ts`;
const domainIndexPath = `${libsDir}/${domainFolderName}/domain/src/index.ts`;

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

const entityName = options.entity ? strings.dasherize(options.entity) : '';

Expand All @@ -54,10 +56,10 @@ export default function (options: FeatureOptions): Rule {

const appName = options.app || options.domain;
const appFolderName = strings.dasherize(appName);
const appModulePath = `apps/${appFolderName}/src/app/app.module.ts`;
const appModulePath = `${appsDir}/${appFolderName}/src/app/app.module.ts`;

if (options.app) {
const requiredAppModulePath = `apps/${appFolderName}/src/app/app.module.ts`;
const requiredAppModulePath = `${appsDir}/${appFolderName}/src/app/app.module.ts`;
if (!host.exists(requiredAppModulePath)) {
throw new Error(
`Specified app ${options.app} does not exist: ${requiredAppModulePath} expected!`
Expand Down
1 change: 1 addition & 0 deletions libs/ddd/src/schematics/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './read-workspace-layout';
export * from './read-into-source-file';
export * from './check-rule-exists';
export * from './read-workspace-name';
Expand Down
32 changes: 32 additions & 0 deletions libs/ddd/src/schematics/utils/read-workspace-layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Tree } from '@angular-devkit/schematics';
import { readJsonFile } from '@nrwl/workspace';

export interface WorkspaceLayout {
appsDir: boolean;
libsDir: boolean;
}

/**
* readWorkspaceLayout
* @param host host provided to a rule
*/
export function readWorkspaceLayout(host: Tree): WorkspaceLayout {
const content = host.read('nx.json').toString();
const config = JSON.parse(content);
return (
config['workspaceLayout'] ?? {
appsDir: 'apps',
libsDir: 'libs',
}
);
}

export function readNxWorkspaceLayout(): WorkspaceLayout {
const config = readJsonFile('nx.json')
return (
config['workspaceLayout'] ?? {
appsDir: 'apps',
libsDir: 'libs',
}
);
}
Loading