@necord/schematics 1.2.0 → 1.3.0

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.
Files changed (38) hide show
  1. package/README.md +2 -1
  2. package/dist/collection.json +24 -0
  3. package/dist/command/command-options.interface.d.ts +5 -0
  4. package/dist/command/command-options.interface.js +2 -0
  5. package/dist/command/command-type.enum.d.ts +4 -0
  6. package/dist/command/command-type.enum.js +8 -0
  7. package/dist/command/command.spec.d.ts +1 -0
  8. package/dist/command/command.spec.js +31 -0
  9. package/dist/command/files/slash-command/__name@dasherize__.commands.ts.template +13 -0
  10. package/dist/command/files/text-command/__name@dasherize__.commands.ts.template +13 -0
  11. package/dist/command/index.d.ts +3 -0
  12. package/dist/command/index.js +27 -0
  13. package/dist/command/schema.json +15 -2
  14. package/dist/component/component-options.interface.d.ts +5 -0
  15. package/dist/component/component-options.interface.js +2 -0
  16. package/dist/component/component-type.enum.d.ts +4 -0
  17. package/dist/component/component-type.enum.js +8 -0
  18. package/dist/component/component.spec.d.ts +1 -0
  19. package/dist/component/component.spec.js +31 -0
  20. package/dist/component/files/button/__name@dasherize__.components.ts.template +10 -0
  21. package/dist/component/files/select/__name@dasherize__.components.ts.template +10 -0
  22. package/dist/component/index.d.ts +3 -0
  23. package/dist/component/index.js +27 -0
  24. package/dist/{modals → component}/schema.json +15 -2
  25. package/dist/context-menu/context-menu-options.interface.d.ts +1 -1
  26. package/dist/context-menu/context-menu.spec.d.ts +1 -0
  27. package/dist/context-menu/context-menu.spec.js +31 -0
  28. package/dist/context-menu/files/message-menu/__name@dasherize__.commands.ts.template +1 -1
  29. package/dist/context-menu/files/user-menu/__name@dasherize__.commands.ts.template +1 -1
  30. package/dist/context-menu/index.js +1 -1
  31. package/dist/context-menu/schema.json +1 -1
  32. package/dist/modal/files/__name@dasherize__.modals.ts.template +12 -0
  33. package/dist/modal/index.d.ts +3 -0
  34. package/dist/modal/index.js +18 -0
  35. package/dist/modal/modal.spec.d.ts +1 -0
  36. package/dist/modal/modal.spec.js +18 -0
  37. package/package.json +1 -1
  38. /package/dist/{message-component → modal}/schema.json +0 -0
package/README.md CHANGED
@@ -21,7 +21,8 @@ schematics --help
21
21
  Now you can execute generation commands.
22
22
 
23
23
  ```bash
24
- schematics @necord/schematics:command
24
+ yarn build
25
+ schematics .:command
25
26
  ```
26
27
 
27
28
  ### Unit Testing
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
3
3
  "schematics": {
4
+ "command": {
5
+ "description": "Generates a command component.",
6
+ "factory": "./command/index#command",
7
+ "schema": "./command/schema.json",
8
+ "aliases": [
9
+ "c"
10
+ ]
11
+ },
4
12
  "context-menu": {
5
13
  "description": "Generates a context menu component.",
6
14
  "factory": "./context-menu/index#contextMenu",
@@ -8,6 +16,22 @@
8
16
  "aliases": [
9
17
  "cm"
10
18
  ]
19
+ },
20
+ "component": {
21
+ "description": "Generates a component.",
22
+ "factory": "./component/index#component",
23
+ "schema": "./component/schema.json",
24
+ "aliases": [
25
+ "com"
26
+ ]
27
+ },
28
+ "modal": {
29
+ "description": "Generates a modal component.",
30
+ "factory": "./modal/index#modal",
31
+ "schema": "./modal/schema.json",
32
+ "aliases": [
33
+ "m"
34
+ ]
11
35
  }
12
36
  }
13
37
  }
@@ -0,0 +1,5 @@
1
+ import { CommonOptions } from '../common';
2
+ import { CommandType } from './command-type.enum';
3
+ export interface CommandOptions extends CommonOptions {
4
+ strategy: CommandType;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export declare enum CommandType {
2
+ SLASH_COMMAND = "slash-command",
3
+ TEXT_COMMAND = "text-command"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandType = void 0;
4
+ var CommandType;
5
+ (function (CommandType) {
6
+ CommandType["SLASH_COMMAND"] = "slash-command";
7
+ CommandType["TEXT_COMMAND"] = "text-command";
8
+ })(CommandType = exports.CommandType || (exports.CommandType = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_test_1 = require("node:test");
4
+ const testing_1 = require("@angular-devkit/schematics/testing");
5
+ const path_1 = require("path");
6
+ const command_type_enum_1 = require("./command-type.enum");
7
+ (0, node_test_1.describe)('Command Factory', () => {
8
+ const runner = new testing_1.SchematicTestRunner('.', (0, path_1.join)(process.cwd(), 'src/collection.json'));
9
+ it('should generate a text command', async () => {
10
+ const options = {
11
+ name: 'Text',
12
+ flat: false,
13
+ sourceRoot: '',
14
+ spec: false,
15
+ strategy: command_type_enum_1.CommandType.TEXT_COMMAND
16
+ };
17
+ const tree = await runner.runSchematicAsync('command', options).toPromise();
18
+ expect(tree.files).toEqual(['/text/text.commands.ts']);
19
+ });
20
+ it('should generate a slash command', async () => {
21
+ const options = {
22
+ name: 'Slash',
23
+ flat: false,
24
+ sourceRoot: '',
25
+ spec: false,
26
+ strategy: command_type_enum_1.CommandType.SLASH_COMMAND
27
+ };
28
+ const tree = await runner.runSchematicAsync('command', options).toPromise();
29
+ expect(tree.files).toEqual(['/slash/slash.commands.ts']);
30
+ });
31
+ });
@@ -0,0 +1,13 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { Context, SlashCommand, SlashCommandContext } from 'necord';
3
+
4
+ @Injectable()
5
+ export class <%= classify(name) %>Commands {
6
+ @SlashCommand({
7
+ name: '<%= name.toLowerCase() %>',
8
+ description: '<%= name %>'
9
+ })
10
+ public <%= name %>(@Context() [interaction]: SlashCommandContext) {
11
+ return interaction.reply({ content: 'Pong!' });
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { Context, TextCommand, TextCommandContext, Arguments } from 'necord';
3
+
4
+ @Injectable()
5
+ export class <%= classify(name) %>Commands {
6
+ @TextCommand({
7
+ name: '<%= name.toLowerCase() %>',
8
+ description: '<%= name %>',
9
+ })
10
+ public <%= name %>(@Context() [message]: TextCommandContext, @Arguments() args: string[]) {
11
+ return message.reply('pong!');
12
+ }
13
+ }
@@ -0,0 +1,3 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ import { CommandOptions } from './command-options.interface';
3
+ export declare function command(options: CommandOptions): Rule;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const common_1 = require("../common");
5
+ const command_type_enum_1 = require("./command-type.enum");
6
+ class CommandSchematicFactory extends common_1.CommonSchematicFactory {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.type = 'command';
10
+ }
11
+ generate(options) {
12
+ switch (options.strategy) {
13
+ case command_type_enum_1.CommandType.TEXT_COMMAND:
14
+ this.templatePath = './files/text-command';
15
+ break;
16
+ case command_type_enum_1.CommandType.SLASH_COMMAND:
17
+ this.templatePath = './files/slash-command';
18
+ break;
19
+ }
20
+ return super.generate(options);
21
+ }
22
+ }
23
+ function command(options) {
24
+ const commandFactory = new CommandSchematicFactory();
25
+ return commandFactory.create(options);
26
+ }
27
+ exports.command = command;
@@ -3,7 +3,8 @@
3
3
  "name": {
4
4
  "type": "string",
5
5
  "minLength": 1,
6
- "x-prompt": "What is the questions set name?"
6
+ "description": "Command name",
7
+ "x-prompt": "What is the command name?"
7
8
  },
8
9
  "path": {
9
10
  "type": "string",
@@ -25,6 +26,18 @@
25
26
  "default": true,
26
27
  "description": "Specifies if a spec file is generated.",
27
28
  "x-prompt": "Generate spec file as well?"
29
+ },
30
+ "strategy": {
31
+ "type": "string",
32
+ "description": "The type of command to create.",
33
+ "enum": [
34
+ "slash-command",
35
+ "text-command"
36
+ ],
37
+ "x-prompt": "What type you want to use?"
28
38
  }
29
- }
39
+ },
40
+ "required": [
41
+ "strategy"
42
+ ]
30
43
  }
@@ -0,0 +1,5 @@
1
+ import { CommonOptions } from '../common';
2
+ import { ComponentType } from './component-type.enum';
3
+ export interface ComponentOptions extends CommonOptions {
4
+ strategy: ComponentType;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export declare enum ComponentType {
2
+ Button = "button",
3
+ Select = "select"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComponentType = void 0;
4
+ var ComponentType;
5
+ (function (ComponentType) {
6
+ ComponentType["Button"] = "button";
7
+ ComponentType["Select"] = "select";
8
+ })(ComponentType = exports.ComponentType || (exports.ComponentType = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_test_1 = require("node:test");
4
+ const testing_1 = require("@angular-devkit/schematics/testing");
5
+ const path_1 = require("path");
6
+ const component_type_enum_1 = require("./component-type.enum");
7
+ (0, node_test_1.describe)('Component Factory', () => {
8
+ const runner = new testing_1.SchematicTestRunner('.', (0, path_1.join)(process.cwd(), 'src/collection.json'));
9
+ it('should generate button', async () => {
10
+ const options = {
11
+ name: 'Button',
12
+ flat: false,
13
+ sourceRoot: '',
14
+ spec: false,
15
+ strategy: component_type_enum_1.ComponentType.Button
16
+ };
17
+ const tree = await runner.runSchematicAsync('component', options).toPromise();
18
+ expect(tree.files).toEqual(['/button/button.components.ts']);
19
+ });
20
+ it('should generate select', async () => {
21
+ const options = {
22
+ name: 'Select',
23
+ flat: false,
24
+ sourceRoot: '',
25
+ spec: false,
26
+ strategy: component_type_enum_1.ComponentType.Select
27
+ };
28
+ const tree = await runner.runSchematicAsync('component', options).toPromise();
29
+ expect(tree.files).toEqual(['/select/select.components.ts']);
30
+ });
31
+ });
@@ -0,0 +1,10 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { Context, Button, ButtonContext } from 'necord';
3
+
4
+ @Injectable()
5
+ export class <%= classify(name) %>Components {
6
+ @Button('<%= name %>')
7
+ public <%= name %>(@Context() [interaction]: ButtonContext) {
8
+ return interaction.reply({ content: 'Button clicked!' });
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { Context, SelectMenu, SelectMenuContext, Values } from 'necord';
3
+
4
+ @Injectable()
5
+ export class <%= classify(name) %>Components {
6
+ @SelectMenu('<%= name %>')
7
+ public <%= name %>(@Context() [interaction]: SelectMenuContext, @Values() values: string[]) {
8
+ return interaction.reply({ content: `Your selected color - ${values.join(' ')}` });
9
+ }
10
+ }
@@ -0,0 +1,3 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ import { ComponentOptions } from './component-options.interface';
3
+ export declare function component(options: ComponentOptions): Rule;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.component = void 0;
4
+ const common_1 = require("../common");
5
+ const component_type_enum_1 = require("./component-type.enum");
6
+ class ComponentSchematicFactory extends common_1.CommonSchematicFactory {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.type = 'component';
10
+ }
11
+ generate(options) {
12
+ switch (options.strategy) {
13
+ case component_type_enum_1.ComponentType.Button:
14
+ this.templatePath = './files/button';
15
+ break;
16
+ case component_type_enum_1.ComponentType.Select:
17
+ this.templatePath = './files/select';
18
+ break;
19
+ }
20
+ return super.generate(options);
21
+ }
22
+ }
23
+ function component(options) {
24
+ const commandFactory = new ComponentSchematicFactory();
25
+ return commandFactory.create(options);
26
+ }
27
+ exports.component = component;
@@ -3,7 +3,8 @@
3
3
  "name": {
4
4
  "type": "string",
5
5
  "minLength": 1,
6
- "x-prompt": "What is the questions set name?"
6
+ "description": "Command name",
7
+ "x-prompt": "What is the command name?"
7
8
  },
8
9
  "path": {
9
10
  "type": "string",
@@ -25,6 +26,18 @@
25
26
  "default": true,
26
27
  "description": "Specifies if a spec file is generated.",
27
28
  "x-prompt": "Generate spec file as well?"
29
+ },
30
+ "strategy": {
31
+ "type": "string",
32
+ "description": "The type of component to create.",
33
+ "enum": [
34
+ "button",
35
+ "select"
36
+ ],
37
+ "x-prompt": "What type you want to use?"
28
38
  }
29
- }
39
+ },
40
+ "required": [
41
+ "strategy"
42
+ ]
30
43
  }
@@ -1,5 +1,5 @@
1
1
  import { CommonOptions } from '../common';
2
2
  import { ContextMenuType } from './context-menu-type.enum';
3
3
  export interface ContextMenuOptions extends CommonOptions {
4
- 'context-menu-type': ContextMenuType;
4
+ strategy: ContextMenuType;
5
5
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_test_1 = require("node:test");
4
+ const testing_1 = require("@angular-devkit/schematics/testing");
5
+ const path_1 = require("path");
6
+ const context_menu_type_enum_1 = require("./context-menu-type.enum");
7
+ (0, node_test_1.describe)('Context Menu Factory', () => {
8
+ const runner = new testing_1.SchematicTestRunner('.', (0, path_1.join)(process.cwd(), 'src/collection.json'));
9
+ it('should generate a message context menu', async () => {
10
+ const options = {
11
+ name: 'Message',
12
+ flat: false,
13
+ sourceRoot: '',
14
+ spec: false,
15
+ strategy: context_menu_type_enum_1.ContextMenuType.Message
16
+ };
17
+ const tree = await runner.runSchematicAsync('context-menu', options).toPromise();
18
+ expect(tree.files).toEqual(['/message/message.commands.ts']);
19
+ });
20
+ it('should generate a user context menu', async () => {
21
+ const options = {
22
+ name: 'User',
23
+ flat: false,
24
+ sourceRoot: '',
25
+ spec: false,
26
+ strategy: context_menu_type_enum_1.ContextMenuType.User
27
+ };
28
+ const tree = await runner.runSchematicAsync('context-menu', options).toPromise();
29
+ expect(tree.files).toEqual(['/user/user.commands.ts']);
30
+ });
31
+ });
@@ -5,7 +5,7 @@ import { Message } from 'discord.js';
5
5
  @Injectable()
6
6
  export class <%= classify(name) %>Commands {
7
7
  @MessageCommand({ name: '<%= name.toLowerCase() %>' })
8
- public async copyMessage(
8
+ public copyMessage(
9
9
  @Context() [interaction]: MessageCommandContext,
10
10
  @TargetMessage() message: Message
11
11
  ) {
@@ -5,7 +5,7 @@ import { User } from 'discord.js';
5
5
  @Injectable()
6
6
  export class <%= classify(name) %>Commands {
7
7
  @UserCommand({ name: '<%= name.toLowerCase() %>' })
8
- public async <%= name %>(
8
+ public <%= name %>(
9
9
  @Context() [interaction]: UserCommandContext,
10
10
  @TargetUser() user: User
11
11
  ) {
@@ -9,7 +9,7 @@ class ContextMenuSchematicFactory extends common_1.CommonSchematicFactory {
9
9
  this.type = 'context-menu';
10
10
  }
11
11
  generate(options) {
12
- switch (options['context-menu-type']) {
12
+ switch (options.strategy) {
13
13
  case context_menu_type_enum_1.ContextMenuType.Message:
14
14
  this.templatePath = './files/message-menu';
15
15
  break;
@@ -38,6 +38,6 @@
38
38
  }
39
39
  },
40
40
  "required": [
41
- "context-menu-type"
41
+ "strategy"
42
42
  ]
43
43
  }
@@ -0,0 +1,12 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { Context, Modal, ModalContext } from 'necord';
3
+
4
+ @Injectable()
5
+ export class <%= classify(name) %>Modals {
6
+ @Modal('<%= name %>')
7
+ public <%= name %>(@Ctx() [interaction]: ModalContext) {
8
+ return interaction.reply({
9
+ content: `Your fav pizza : ${interaction.fields.getTextInputValue('pizza')}`
10
+ });
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ import { CommonOptions } from '../common';
2
+ import { Rule } from '@angular-devkit/schematics';
3
+ export declare function modal(options: CommonOptions): Rule;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modal = void 0;
4
+ const common_1 = require("../common");
5
+ class ModalSchematicFactory extends common_1.CommonSchematicFactory {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.type = 'modal';
9
+ }
10
+ generate(options) {
11
+ return super.generate(options);
12
+ }
13
+ }
14
+ function modal(options) {
15
+ const modalFactory = new ModalSchematicFactory();
16
+ return modalFactory.create(options);
17
+ }
18
+ exports.modal = modal;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_test_1 = require("node:test");
4
+ const testing_1 = require("@angular-devkit/schematics/testing");
5
+ const path_1 = require("path");
6
+ (0, node_test_1.describe)('Modal Factory', () => {
7
+ const runner = new testing_1.SchematicTestRunner('.', (0, path_1.join)(process.cwd(), 'src/collection.json'));
8
+ it('should generate a modal', async () => {
9
+ const options = {
10
+ name: 'Modal',
11
+ flat: false,
12
+ sourceRoot: '',
13
+ spec: false
14
+ };
15
+ const tree = await runner.runSchematicAsync('modal', options).toPromise();
16
+ expect(tree.files).toEqual(['/modal/modal.modals.ts']);
17
+ });
18
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@necord/schematics",
3
3
  "description": "A collection of schematics for Necord projects with NestJS",
4
- "version": "1.2.0",
4
+ "version": "1.3.0",
5
5
  "scripts": {
6
6
  "build": "rimraf -rf dist && tsc -p tsconfig.json",
7
7
  "postbuild": "npm run copy:collection && npm run copy:lib",
File without changes