@necord/schematics 1.1.3 → 1.1.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.
- package/package.json +6 -4
- package/src/collection.json +13 -0
- package/src/command/schema.json +30 -0
- package/src/common/common-options.interface.ts +12 -0
- package/src/common/index.ts +88 -0
- package/{dist/context-menu/context-menu-options.interface.d.ts → src/context-menu/context-menu-options.interface.ts} +2 -1
- package/src/context-menu/context-menu-type.enum.ts +4 -0
- package/src/context-menu/files/user-menu/__name@dasherize__.commands.ts.template +14 -0
- package/src/context-menu/index.ts +26 -0
- package/src/context-menu/schema.json +42 -0
- package/src/message-component/schema.json +30 -0
- package/src/modals/schema.json +30 -0
- package/.prettierrc +0 -8
- package/.release-it.json +0 -8
- package/dist/common/common-options.interface.d.ts +0 -11
- package/dist/common/common-options.interface.js +0 -2
- package/dist/common/index.d.ts +0 -12
- package/dist/common/index.js +0 -74
- package/dist/context-menu/context-menu-options.interface.js +0 -2
- package/dist/context-menu/context-menu-type.enum.d.ts +0 -4
- package/dist/context-menu/context-menu-type.enum.js +0 -8
- package/dist/context-menu/index.d.ts +0 -3
- package/dist/context-menu/index.js +0 -27
- package/jest.config.json +0 -13
- package/test/.keep +0 -0
- /package/{dist/index.d.ts → src/context-menu/files/message-menu/__name@dasherize__.commands.ts.template} +0 -0
- /package/{dist/index.js → src/index.ts} +0 -0
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.1.
|
|
4
|
+
"version": "1.1.5",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf -rf dist && tsc -p tsconfig.json",
|
|
7
7
|
"prepublish:npm": "npm run build",
|
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
"lint": "eslint --ignore-path .gitignore {integration,src}/**/*.ts",
|
|
14
14
|
"test": "jest"
|
|
15
15
|
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"schematics": "./src/collection.json",
|
|
17
|
+
"files": [
|
|
18
|
+
"src",
|
|
19
|
+
"*.md"
|
|
20
|
+
],
|
|
18
21
|
"publishConfig": {
|
|
19
22
|
"access": "public"
|
|
20
23
|
},
|
|
21
|
-
"schematics": "./src/collection.json",
|
|
22
24
|
"author": "Alexey Filippov <socket.someone@gmail.com>",
|
|
23
25
|
"license": "MIT",
|
|
24
26
|
"keywords": [
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
3
|
+
"schematics": {
|
|
4
|
+
"context-menu": {
|
|
5
|
+
"description": "Generates a context menu component.",
|
|
6
|
+
"factory": "./context-menu/index#contextMenu",
|
|
7
|
+
"schema": "./context-menu/schema.json",
|
|
8
|
+
"aliases": [
|
|
9
|
+
"cm"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"properties": {
|
|
3
|
+
"name": {
|
|
4
|
+
"type": "string",
|
|
5
|
+
"minLength": 1,
|
|
6
|
+
"x-prompt": "What is the questions set name?"
|
|
7
|
+
},
|
|
8
|
+
"path": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"format": "path",
|
|
11
|
+
"description": "The path to create the service."
|
|
12
|
+
},
|
|
13
|
+
"sourceRoot": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Nest service source root directory."
|
|
16
|
+
},
|
|
17
|
+
"flat": {
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"default": false,
|
|
20
|
+
"description": "Flag to indicate if a directory is created.",
|
|
21
|
+
"x-prompt": "Create a directory?"
|
|
22
|
+
},
|
|
23
|
+
"spec": {
|
|
24
|
+
"type": "boolean",
|
|
25
|
+
"default": true,
|
|
26
|
+
"description": "Specifies if a spec file is generated.",
|
|
27
|
+
"x-prompt": "Generate spec file as well?"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Path, strings } from '@angular-devkit/core';
|
|
2
|
+
import {
|
|
3
|
+
apply,
|
|
4
|
+
applyTemplates,
|
|
5
|
+
branchAndMerge,
|
|
6
|
+
chain,
|
|
7
|
+
filter,
|
|
8
|
+
mergeWith,
|
|
9
|
+
move,
|
|
10
|
+
noop,
|
|
11
|
+
Rule,
|
|
12
|
+
SchematicContext,
|
|
13
|
+
SchematicsException,
|
|
14
|
+
Source,
|
|
15
|
+
Tree,
|
|
16
|
+
url
|
|
17
|
+
} from '@angular-devkit/schematics';
|
|
18
|
+
import {
|
|
19
|
+
DeclarationOptions,
|
|
20
|
+
Location,
|
|
21
|
+
mergeSourceRoot,
|
|
22
|
+
ModuleDeclarator,
|
|
23
|
+
ModuleFinder,
|
|
24
|
+
NameParser
|
|
25
|
+
} from '@nestjs/schematics';
|
|
26
|
+
import { join } from 'path';
|
|
27
|
+
import { CommonOptions } from './common-options.interface';
|
|
28
|
+
|
|
29
|
+
export * from './common-options.interface';
|
|
30
|
+
|
|
31
|
+
export class CommonSchematicFactory<T extends CommonOptions = CommonOptions> {
|
|
32
|
+
public templatePath = './files';
|
|
33
|
+
public type = 'service';
|
|
34
|
+
public metadata = 'providers';
|
|
35
|
+
|
|
36
|
+
public create(options: T): Rule {
|
|
37
|
+
options = this.transform(options);
|
|
38
|
+
return branchAndMerge(
|
|
39
|
+
chain([mergeWith(this.generate(options)), this.addDeclarationToModule(options), mergeSourceRoot(options)])
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public generate(options: T): Source {
|
|
44
|
+
return (context: SchematicContext) =>
|
|
45
|
+
apply(url(join(this.templatePath as Path)), [
|
|
46
|
+
options.spec ? noop() : filter((path: string) => !path.endsWith('.spec.ts')),
|
|
47
|
+
applyTemplates({
|
|
48
|
+
...strings,
|
|
49
|
+
...options,
|
|
50
|
+
lowercase: (str: string) => str.toLowerCase()
|
|
51
|
+
}),
|
|
52
|
+
move(options.path ?? '')
|
|
53
|
+
])(context);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public addDeclarationToModule(options: T): Rule {
|
|
57
|
+
return (tree: Tree) => {
|
|
58
|
+
options.module = new ModuleFinder(tree).find({
|
|
59
|
+
name: options.name,
|
|
60
|
+
path: options.path as Path
|
|
61
|
+
});
|
|
62
|
+
if (options.module === undefined || options.module === null) {
|
|
63
|
+
return tree;
|
|
64
|
+
}
|
|
65
|
+
const rawContent = tree.read(options.module);
|
|
66
|
+
const content = rawContent?.toString() ?? '';
|
|
67
|
+
const declarator: ModuleDeclarator = new ModuleDeclarator();
|
|
68
|
+
tree.overwrite(options.module, declarator.declare(content, options as DeclarationOptions));
|
|
69
|
+
return tree;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public transform(source: T): T {
|
|
74
|
+
const target: T = Object.assign({}, source);
|
|
75
|
+
target.metadata = this.metadata;
|
|
76
|
+
target.type = this.type;
|
|
77
|
+
|
|
78
|
+
if (target.name === null || target.name === undefined) {
|
|
79
|
+
throw new SchematicsException('Option (name) is required.');
|
|
80
|
+
}
|
|
81
|
+
const location: Location = new NameParser().parse(target);
|
|
82
|
+
target.name = strings.dasherize(location.name);
|
|
83
|
+
target.path = strings.dasherize(location.path);
|
|
84
|
+
|
|
85
|
+
target.path = target.flat ? target.path : join(target.path as Path, target.name);
|
|
86
|
+
return target;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { Context, UserCommand, UserCommandContext, TargetUser } from 'necord';
|
|
3
|
+
import { User } from 'discord.js';
|
|
4
|
+
|
|
5
|
+
@Injectable()
|
|
6
|
+
export class <%= classify(name) %>Commands {
|
|
7
|
+
@UserCommand({ name: <%= name.toLowerCase() %> })
|
|
8
|
+
public async <%= name %>(
|
|
9
|
+
@Context() [interaction]: UserCommandContext,
|
|
10
|
+
@TargetUser() user: User
|
|
11
|
+
) {
|
|
12
|
+
return interaction.reply({ content: `Hello ${user.username}!` });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CommonSchematicFactory } from '../common';
|
|
2
|
+
import { ContextMenuOptions } from './context-menu-options.interface';
|
|
3
|
+
import { Rule, Source } from '@angular-devkit/schematics';
|
|
4
|
+
import { ContextMenuType } from './context-menu-type.enum';
|
|
5
|
+
|
|
6
|
+
class ContextMenuSchematicFactory extends CommonSchematicFactory<ContextMenuOptions> {
|
|
7
|
+
public type = 'context-menu';
|
|
8
|
+
|
|
9
|
+
generate(options: ContextMenuOptions): Source {
|
|
10
|
+
switch (options.type) {
|
|
11
|
+
case ContextMenuType.Message:
|
|
12
|
+
this.templatePath = './files/message-menu';
|
|
13
|
+
break;
|
|
14
|
+
case ContextMenuType.User:
|
|
15
|
+
this.templatePath = './files/user-menu';
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return super.generate(options);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function contextMenu(options: ContextMenuOptions): Rule {
|
|
24
|
+
const contextMenuFactory = new ContextMenuSchematicFactory();
|
|
25
|
+
return contextMenuFactory.create(options);
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"properties": {
|
|
3
|
+
"name": {
|
|
4
|
+
"type": "string",
|
|
5
|
+
"minLength": 1,
|
|
6
|
+
"description": "Command name",
|
|
7
|
+
"x-prompt": "What is the command name?"
|
|
8
|
+
},
|
|
9
|
+
"path": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"format": "path",
|
|
12
|
+
"description": "The path to create the service."
|
|
13
|
+
},
|
|
14
|
+
"sourceRoot": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Nest service source root directory."
|
|
17
|
+
},
|
|
18
|
+
"flat": {
|
|
19
|
+
"type": "boolean",
|
|
20
|
+
"default": false,
|
|
21
|
+
"description": "Flag to indicate if a directory is created.",
|
|
22
|
+
"x-prompt": "Create a directory?"
|
|
23
|
+
},
|
|
24
|
+
"spec": {
|
|
25
|
+
"type": "boolean",
|
|
26
|
+
"default": true,
|
|
27
|
+
"description": "Specifies if a spec file is generated.",
|
|
28
|
+
"x-prompt": "Generate spec file as well?"
|
|
29
|
+
},
|
|
30
|
+
"type": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"description": "The type of context menu to create.",
|
|
33
|
+
"enum": [
|
|
34
|
+
"message",
|
|
35
|
+
"user"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"required": [
|
|
40
|
+
"type"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"properties": {
|
|
3
|
+
"name": {
|
|
4
|
+
"type": "string",
|
|
5
|
+
"minLength": 1,
|
|
6
|
+
"x-prompt": "What is the questions set name?"
|
|
7
|
+
},
|
|
8
|
+
"path": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"format": "path",
|
|
11
|
+
"description": "The path to create the service."
|
|
12
|
+
},
|
|
13
|
+
"sourceRoot": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Nest service source root directory."
|
|
16
|
+
},
|
|
17
|
+
"flat": {
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"default": false,
|
|
20
|
+
"description": "Flag to indicate if a directory is created.",
|
|
21
|
+
"x-prompt": "Create a directory?"
|
|
22
|
+
},
|
|
23
|
+
"spec": {
|
|
24
|
+
"type": "boolean",
|
|
25
|
+
"default": true,
|
|
26
|
+
"description": "Specifies if a spec file is generated.",
|
|
27
|
+
"x-prompt": "Generate spec file as well?"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"properties": {
|
|
3
|
+
"name": {
|
|
4
|
+
"type": "string",
|
|
5
|
+
"minLength": 1,
|
|
6
|
+
"x-prompt": "What is the questions set name?"
|
|
7
|
+
},
|
|
8
|
+
"path": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"format": "path",
|
|
11
|
+
"description": "The path to create the service."
|
|
12
|
+
},
|
|
13
|
+
"sourceRoot": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Nest service source root directory."
|
|
16
|
+
},
|
|
17
|
+
"flat": {
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"default": false,
|
|
20
|
+
"description": "Flag to indicate if a directory is created.",
|
|
21
|
+
"x-prompt": "Create a directory?"
|
|
22
|
+
},
|
|
23
|
+
"spec": {
|
|
24
|
+
"type": "boolean",
|
|
25
|
+
"default": true,
|
|
26
|
+
"description": "Specifies if a spec file is generated.",
|
|
27
|
+
"x-prompt": "Generate spec file as well?"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/.prettierrc
DELETED
package/.release-it.json
DELETED
package/dist/common/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Rule, Source } from '@angular-devkit/schematics';
|
|
2
|
-
import { CommonOptions } from './common-options.interface';
|
|
3
|
-
export * from './common-options.interface';
|
|
4
|
-
export declare class CommonSchematicFactory<T extends CommonOptions = CommonOptions> {
|
|
5
|
-
templatePath: string;
|
|
6
|
-
type: string;
|
|
7
|
-
metadata: string;
|
|
8
|
-
create(options: T): Rule;
|
|
9
|
-
generate(options: T): Source;
|
|
10
|
-
addDeclarationToModule(options: T): Rule;
|
|
11
|
-
transform(source: T): T;
|
|
12
|
-
}
|
package/dist/common/index.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.CommonSchematicFactory = void 0;
|
|
18
|
-
const core_1 = require("@angular-devkit/core");
|
|
19
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
20
|
-
const schematics_2 = require("@nestjs/schematics");
|
|
21
|
-
const path_1 = require("path");
|
|
22
|
-
__exportStar(require("./common-options.interface"), exports);
|
|
23
|
-
class CommonSchematicFactory {
|
|
24
|
-
constructor() {
|
|
25
|
-
this.templatePath = './files';
|
|
26
|
-
this.type = 'service';
|
|
27
|
-
this.metadata = 'providers';
|
|
28
|
-
}
|
|
29
|
-
create(options) {
|
|
30
|
-
options = this.transform(options);
|
|
31
|
-
return (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([(0, schematics_1.mergeWith)(this.generate(options)), this.addDeclarationToModule(options), (0, schematics_2.mergeSourceRoot)(options)]));
|
|
32
|
-
}
|
|
33
|
-
generate(options) {
|
|
34
|
-
return (context) => (0, schematics_1.apply)((0, schematics_1.url)((0, path_1.join)(this.templatePath)), [
|
|
35
|
-
options.spec ? (0, schematics_1.noop)() : (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts')),
|
|
36
|
-
(0, schematics_1.applyTemplates)({
|
|
37
|
-
...core_1.strings,
|
|
38
|
-
...options,
|
|
39
|
-
lowercase: (str) => str.toLowerCase()
|
|
40
|
-
}),
|
|
41
|
-
(0, schematics_1.move)(options.path ?? '')
|
|
42
|
-
])(context);
|
|
43
|
-
}
|
|
44
|
-
addDeclarationToModule(options) {
|
|
45
|
-
return (tree) => {
|
|
46
|
-
options.module = new schematics_2.ModuleFinder(tree).find({
|
|
47
|
-
name: options.name,
|
|
48
|
-
path: options.path
|
|
49
|
-
});
|
|
50
|
-
if (options.module === undefined || options.module === null) {
|
|
51
|
-
return tree;
|
|
52
|
-
}
|
|
53
|
-
const rawContent = tree.read(options.module);
|
|
54
|
-
const content = rawContent?.toString() ?? '';
|
|
55
|
-
const declarator = new schematics_2.ModuleDeclarator();
|
|
56
|
-
tree.overwrite(options.module, declarator.declare(content, options));
|
|
57
|
-
return tree;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
transform(source) {
|
|
61
|
-
const target = Object.assign({}, source);
|
|
62
|
-
target.metadata = this.metadata;
|
|
63
|
-
target.type = this.type;
|
|
64
|
-
if (target.name === null || target.name === undefined) {
|
|
65
|
-
throw new schematics_1.SchematicsException('Option (name) is required.');
|
|
66
|
-
}
|
|
67
|
-
const location = new schematics_2.NameParser().parse(target);
|
|
68
|
-
target.name = core_1.strings.dasherize(location.name);
|
|
69
|
-
target.path = core_1.strings.dasherize(location.path);
|
|
70
|
-
target.path = target.flat ? target.path : (0, path_1.join)(target.path, target.name);
|
|
71
|
-
return target;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.CommonSchematicFactory = CommonSchematicFactory;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContextMenuType = void 0;
|
|
4
|
-
var ContextMenuType;
|
|
5
|
-
(function (ContextMenuType) {
|
|
6
|
-
ContextMenuType["Message"] = "message";
|
|
7
|
-
ContextMenuType["User"] = "user";
|
|
8
|
-
})(ContextMenuType = exports.ContextMenuType || (exports.ContextMenuType = {}));
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.contextMenu = void 0;
|
|
4
|
-
const common_1 = require("../common");
|
|
5
|
-
const context_menu_type_enum_1 = require("./context-menu-type.enum");
|
|
6
|
-
class ContextMenuSchematicFactory extends common_1.CommonSchematicFactory {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.type = 'context-menu';
|
|
10
|
-
}
|
|
11
|
-
generate(options) {
|
|
12
|
-
switch (options.type) {
|
|
13
|
-
case context_menu_type_enum_1.ContextMenuType.Message:
|
|
14
|
-
this.templatePath = './files/message-menu';
|
|
15
|
-
break;
|
|
16
|
-
case context_menu_type_enum_1.ContextMenuType.User:
|
|
17
|
-
this.templatePath = './files/user-menu';
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
return super.generate(options);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function contextMenu(options) {
|
|
24
|
-
const contextMenuFactory = new ContextMenuSchematicFactory();
|
|
25
|
-
return contextMenuFactory.create(options);
|
|
26
|
-
}
|
|
27
|
-
exports.contextMenu = contextMenu;
|
package/jest.config.json
DELETED
package/test/.keep
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|