Skip to content

Commit d184253

Browse files
committed
feat(domain,feature): add schematics for domain and feature libs
0 parents  commit d184253

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+17937
-0
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

.eslintrc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 2018,
6+
"sourceType": "module",
7+
"project": "./tsconfig.json"
8+
},
9+
"plugins": ["@typescript-eslint", "@nrwl/nx"],
10+
"extends": [
11+
"eslint:recommended",
12+
"plugin:@typescript-eslint/eslint-recommended",
13+
"plugin:@typescript-eslint/recommended",
14+
"prettier",
15+
"prettier/@typescript-eslint"
16+
],
17+
"rules": {
18+
"@typescript-eslint/explicit-member-accessibility": "off",
19+
"@typescript-eslint/explicit-function-return-type": "off",
20+
"@typescript-eslint/no-parameter-properties": "off",
21+
"@nrwl/nx/enforce-module-boundaries": [
22+
"error",
23+
{
24+
"enforceBuildableLibDependency": true,
25+
"allow": [],
26+
"depConstraints": [
27+
{ "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] }
28+
]
29+
}
30+
]
31+
},
32+
"overrides": [
33+
{
34+
"files": ["*.tsx"],
35+
"rules": {
36+
"@typescript-eslint/no-unused-vars": "off"
37+
}
38+
}
39+
]
40+
}

.gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
8+
# dependencies
9+
/node_modules
10+
11+
# IDEs and editors
12+
/.idea
13+
.project
14+
.classpath
15+
.c9/
16+
*.launch
17+
.settings/
18+
*.sublime-workspace
19+
20+
# IDE - VSCode
21+
.vscode/*
22+
!.vscode/settings.json
23+
!.vscode/tasks.json
24+
!.vscode/launch.json
25+
!.vscode/extensions.json
26+
27+
# misc
28+
/.sass-cache
29+
/connect.lock
30+
/coverage
31+
/libpeerconnection.log
32+
npm-debug.log
33+
yarn-error.log
34+
testem.log
35+
/typings
36+
37+
# System Files
38+
.DS_Store
39+
Thumbs.db

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Add files here to ignore them from prettier formatting
2+
3+
/dist
4+
/coverage

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

.vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"ms-vscode.vscode-typescript-tslint-plugin",
4+
"esbenp.prettier-vscode"
5+
]
6+
}

README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# AngularArchitects
2+
3+
This project was generated using [Nx](https://nx.dev).
4+
5+
<p align="center"><img src="https://raw.githubusercontent.com/nrwl/nx/master/nx-logo.png" width="450"></p>
6+
7+
🔎 **Nx is a set of Extensible Dev Tools for Monorepos.**
8+
9+
## Adding capabilities to your workspace
10+
11+
Nx supports many plugins which add capabilities for developing different types of applications and different tools.
12+
13+
These capabilities include generating applications, libraries, etc as well as the devtools to test, and build projects as well.
14+
15+
Below are some plugins which you can add to your workspace:
16+
17+
- [React](https://reactjs.org)
18+
- `npm install --save-dev @nrwl/react`
19+
- Web (no framework frontends)
20+
- `npm install --save-dev @nrwl/web`
21+
- [Angular](https://angular.io)
22+
- `npm install --save-dev @nrwl/angular`
23+
- [Nest](https://nestjs.com)
24+
- `npm install --save-dev @nrwl/nest`
25+
- [Express](https://expressjs.com)
26+
- `npm install --save-dev @nrwl/express`
27+
- [Node](https://nodejs.org)
28+
- `npm install --save-dev @nrwl/node`
29+
30+
## Generate an application
31+
32+
Run `nx g @nrwl/react:app my-app` to generate an application.
33+
34+
> You can use any of the plugins above to generate applications as well.
35+
36+
When using Nx, you can create multiple applications and libraries in the same workspace.
37+
38+
## Generate a library
39+
40+
Run `nx g @nrwl/react:lib my-lib` to generate a library.
41+
42+
> You can also use any of the plugins above to generate libraries as well.
43+
44+
Libraries are sharable across libraries and applications. They can be imported from `@angular-architects/mylib`.
45+
46+
## Development server
47+
48+
Run `nx serve my-app` for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
49+
50+
## Code scaffolding
51+
52+
Run `nx g @nrwl/react:component my-component --project=my-app` to generate a new component.
53+
54+
## Build
55+
56+
Run `nx build my-app` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
57+
58+
## Running unit tests
59+
60+
Run `nx test my-app` to execute the unit tests via [Jest](https://jestjs.io).
61+
62+
Run `nx affected:test` to execute the unit tests affected by a change.
63+
64+
## Running end-to-end tests
65+
66+
Run `ng e2e my-app` to execute the end-to-end tests via [Cypress](https://www.cypress.io).
67+
68+
Run `nx affected:e2e` to execute the end-to-end tests affected by a change.
69+
70+
## Understand your workspace
71+
72+
Run `nx dep-graph` to see a diagram of the dependencies of your projects.
73+
74+
## Further help
75+
76+
Visit the [Nx Documentation](https://nx.dev) to learn more.

apps/.gitkeep

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

apps/ddd-e2e/jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
name: 'ddd-e2e',
3+
preset: '../../jest.config.js',
4+
coverageDirectory: '../../coverage/appsddd-e2e'
5+
};

apps/ddd-e2e/tests/ddd.test.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {
2+
checkFilesExist,
3+
ensureNxProject,
4+
readJson,
5+
runNxCommandAsync,
6+
uniq
7+
} from '@nrwl/nx-plugin/testing';
8+
describe('ddd e2e', () => {
9+
it('should create ddd', async done => {
10+
const plugin = uniq('ddd');
11+
ensureNxProject('@angular-architects/ddd', 'dist/libs/ddd');
12+
await runNxCommandAsync(`generate @angular-architects/ddd:ddd ${plugin}`);
13+
14+
const result = await runNxCommandAsync(`build ${plugin}`);
15+
expect(result.stdout).toContain('Builder ran');
16+
17+
done();
18+
});
19+
20+
describe('--directory', () => {
21+
it('should create src in the specified directory', async done => {
22+
const plugin = uniq('ddd');
23+
ensureNxProject('@angular-architects/ddd', 'dist/libs/ddd');
24+
await runNxCommandAsync(
25+
`generate @angular-architects/ddd:ddd ${plugin} --directory subdir`
26+
);
27+
expect(() =>
28+
checkFilesExist(`libs/subdir/${plugin}/src/index.ts`)
29+
).not.toThrow();
30+
done();
31+
});
32+
});
33+
34+
describe('--tags', () => {
35+
it('should add tags to nx.json', async done => {
36+
const plugin = uniq('ddd');
37+
ensureNxProject('@angular-architects/ddd', 'dist/libs/ddd');
38+
await runNxCommandAsync(
39+
`generate @angular-architects/ddd:ddd ${plugin} --tags e2etag,e2ePackage`
40+
);
41+
const nxJson = readJson('nx.json');
42+
expect(nxJson.projects[plugin].tags).toEqual(['e2etag', 'e2ePackage']);
43+
done();
44+
});
45+
});
46+
});

apps/ddd-e2e/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"types": ["node", "jest"]
5+
},
6+
"include": ["**/*.ts"]
7+
}

apps/ddd-e2e/tsconfig.spec.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"types": ["jest", "node"]
7+
},
8+
"include": ["**/*.spec.ts", "**/*.d.ts"]
9+
}

jest.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
3+
transform: {
4+
'^.+\\.(ts|js|html)$': 'ts-jest'
5+
},
6+
resolver: '@nrwl/jest/plugins/resolver',
7+
moduleFileExtensions: ['ts', 'js', 'html'],
8+
coverageReporters: ['html']
9+
};

libs/.gitkeep

Whitespace-only changes.

libs/ddd/.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "../../.eslintrc", "rules": {} }

libs/ddd/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# @angular-architects/ddd -- DDD Plugin for Nx
2+
3+
```
4+
npm i
5+
```
6+
7+
```
8+
ng g @angular-architects/ddd:domain booking
9+
ng g @angular-architects/ddd:domain boarding
10+
ng g @angular-architects/ddd:feature search --domain booking --app flight-app --entity flight
11+
ng g @angular-architects/ddd:feature cancel --domain booking --app flight-app
12+
ng g @angular-architects/ddd:feature manage --domain boarding --app flight-app
13+
```
14+
15+
```
16+
npm run dep-graph
17+
```

libs/ddd/assets/ddd-libs.png

8.38 KB
Loading

libs/ddd/assets/ddd.png

191 KB
Loading

libs/ddd/assets/domain-layer.png

22.4 KB
Loading

libs/ddd/assets/linting-1.png

70.8 KB
Loading

libs/ddd/assets/linting-2.png

68.9 KB
Loading

libs/ddd/assets/result.png

31 KB
Loading

libs/ddd/collection.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json",
3+
"name": "@angular-architects/ddd",
4+
"version": "0.0.1",
5+
"schematics": {
6+
"domain": {
7+
"factory": "./src/schematics/domain/index",
8+
"schema": "./src/schematics/domain/schema.json",
9+
"description": "adds a domain including a domain folder, domain lib, entries in nx.json, and linting rules in tslint.json"
10+
},
11+
"feature": {
12+
"factory": "./src/schematics/feature/index",
13+
"schema": "./src/schematics/feature/schema.json",
14+
"description": "adds a feature lib to a domain"
15+
}
16+
17+
}
18+
}

libs/ddd/jest.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
name: 'ddd',
3+
preset: '../../jest.config.js',
4+
transform: {
5+
'^.+\\.[tj]sx?$': 'ts-jest'
6+
},
7+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
8+
coverageDirectory: '../../coverage/libs/ddd'
9+
};

libs/ddd/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@angular-architects/ddd",
3+
"version": "0.0.7",
4+
"main": "src/index.js",
5+
"schematics": "./collection.json"
6+
}

libs/ddd/src/index.ts

Whitespace-only changes.

libs/ddd/src/schematics/domain/files/application/.gitkeep

Whitespace-only changes.

libs/ddd/src/schematics/domain/files/entities/.gitkeep

Whitespace-only changes.

libs/ddd/src/schematics/domain/files/infrastructure/.gitkeep

Whitespace-only changes.
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
chain,
3+
externalSchematic,
4+
Rule,
5+
apply,
6+
url,
7+
template,
8+
move,
9+
mergeWith,
10+
noop,
11+
} from '@angular-devkit/schematics';
12+
13+
import { strings } from '@angular-devkit/core';
14+
import { DomainOptions } from './schema';
15+
import { updateLintingRules } from '../utils/update-linting-rules';
16+
17+
export default function(options: DomainOptions): Rule {
18+
const libFolder = strings.dasherize(options.name);
19+
20+
const templateSource = apply(url('./files'), [
21+
template({}),
22+
move(`libs/${libFolder}/domain/src/lib`)
23+
]);
24+
25+
return chain([
26+
externalSchematic('@nrwl/angular', 'lib', {
27+
name: 'domain',
28+
directory: options.name,
29+
tags: `domain:${options.name},type:domain-logic`,
30+
style: 'scss',
31+
}),
32+
updateLintingRules(options.name),
33+
mergeWith(templateSource),
34+
(!options.addApp) ?
35+
noop() :
36+
externalSchematic('@nrwl/angular', 'app', {
37+
name: options.name,
38+
tags: `domain:${options.name},type:app`,
39+
style: 'scss',
40+
}),
41+
]);
42+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "domain-options",
4+
"type": "object",
5+
"properties": {
6+
"name": {
7+
"type": "string",
8+
"description": "Domain name",
9+
"$default": {
10+
"$source": "argv",
11+
"index": 0
12+
}
13+
},
14+
"addApp": {
15+
"type": "boolean",
16+
"description": "Add an app for the domain?",
17+
"default": false
18+
}
19+
},
20+
"required": ["name"]
21+
}

0 commit comments

Comments
 (0)