Skip to content

Commit 73bfbb2

Browse files
committed
making v2 ready
1 parent f1a61fe commit 73bfbb2

9 files changed

Lines changed: 136 additions & 17 deletions

File tree

libs/ddd/collection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"schema": "./src/generators/ui/schema.json",
3030
"description": "adds a UI library to a domain or as a shared library"
3131
},
32+
"api": {
33+
"factory": "./src/generators/api/index",
34+
"schema": "./src/generators/api/schema.json",
35+
"description": "adds a API library to a domain or as a shared library"
36+
},
3237
"util": {
3338
"factory": "./src/generators/util/index",
3439
"schema": "./src/generators/util/schema.json",

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": "2.0.0-rc.1",
3+
"version": "2.0.0",
44
"license": "MIT",
55
"author": "Manfred Steyer",
66
"description": "Nx plugin for structuring a monorepo with domains and layers",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Tree, formatFiles } from '@nrwl/devkit';
2+
import { libraryGenerator } from '@nrwl/angular/generators';
3+
import { ApiOptions } from './schema';
4+
import { strings } from '@angular-devkit/core';
5+
import { validateInputs } from '../utils/validate-inputs';
6+
7+
export default async function (tree: Tree, options: ApiOptions) {
8+
validateInputs(options);
9+
10+
const libName = options.name ?
11+
`api-${strings.dasherize(options.name)}`
12+
: 'api';
13+
14+
const domain = options.shared ? 'shared' : options.domain;
15+
const libDirectory = options.directory
16+
? `${domain}/${options.directory}`
17+
: domain;
18+
const isPublishableLib = options.type === 'publishable';
19+
20+
await libraryGenerator(tree, {
21+
name: libName,
22+
tags: `domain:${domain},domain:${domain}/${libName},type:api`,
23+
prefix: options.name,
24+
publishable: isPublishableLib,
25+
buildable: options.type === 'buildable',
26+
directory: libDirectory,
27+
importPath: options.importPath
28+
});
29+
30+
console.info(`\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 `);
31+
32+
await formatFiles(tree);
33+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"cli": "nx",
4+
"$id": "api",
5+
"type": "object",
6+
"properties": {
7+
"name": {
8+
"type": "string",
9+
"description": "Name of the API library",
10+
"$default": {
11+
"$source": "argv",
12+
"index": 0
13+
}
14+
},
15+
"shared": {
16+
"type": "boolean",
17+
"description": "Whether the library should be shared across all domains.",
18+
"default": false
19+
},
20+
"domain": {
21+
"type": "string",
22+
"description": "Domain name, if the library belongs to a certain domain."
23+
},
24+
"directory": {
25+
"type": "string",
26+
"description": "Subpath of the library beneath the domain or shared folder."
27+
},
28+
"importPath": {
29+
"type": "string",
30+
"description": "For publishable libs: Official package name used in import statements"
31+
},
32+
"type": {
33+
"type": "string",
34+
"enum": ["internal", "buildable", "publishable"],
35+
"description": "A type to determine if and how to build the library.",
36+
"default": "buildable"
37+
}
38+
}
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export interface ApiOptions {
9+
/**
10+
* Name of the UI library
11+
*/
12+
name: string;
13+
/**
14+
* Whether the library should be shared across all domains.
15+
*/
16+
shared?: boolean;
17+
/**
18+
* Domain name, if the library belongs to a certain domain.
19+
*/
20+
domain?: string;
21+
/**
22+
* Subpath of the library beneath the domain or shared folder.
23+
*/
24+
directory?: string;
25+
/**
26+
* For publishable libs: Official package name used in import statements
27+
*/
28+
importPath?: string;
29+
/**
30+
* A type to determine if and how to build the library.
31+
*/
32+
type?: "internal" | "buildable" | "publishable";
33+
[k: string]: any;
34+
}

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as ts from 'typescript';
1010
import { NGRX_VERSION } from '../utils/ngrx-version';
1111

1212
export default async function (tree: Tree, options: DomainOptions) {
13-
13+
1414
const appName = strings.dasherize(options.name);
1515
const appNameAndDirectory = options.appDirectory
1616
? `${options.appDirectory}/${appName}`
@@ -34,11 +34,11 @@ export default async function (tree: Tree, options: DomainOptions) {
3434
const libFolderPath = `libs/${libNameAndDirectory}`;
3535
const libLibFolder = `${libFolderPath}/domain/src/lib`;
3636

37-
if (options.ngrx && !options.addApp) {
38-
throw new Error(
39-
`The 'ngrx' option may only be used when the 'addApp' option is used.`
40-
);
41-
}
37+
// if (options.ngrx && !options.addApp) {
38+
// throw new Error(
39+
// `The 'ngrx' option may only be used when the 'addApp' option is used.`
40+
// );
41+
// }
4242

4343
await libraryGenerator(tree, {
4444
name: 'domain',
@@ -79,25 +79,24 @@ export default async function (tree: Tree, options: DomainOptions) {
7979

8080
if (options.addApp && options.ngrx) {
8181
const generateStore = wrapAngularDevkitSchematic('@ngrx/schematics', 'store');
82-
82+
8383
await generateStore(tree, {
8484
project: appNameAndDirectoryDasherized,
8585
root: true,
8686
minimal: true,
8787
module: 'app.module.ts',
8888
name: 'state',
8989
});
90-
90+
9191
addNgrxImportsToApp(tree, appModuleFilepath);
9292
addNgrxDependencies(tree);
93-
94-
await formatFiles(tree);
95-
return () => {
96-
installPackagesTask(tree);
97-
};
98-
9993
}
10094

95+
await formatFiles(tree);
96+
return () => {
97+
installPackagesTask(tree);
98+
};
99+
101100
}
102101

103102
function addNgrxDependencies(tree: Tree) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default async function (tree: Tree, options: FeatureOptions) {
8080
const appModulePath = `apps/${appDirectoryAndName}/src/app/app.module.ts`;
8181

8282
const requiredAppModulePath = `apps/${appDirectoryAndName}/src/app/app.module.ts`;
83-
if (!tree.exists(requiredAppModulePath)) {
83+
if (!options.noApp && !tree.exists(requiredAppModulePath)) {
8484
throw new Error(
8585
`Specified app ${options.app} does not exist: ${requiredAppModulePath} expected!`
8686
);
@@ -112,7 +112,7 @@ export default async function (tree: Tree, options: FeatureOptions) {
112112
importPath: domainImportPath
113113
});
114114

115-
if (!options.lazy && tree.exists(appModulePath)) {
115+
if (!options.noApp && !options.lazy && tree.exists(appModulePath)) {
116116
addImportToNgModule(tree, {
117117
filePath: appModulePath,
118118
importClassName: featureModuleClassName,

libs/ddd/src/generators/feature/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
"type": "boolean",
6363
"default": false,
6464
"description": "Add ngrx for the domain (entity required)"
65+
},
66+
"noApp": {
67+
"type": "boolean",
68+
"default": false,
69+
"description": "Don't connect the feature lib to an app"
6570
}
6671
},
6772
"required": ["name", "domain"]

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export interface FeatureOptions {
2626
* Domain name
2727
*/
2828
domainDirectory?: string;
29+
/**
30+
* Don't connect this feature lib to an app
31+
*/
32+
noApp?: boolean;
2933
/**
3034
* app name
3135
*/

0 commit comments

Comments
 (0)