Skip to content

Commit 3e64e03

Browse files
manfredsteyerL-X-T
authored andcommitted
feat: support eslint.config.cjs and use original import path
1 parent 40f896c commit 3e64e03

File tree

11 files changed

+114
-39
lines changed

11 files changed

+114
-39
lines changed

libs/ddd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/ddd",
3-
"version": "19.0.5",
3+
"version": "19.0.6",
44
"license": "MIT",
55
"author": "Manfred Steyer",
66
"description": "Nx plugin for structuring a monorepo with domain driven design",

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,41 @@ import { ApiOptions } from './schema';
44
import { strings } from '@angular-devkit/core';
55
import { validateInputs } from '../utils/validate-inputs';
66
import { deleteDefaultComponent } from '../utils/delete-default-component';
7+
import { getWorkspaceScope } from '../utils/get-workspace-scope';
78

89
export default async function (tree: Tree, options: ApiOptions) {
910
validateInputs(options);
1011

11-
const libName = options.name ? `api-${strings.dasherize(options.name)}` : 'api';
12-
const libDirectory = options.directory ? strings.dasherize(options.directory) : libName;
12+
const workspaceName = getWorkspaceScope(tree);
13+
14+
const libName = options.name
15+
? `api-${strings.dasherize(options.name)}`
16+
: 'api';
17+
const libDirectory = options.directory
18+
? strings.dasherize(options.directory)
19+
: libName;
1320
const domainName = options.shared ? 'shared' : options.domain;
1421
const isPublishableLib = options.type === 'publishable';
1522

1623
// additions for Nx20 by LXT
1724
const finalName = domainName + '-' + libName;
1825
const finalDirectory = `libs/${domainName}/${libDirectory}`;
1926

27+
const prefix = strings.dasherize(finalName).split('/').join('-');
28+
const importPath = `${workspaceName}/${domainName}/${libDirectory}`;
29+
2030
await libraryGenerator(tree, {
2131
name: finalName,
22-
prefix: finalName,
32+
prefix: prefix,
2333
directory: finalDirectory,
2434
tags: `domain:${domainName},domain:${domainName}/${libName},type:api`,
2535
publishable: isPublishableLib,
2636
buildable: options.type === 'buildable',
27-
importPath: options.importPath,
37+
importPath: options.importPath ?? importPath,
2838
standalone: options.standalone,
2939
});
3040

31-
deleteDefaultComponent(
32-
tree,
33-
finalDirectory,
34-
finalName
35-
);
41+
deleteDefaultComponent(tree, finalDirectory, finalName);
3642

3743
console.info(
3844
`\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 `

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ function convertToStandaloneApp(
5252
}
5353

5454
export default async function (tree: Tree, options: DomainOptions) {
55+
const npmScope = getNpmScope(tree);
56+
5557
const appName = strings.dasherize(options.name);
5658
const appNameAndDirectory = options.appDirectory
5759
? `apps/${options.appDirectory}/${appName}`
@@ -82,14 +84,21 @@ export default async function (tree: Tree, options: DomainOptions) {
8284
);
8385
}*/
8486

87+
const prefix = strings
88+
.dasherize(finalName)
89+
.split('/')
90+
.join('-');
91+
92+
const importPath = `${npmScope}/${domainNameAndDirectory}/domain`;
93+
8594
await libraryGenerator(tree, {
8695
name: finalName,
87-
prefix: finalName,
96+
prefix: prefix,
8897
directory: finalDirectory,
8998
tags: `domain:${domainName},type:domain-logic`,
9099
publishable: options.type === 'publishable',
91100
buildable: options.type === 'buildable',
92-
importPath: options.importPath,
101+
importPath: options.importPath ?? importPath,
93102
standalone: options.standalone,
94103
});
95104

@@ -122,7 +131,6 @@ export default async function (tree: Tree, options: DomainOptions) {
122131
}
123132

124133
const wsConfig = readNxJson(tree);
125-
const npmScope = getNpmScope(tree);
126134
// const wsConfig = readWorkspaceConfiguration(tree);
127135

128136
if (options.addApp && options.standalone) {

libs/ddd/src/generators/feature/files/forFeature/__name@dasherize__.component.ts__tmpl__

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CommonModule } from '@angular/common';
55
@Component({ <% if (standalone) { %>
66
standalone: true,
77
imports: [CommonModule],
8-
<% } %>selector: '<%=dasherize(domain)%>-<%=dasherize(name)%>',
8+
<% } %>selector: '<%=dasherize(flatDomain)%>-feature-<%=dasherize(name)%>',
99
templateUrl: './<%=dasherize(name)%>.component.html',
1010
styleUrls: ['./<%=dasherize(name)%>.component.scss']
1111
})

libs/ddd/src/generators/feature/files/forFeatureWithNgrx/__name@dasherize__.component.ts__tmpl__

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CommonModule } from '@angular/common';
55
@Component({ <% if (standalone) { %>
66
standalone: true,
77
imports: [CommonModule],
8-
<% } %>selector: '<%=dasherize(domain)%>-<%=dasherize(name)%>',
8+
<% } %>selector: '<%=dasherize(flatDomain)%>-feature-<%=dasherize(name)%>',
99
templateUrl: './<%=dasherize(name)%>.component.html',
1010
styleUrls: ['./<%=dasherize(name)%>.component.scss']
1111
})

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,21 @@ export default async function (tree: Tree, options: FeatureOptions) {
108108
? `libs/${domainNameAndDirectory}/${featureDirectory}`
109109
: `libs/${domainNameAndDirectory}/${featureFolderName}`;
110110

111+
const prefix = strings
112+
.dasherize(finalName)
113+
.split('/')
114+
.join('-');
115+
116+
const importPath = `${workspaceName}/${domainNameAndDirectory}/${featureFolderName}`;
117+
111118
await libraryGenerator(tree, {
112119
name: finalName,
113-
prefix: finalName,
120+
prefix: prefix,
114121
directory: finalDirectory,
115122
tags: `domain:${domainName},type:feature`,
116123
publishable: options.type === 'publishable',
117124
buildable: options.type === 'buildable',
118-
importPath: options.importPath,
125+
importPath: options.importPath ?? importPath,
119126
standalone: options.standalone,
120127
});
121128

@@ -279,6 +286,9 @@ function generate(
279286
featureLibFolderPath: string;
280287
}
281288
) {
289+
290+
const flatDomain = strings.dasherize(options.domain).split('/').join('-');
291+
282292
const tmpl = '';
283293
const params = {
284294
...strings,
@@ -290,6 +300,7 @@ function generate(
290300
domainLibFolderPath,
291301
featureLibFolderPath,
292302
tmpl,
303+
flatDomain
293304
};
294305

295306
if (options.ngrx && entityName) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tree } from '@nx/devkit';
1+
import { formatFiles, Tree } from '@nx/devkit';
22
import { updateDepConst } from '../utils/update-dep-const';
33

44
export default async function (tree: Tree, schema: any) {
@@ -53,4 +53,6 @@ export default async function (tree: Tree, schema: any) {
5353
onlyDependOnLibsWithTags: ['domain:shared'],
5454
});
5555
});
56+
57+
await formatFiles(tree);
5658
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { UiOptions } from './schema';
44
import { strings } from '@angular-devkit/core';
55
import { validateInputs } from '../utils/validate-inputs';
66
import { deleteDefaultComponent } from '../utils/delete-default-component';
7+
import { getWorkspaceScope } from '../utils/get-workspace-scope';
78

89
export default async function (tree: Tree, options: UiOptions) {
910
validateInputs(options);
1011

12+
const workspaceName = getWorkspaceScope(tree);
13+
1114
const libName = `ui-${strings.dasherize(options.name)}`;
1215
const libDirectory = options.directory ? strings.dasherize(options.directory) : libName;
1316
const domainName = options.shared ? 'shared' : options.domain;
@@ -17,14 +20,17 @@ export default async function (tree: Tree, options: UiOptions) {
1720
const finalName = domainName + '-' + libName;
1821
const finalDirectory = `libs/${domainName}/${libDirectory}`;
1922

23+
const prefix = strings.dasherize(finalName).split('/').join('-');
24+
const importPath = `${workspaceName}/${domainName}/${libDirectory}`;
25+
2026
await libraryGenerator(tree, {
2127
name: finalName,
22-
prefix: finalName,
28+
prefix: prefix,
2329
directory: finalDirectory,
2430
tags: `domain:${domainName},type:ui`,
2531
publishable: isPublishableLib,
2632
buildable: options.type === 'buildable',
27-
importPath: options.importPath,
33+
importPath: options.importPath ?? importPath,
2834
standalone: options.standalone,
2935
});
3036

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { UtilOptions } from './schema';
44
import { strings } from '@angular-devkit/core';
55
import { validateInputs } from '../utils/validate-inputs';
66
import { deleteDefaultComponent } from '../utils/delete-default-component';
7+
import { getWorkspaceScope } from '../utils/get-workspace-scope';
78

89
export default async function (tree: Tree, options: UtilOptions) {
910
validateInputs(options);
1011

12+
const workspaceName = getWorkspaceScope(tree);
13+
1114
const libName = `util-${strings.dasherize(options.name)}`;
1215
const libDirectory = options.directory ? strings.dasherize(options.directory) : libName;
1316
const domainName = options.shared ? 'shared' : options.domain;
@@ -17,14 +20,17 @@ export default async function (tree: Tree, options: UtilOptions) {
1720
const finalName = domainName + '-' + libName;
1821
const finalDirectory = `libs/${domainName}/${libDirectory}`;
1922

23+
const prefix = strings.dasherize(finalName).split('/').join('-');
24+
const importPath = `${workspaceName}/${domainName}/${libDirectory}`;
25+
2026
await libraryGenerator(tree, {
2127
name: finalName,
22-
prefix: finalName,
28+
prefix: prefix,
2329
directory: finalDirectory,
2430
tags: `domain:${domainName},type:util`,
2531
publishable: isPublishableLib,
2632
buildable: options.type === 'buildable',
27-
importPath: options.importPath,
33+
importPath: options.importPath ?? importPath,
2834
standalone: options.standalone,
2935
});
3036

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
import { Tree } from '@nx/devkit';
22
import { checkRuleExists } from './check-rule-exists';
33

4+
const allowAll = /\s*\{\s*sourceTag:\s*'\*',\s*onlyDependOnLibsWithTags:\s*\['\*'\],?\s*\}\s*,?/;
5+
const depConstraints = /depConstraints:\s*\[\s*/;
6+
7+
48
export function updateDepConst(
59
host: Tree,
610
update: (depConst: Array<object>) => void
711
) {
812
let filePath = 'tslint.json';
9-
let rule = 'nx-enforce-module-boundaries';
13+
const rule = 'nx-enforce-module-boundaries';
14+
let isJson = true;
15+
let newText = '';
1016

1117
if (!host.exists('tslint.json')) {
1218
if (host.exists('.eslintrc.json')) {
1319
filePath = '.eslintrc.json';
14-
rule = '@nx/enforce-module-boundaries';
1520
console.info('Found .eslintrc.json');
1621
} else if (host.exists('.eslintrc')) {
1722
filePath = '.eslintrc';
18-
rule = '@nx/enforce-module-boundaries';
19-
console.info('Did not find .eslintrc.json but found .eslintrc');
20-
} else if (host.exists('eslint.config.js')) {
23+
console.info('Found .eslintrc');
24+
} else if (host.exists('eslint.config.cjs')) {
25+
filePath = 'eslint.config.cjs';
26+
console.info('Found .eslintrc');
27+
isJson = false;
28+
}
29+
else if (host.exists('eslint.config.js')) {
2130
console.info(
2231
'ESLint flat config will be supported in next release!'
2332
);
@@ -31,20 +40,44 @@ export function updateDepConst(
3140
}
3241

3342
const text = host.read(filePath).toString();
34-
const json = JSON.parse(text);
35-
let rules = json;
36-
if (rules['overrides']) {
37-
const overrides = rules['overrides'];
38-
rules = overrides.find(
39-
(e) => e.rules && e.rules['@nx/enforce-module-boundaries']
40-
);
41-
}
4243

43-
if (!checkRuleExists(filePath, rule, rules)) return;
44+
if (isJson) {
45+
const json = JSON.parse(text);
46+
let rules = json;
47+
if (rules['overrides']) {
48+
const overrides = rules['overrides'];
49+
rules = overrides.find(
50+
(e) => e.rules && e.rules['@nx/enforce-module-boundaries']
51+
);
52+
}
53+
54+
if (!checkRuleExists(filePath, rule, rules)) return;
4455

45-
const depConst = rules['rules'][rule][1]['depConstraints'] as Array<object>;
46-
update(depConst);
56+
const depConst = rules['rules'][rule][1]['depConstraints'] as Array<object>;
57+
update(depConst);
58+
newText = JSON.stringify(json, undefined, 2);
59+
60+
}
61+
else {
62+
const rules = new Array<object>();
63+
update(rules);
64+
const code = trim(JSON.stringify(rules, null, 2)) + ',';
65+
newText = text.replace(allowAll, '');
66+
newText = newText.replace(depConstraints, 'depConstraints: [\n' + code);
67+
}
4768

48-
const newText = JSON.stringify(json, undefined, 2);
4969
host.write(filePath, newText);
5070
}
71+
72+
function trim(str: string) {
73+
74+
if (str.startsWith('[')) {
75+
str = str.substring(1);
76+
}
77+
78+
if (str.endsWith(']')) {
79+
str = str.substring(0, str.length-1);
80+
}
81+
82+
return str.trim();
83+
}

0 commit comments

Comments
 (0)