@wallentaine/cqrs-schematics 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "cqrs-command": {
5
+ "factory": "./src/schematics/cqrs-command",
6
+ "schema": "./src/schematics/cqrs-command/schema.json",
7
+ "description": "Generate CQRS Command files"
8
+ }
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wallentaine/cqrs-schematics",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -8,7 +8,8 @@
8
8
  "prepublishOnly": "npm run build"
9
9
  },
10
10
  "files": [
11
- "dist/**/*"
11
+ "src/**/*",
12
+ "collection.json"
12
13
  ],
13
14
  "keywords": [
14
15
  "nestjs",
@@ -24,5 +25,6 @@
24
25
  },
25
26
  "dependencies": {
26
27
  "@angular-devkit/schematics": "^19.2.19"
27
- }
28
+ },
29
+ "schematics": "./collection.json"
28
30
  }
@@ -0,0 +1,7 @@
1
+ import { Command, CommandProps } from '@Libs/DDD/Command.base';
2
+
3
+ export class <%= className %>Command extends Command {
4
+ public constructor(props: CommandProps<<%= className %>Command>) {
5
+ super(props);
6
+ }
7
+ }
@@ -0,0 +1,12 @@
1
+ import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
2
+ import { <%= className %>Command } from './<%= name %>.command';
3
+
4
+ @CommandHandler(<%= className %>Command)
5
+ export class <%= className %>CommandHandler implements ICommandHandler<<%= className %>Command> {
6
+
7
+ public constructor() {}
8
+
9
+ async execute(command: <%= className %>Command): Promise<any> {
10
+ // Implement your command logic here
11
+ }
12
+ }
@@ -0,0 +1,18 @@
1
+ import { Controller, Post, Body } from '@nestjs/common';
2
+ import { CommandBus } from '@nestjs/cqrs';
3
+ import { CommandResponse } from '@Libs/types/CQRSResponse.type';
4
+ import { <%= className %>Command } from './<%= name %>.command';
5
+ import { <%= className %>CommandHandler } from './<%= name %>.commandHandler';
6
+
7
+ @Controller('')
8
+ export class <%= className %>Controller {
9
+ public constructor(private readonly commandBus: CommandBus) {}
10
+
11
+ @Post()
12
+ async create(@Body() data: {}): Promise<void> {
13
+ return this.commandBus.execute<
14
+ <%= className %>Command,
15
+ CommandResponse<<%= className %>CommandHandler>
16
+ >(new <%= className %>Command({}));
17
+ }
18
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,IAAI,EAIJ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,UAAU,CAAC;AAEpD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAuBtE"}
@@ -0,0 +1,38 @@
1
+ import {
2
+ apply,
3
+ applyTemplates,
4
+ chain,
5
+ mergeWith,
6
+ move,
7
+ Rule,
8
+ SchematicContext,
9
+ Tree,
10
+ url,
11
+ } from "@angular-devkit/schematics";
12
+ import { strings } from "@angular-devkit/core";
13
+ import { Schema as CommandOptions } from "./schema";
14
+
15
+ export default function commandSchematic(options: CommandOptions): Rule {
16
+ return (tree: Tree, context: SchematicContext) => {
17
+ console.log(options);
18
+
19
+ const classifiedName = strings.classify(options.name);
20
+
21
+ const modulePath = options.module ? `/${options.module}` : "";
22
+ const targetPath = `${options.path}${modulePath}/Commands/${classifiedName}`;
23
+
24
+ const templateSource = apply(url("./files"), [
25
+ applyTemplates({
26
+ ...strings,
27
+ ...options,
28
+ name: classifiedName,
29
+ className: classifiedName,
30
+ }),
31
+ move(targetPath),
32
+ ]);
33
+
34
+ const rules: Rule[] = [mergeWith(templateSource)];
35
+
36
+ return chain(rules)(tree, context);
37
+ };
38
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IAEb,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,yBAAyB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,iCAAiC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,+BAA+B;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,yCAAyC;IACzC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB"}
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "CqrsCommand",
4
+ "title": "CQRS Command Schematic",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The name of the command",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the command?"
15
+ },
16
+ "module": {
17
+ "type": "string",
18
+ "description": "Module name",
19
+ "x-prompt": "What name would you like to use for the Module?"
20
+ },
21
+ "path": {
22
+ "type": "string",
23
+ "description": "The path where to create the files",
24
+ "default": "src"
25
+ },
26
+ "prefix": {
27
+ "type": "string",
28
+ "description": "Command prefix (Create, Update, Delete)",
29
+ "default": "Create",
30
+ "x-prompt": "What prefix would you like to use? (Create, Update, Delete)"
31
+ }
32
+ },
33
+ "required": ["name", "module"]
34
+ }
@@ -0,0 +1,20 @@
1
+ export interface Schema {
2
+ /** Имя команды (например: CreatePost) */
3
+ name: string;
4
+
5
+ /** Модуль, в который добавить команду */
6
+ module?: string;
7
+
8
+ /** Путь для генерации */
9
+ path?: string;
10
+
11
+ /** Пропустить импорт в модуль */
12
+ skipImport?: boolean;
13
+
14
+ /** Плоская структура файлов */
15
+ flat?: boolean;
16
+
17
+ /** Специфические для команды свойства */
18
+ hasDto?: boolean;
19
+ hasResponse?: boolean;
20
+ }
@@ -1,10 +0,0 @@
1
- {
2
- "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
3
- "schematics": {
4
- "cqrs-command": {
5
- "factory": "./schematics/cqrs-command",
6
- "schema": "./schematics/cqrs-command/schema.json",
7
- "description": "Generate CQRS Command files"
8
- }
9
- }
10
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/schematics/cqrs-command/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,IAAI,EAIJ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,UAAU,CAAC;AAEpD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAuBtE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/schematics/cqrs-command/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IAEb,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,yBAAyB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,iCAAiC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,+BAA+B;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,yCAAyC;IACzC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB"}
@@ -1,34 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/schema",
3
- "$id": "CqrsCommand",
4
- "title": "CQRS Command Schematic",
5
- "type": "object",
6
- "properties": {
7
- "name": {
8
- "type": "string",
9
- "description": "The name of the command",
10
- "$default": {
11
- "$source": "argv",
12
- "index": 0
13
- },
14
- "x-prompt": "What name would you like to use for the command?"
15
- },
16
- "module": {
17
- "type": "string",
18
- "description": "Module name",
19
- "x-prompt": "What name would you like to use for the Module?"
20
- },
21
- "path": {
22
- "type": "string",
23
- "description": "The path where to create the files",
24
- "default": "src"
25
- },
26
- "prefix": {
27
- "type": "string",
28
- "description": "Command prefix (Create, Update, Delete)",
29
- "default": "Create",
30
- "x-prompt": "What prefix would you like to use? (Create, Update, Delete)"
31
- }
32
- },
33
- "required": ["name", "module"]
34
- }
File without changes
File without changes