meocord 1.0.0-alpha.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.
- package/README.md +1 -0
- package/dist/bin/generator.d.ts +10 -0
- package/dist/bin/generator.js +194 -0
- package/dist/bin/helper/generator.helper.d.ts +23 -0
- package/dist/bin/helper/generator.helper.js +260 -0
- package/dist/bin/meocord.d.ts +2 -0
- package/dist/bin/meocord.js +407 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.js +19 -0
- package/dist/common/logger.d.ts +14 -0
- package/dist/common/logger.js +180 -0
- package/dist/common/theme.d.ts +7 -0
- package/dist/common/theme.js +20 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +19 -0
- package/dist/core/meocord-factory.d.ts +9 -0
- package/dist/core/meocord-factory.js +38 -0
- package/dist/core/meocord.app.d.ts +23 -0
- package/dist/core/meocord.app.js +623 -0
- package/dist/decorator/app.decorator.d.ts +13 -0
- package/dist/decorator/app.decorator.js +74 -0
- package/dist/decorator/command-builder.decorator.d.ts +4 -0
- package/dist/decorator/command-builder.decorator.js +18 -0
- package/dist/decorator/controller.decorator.d.ts +23 -0
- package/dist/decorator/controller.decorator.js +137 -0
- package/dist/decorator/guard.decorator.d.ts +60 -0
- package/dist/decorator/guard.decorator.js +166 -0
- package/dist/decorator/index.d.ts +5 -0
- package/dist/decorator/index.js +60 -0
- package/dist/decorator/service.decorator.d.ts +2 -0
- package/dist/decorator/service.decorator.js +46 -0
- package/dist/enum/controller.enum.d.ts +16 -0
- package/dist/enum/controller.enum.js +24 -0
- package/dist/enum/index.d.ts +1 -0
- package/dist/enum/index.js +12 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/util/common.util.d.ts +7 -0
- package/dist/util/common.util.js +43 -0
- package/dist/util/embed.util.d.ts +2 -0
- package/dist/util/embed.util.js +15 -0
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +11 -0
- package/dist/util/wait.util.d.ts +1 -0
- package/dist/util/wait.util.js +11 -0
- package/package.json +86 -0
- package/webpack.config.js +73 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# core
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export declare class GeneratorCLI {
|
|
3
|
+
private appName;
|
|
4
|
+
private logger;
|
|
5
|
+
private generatorHelper;
|
|
6
|
+
constructor(appName: string);
|
|
7
|
+
register(program: Command): Command;
|
|
8
|
+
private handleGenerateComponent;
|
|
9
|
+
private handleGenerateController;
|
|
10
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GeneratorCLI = void 0;
|
|
7
|
+
var _commander = require("commander");
|
|
8
|
+
var _controller = require("../enum/controller.enum");
|
|
9
|
+
var _generator = require("./helper/generator.helper");
|
|
10
|
+
var _common = require("../common");
|
|
11
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
12
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
14
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
15
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
16
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
17
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
18
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
20
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
21
|
+
var GeneratorCLI = exports.GeneratorCLI = /*#__PURE__*/function () {
|
|
22
|
+
function GeneratorCLI(appName) {
|
|
23
|
+
_classCallCheck(this, GeneratorCLI);
|
|
24
|
+
this.appName = appName;
|
|
25
|
+
this.logger = new _common.Logger(this.appName);
|
|
26
|
+
this.generatorHelper = new _generator.GeneratorHelper(this.appName);
|
|
27
|
+
}
|
|
28
|
+
return _createClass(GeneratorCLI, [{
|
|
29
|
+
key: "register",
|
|
30
|
+
value: function register(program) {
|
|
31
|
+
var _this = this;
|
|
32
|
+
var generatorCommand = program.command('generate').alias('g').description('Generate components');
|
|
33
|
+
generatorCommand.command('controller').alias('c').description('Generate a controller component').addArgument(new _commander.Argument('<type>', 'Type of the controller (e.g., button, context-menu, etc.)').choices(['button', 'context-menu', 'message', 'modal-submit', 'reaction', 'select-menu', 'slash'])).addArgument(new _commander.Argument('<name>', 'Name of the controller')).action(/*#__PURE__*/function () {
|
|
34
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(type, name) {
|
|
35
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
36
|
+
while (1) switch (_context.prev = _context.next) {
|
|
37
|
+
case 0:
|
|
38
|
+
_context.next = 2;
|
|
39
|
+
return _this.handleGenerateComponent({
|
|
40
|
+
component: 'controller',
|
|
41
|
+
type: type,
|
|
42
|
+
name: name
|
|
43
|
+
});
|
|
44
|
+
case 2:
|
|
45
|
+
case "end":
|
|
46
|
+
return _context.stop();
|
|
47
|
+
}
|
|
48
|
+
}, _callee);
|
|
49
|
+
}));
|
|
50
|
+
return function (_x, _x2) {
|
|
51
|
+
return _ref.apply(this, arguments);
|
|
52
|
+
};
|
|
53
|
+
}());
|
|
54
|
+
generatorCommand.command('service').alias('s').addArgument(new _commander.Argument('<name>', 'Name of the service.')).description('Generate a service component').action(/*#__PURE__*/function () {
|
|
55
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(name) {
|
|
56
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
57
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
_context2.next = 2;
|
|
60
|
+
return _this.handleGenerateComponent({
|
|
61
|
+
component: 'service',
|
|
62
|
+
name: name
|
|
63
|
+
});
|
|
64
|
+
case 2:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context2.stop();
|
|
67
|
+
}
|
|
68
|
+
}, _callee2);
|
|
69
|
+
}));
|
|
70
|
+
return function (_x3) {
|
|
71
|
+
return _ref2.apply(this, arguments);
|
|
72
|
+
};
|
|
73
|
+
}());
|
|
74
|
+
generatorCommand.command('guard').alias('g').addArgument(new _commander.Argument('<name>', 'Name of the guard.')).description('Generate a guard component').action(/*#__PURE__*/function () {
|
|
75
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(name) {
|
|
76
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
77
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
78
|
+
case 0:
|
|
79
|
+
_context3.next = 2;
|
|
80
|
+
return _this.handleGenerateComponent({
|
|
81
|
+
component: 'guard',
|
|
82
|
+
name: name
|
|
83
|
+
});
|
|
84
|
+
case 2:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context3.stop();
|
|
87
|
+
}
|
|
88
|
+
}, _callee3);
|
|
89
|
+
}));
|
|
90
|
+
return function (_x4) {
|
|
91
|
+
return _ref3.apply(this, arguments);
|
|
92
|
+
};
|
|
93
|
+
}());
|
|
94
|
+
return program;
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "handleGenerateComponent",
|
|
98
|
+
value: function () {
|
|
99
|
+
var _handleGenerateComponent = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(args) {
|
|
100
|
+
var component, name, type;
|
|
101
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
102
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
103
|
+
case 0:
|
|
104
|
+
component = args.component, name = args.name, type = args.type;
|
|
105
|
+
if (name) {
|
|
106
|
+
_context4.next = 3;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
throw new Error('Name is required');
|
|
110
|
+
case 3:
|
|
111
|
+
_context4.t0 = component;
|
|
112
|
+
_context4.next = _context4.t0 === 'controller' ? 6 : _context4.t0 === 'service' ? 11 : _context4.t0 === 'guard' ? 12 : 13;
|
|
113
|
+
break;
|
|
114
|
+
case 6:
|
|
115
|
+
if (type) {
|
|
116
|
+
_context4.next = 8;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
throw new Error('Type is required for controllers');
|
|
120
|
+
case 8:
|
|
121
|
+
_context4.next = 10;
|
|
122
|
+
return this.handleGenerateController({
|
|
123
|
+
name: name,
|
|
124
|
+
type: type
|
|
125
|
+
});
|
|
126
|
+
case 10:
|
|
127
|
+
return _context4.abrupt("break", 14);
|
|
128
|
+
case 11:
|
|
129
|
+
return _context4.abrupt("break", 14);
|
|
130
|
+
case 12:
|
|
131
|
+
return _context4.abrupt("break", 14);
|
|
132
|
+
case 13:
|
|
133
|
+
throw new Error("Unsupported component type: ".concat(component));
|
|
134
|
+
case 14:
|
|
135
|
+
case "end":
|
|
136
|
+
return _context4.stop();
|
|
137
|
+
}
|
|
138
|
+
}, _callee4, this);
|
|
139
|
+
}));
|
|
140
|
+
function handleGenerateComponent(_x5) {
|
|
141
|
+
return _handleGenerateComponent.apply(this, arguments);
|
|
142
|
+
}
|
|
143
|
+
return handleGenerateComponent;
|
|
144
|
+
}()
|
|
145
|
+
}, {
|
|
146
|
+
key: "handleGenerateController",
|
|
147
|
+
value: function () {
|
|
148
|
+
var _handleGenerateController = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(args) {
|
|
149
|
+
var typeMap, config;
|
|
150
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
151
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
152
|
+
case 0:
|
|
153
|
+
typeMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, _controller.ControllerType.BUTTON, {
|
|
154
|
+
interactionType: ['ButtonInteraction'],
|
|
155
|
+
commandType: _controller.CommandType.BUTTON
|
|
156
|
+
}), _controller.ControllerType.MODAL_SUBMIT, {
|
|
157
|
+
interactionType: ['ModalSubmitInteraction'],
|
|
158
|
+
commandType: _controller.CommandType.MODAL_SUBMIT
|
|
159
|
+
}), _controller.ControllerType.SELECT_MENU, {
|
|
160
|
+
interactionType: ['StringSelectMenuInteraction'],
|
|
161
|
+
commandType: _controller.CommandType.SELECT_MENU
|
|
162
|
+
}), _controller.ControllerType.REACTION, {
|
|
163
|
+
interactionType: ['MessageReaction']
|
|
164
|
+
}), _controller.ControllerType.SLASH, {
|
|
165
|
+
interactionType: ['ChatInputCommandInteraction'],
|
|
166
|
+
hasBuilder: true
|
|
167
|
+
}), _controller.ControllerType.CONTEXT_MENU, {
|
|
168
|
+
interactionType: ['UserContextMenuCommandInteraction', 'MessageContextMenuCommandInteraction'],
|
|
169
|
+
hasBuilder: true
|
|
170
|
+
});
|
|
171
|
+
config = typeMap[args.type];
|
|
172
|
+
if (config) {
|
|
173
|
+
_context5.next = 4;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
throw new Error("Unsupported controller type: ".concat(args.type));
|
|
177
|
+
case 4:
|
|
178
|
+
_context5.next = 6;
|
|
179
|
+
return this.generatorHelper.generateController({
|
|
180
|
+
controllerName: args.name
|
|
181
|
+
}, args.type, config.interactionType, config.commandType, config.hasBuilder);
|
|
182
|
+
case 6:
|
|
183
|
+
case "end":
|
|
184
|
+
return _context5.stop();
|
|
185
|
+
}
|
|
186
|
+
}, _callee5, this);
|
|
187
|
+
}));
|
|
188
|
+
function handleGenerateController(_x6) {
|
|
189
|
+
return _handleGenerateController.apply(this, arguments);
|
|
190
|
+
}
|
|
191
|
+
return handleGenerateController;
|
|
192
|
+
}()
|
|
193
|
+
}]);
|
|
194
|
+
}();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CommandType } from '@src/enum';
|
|
2
|
+
import { ControllerType } from '@src/enum/controller.enum';
|
|
3
|
+
export declare class GeneratorHelper {
|
|
4
|
+
private appName;
|
|
5
|
+
private logger;
|
|
6
|
+
constructor(appName: string);
|
|
7
|
+
toClassName(originalName: string): Promise<string>;
|
|
8
|
+
validateAndFormatName(originalName?: string): Promise<{
|
|
9
|
+
parts: string[];
|
|
10
|
+
kebabCaseName: string;
|
|
11
|
+
className: string;
|
|
12
|
+
}>;
|
|
13
|
+
createDirectoryIfNotExists(directory: string): void;
|
|
14
|
+
generateFileWithESLintFix(filePath: string, template: string): void;
|
|
15
|
+
generateController(args: {
|
|
16
|
+
controllerName: string | undefined;
|
|
17
|
+
}, type: ControllerType, interactionType: string[], commandType?: CommandType, hasBuilder?: boolean): Promise<void>;
|
|
18
|
+
generateControllerPaths(parts: string[], type: string): string;
|
|
19
|
+
generateControllerFile(controllerDir: string, type: string, kebabCaseName: string): string;
|
|
20
|
+
buildControllerTemplate(className: string, type: ControllerType, interactionType: string[], commandType?: CommandType, hasBuilder?: boolean): Promise<string>;
|
|
21
|
+
generateControllerStructure(controllerDir: string, hasBuilder: boolean, kebabCaseName: string, type: string, controllerTemplate: string): void;
|
|
22
|
+
buildBuilderTemplate(type: string): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GeneratorHelper = void 0;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _child_process = require("child_process");
|
|
10
|
+
var _common = require("../../common");
|
|
11
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
12
|
+
var _wait = _interopRequireDefault(require("../../util/wait.util"));
|
|
13
|
+
var _controller = require("../../enum/controller.enum");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
15
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
16
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
17
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
19
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
20
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
21
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
22
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
23
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
24
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
25
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
26
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
27
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
28
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
29
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
30
|
+
var GeneratorHelper = exports.GeneratorHelper = /*#__PURE__*/function () {
|
|
31
|
+
function GeneratorHelper(appName) {
|
|
32
|
+
_classCallCheck(this, GeneratorHelper);
|
|
33
|
+
this.appName = appName;
|
|
34
|
+
this.logger = new _common.Logger(this.appName);
|
|
35
|
+
}
|
|
36
|
+
return _createClass(GeneratorHelper, [{
|
|
37
|
+
key: "toClassName",
|
|
38
|
+
value: function () {
|
|
39
|
+
var _toClassName = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(originalName) {
|
|
40
|
+
var className, classNameRegex;
|
|
41
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
42
|
+
while (1) switch (_context.prev = _context.next) {
|
|
43
|
+
case 0:
|
|
44
|
+
className = _lodash["default"].startCase(_lodash["default"].camelCase(originalName)).replace(/\s/g, '');
|
|
45
|
+
classNameRegex = /^[A-Z][A-Za-z0-9]*$/;
|
|
46
|
+
if (classNameRegex.test(className)) {
|
|
47
|
+
_context.next = 7;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
this.logger.error("Invalid class name \"".concat(originalName, "\". It must start with a letter and contain only alphanumeric characters."));
|
|
51
|
+
_context.next = 6;
|
|
52
|
+
return (0, _wait["default"])(100);
|
|
53
|
+
case 6:
|
|
54
|
+
process.exit(1);
|
|
55
|
+
case 7:
|
|
56
|
+
return _context.abrupt("return", className);
|
|
57
|
+
case 8:
|
|
58
|
+
case "end":
|
|
59
|
+
return _context.stop();
|
|
60
|
+
}
|
|
61
|
+
}, _callee, this);
|
|
62
|
+
}));
|
|
63
|
+
function toClassName(_x) {
|
|
64
|
+
return _toClassName.apply(this, arguments);
|
|
65
|
+
}
|
|
66
|
+
return toClassName;
|
|
67
|
+
}()
|
|
68
|
+
}, {
|
|
69
|
+
key: "validateAndFormatName",
|
|
70
|
+
value: function () {
|
|
71
|
+
var _validateAndFormatName = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(originalName) {
|
|
72
|
+
var parts, fileName, kebabCaseName, className;
|
|
73
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
74
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
if (!originalName) {
|
|
77
|
+
this.logger.error('Controller name is required');
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
parts = _lodash["default"].split(originalName, '/');
|
|
81
|
+
fileName = parts.pop();
|
|
82
|
+
if (!fileName) {
|
|
83
|
+
this.logger.error('Invalid controller name');
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
kebabCaseName = _lodash["default"].kebabCase(fileName);
|
|
87
|
+
_context2.next = 7;
|
|
88
|
+
return this.toClassName(fileName);
|
|
89
|
+
case 7:
|
|
90
|
+
className = _context2.sent;
|
|
91
|
+
if (className) {
|
|
92
|
+
_context2.next = 13;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
this.logger.error('Invalid controller name');
|
|
96
|
+
_context2.next = 12;
|
|
97
|
+
return (0, _wait["default"])(100);
|
|
98
|
+
case 12:
|
|
99
|
+
process.exit(1);
|
|
100
|
+
case 13:
|
|
101
|
+
return _context2.abrupt("return", {
|
|
102
|
+
parts: parts,
|
|
103
|
+
kebabCaseName: kebabCaseName,
|
|
104
|
+
className: className
|
|
105
|
+
});
|
|
106
|
+
case 14:
|
|
107
|
+
case "end":
|
|
108
|
+
return _context2.stop();
|
|
109
|
+
}
|
|
110
|
+
}, _callee2, this);
|
|
111
|
+
}));
|
|
112
|
+
function validateAndFormatName(_x2) {
|
|
113
|
+
return _validateAndFormatName.apply(this, arguments);
|
|
114
|
+
}
|
|
115
|
+
return validateAndFormatName;
|
|
116
|
+
}()
|
|
117
|
+
}, {
|
|
118
|
+
key: "createDirectoryIfNotExists",
|
|
119
|
+
value: function createDirectoryIfNotExists(directory) {
|
|
120
|
+
if (!_fs["default"].existsSync(directory)) {
|
|
121
|
+
_fs["default"].mkdirSync(directory, {
|
|
122
|
+
recursive: true
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
key: "generateFileWithESLintFix",
|
|
128
|
+
value: function generateFileWithESLintFix(filePath, template) {
|
|
129
|
+
try {
|
|
130
|
+
_fs["default"].writeFileSync(filePath, template);
|
|
131
|
+
this.logger.log("File created at ".concat(_path["default"].relative(process.cwd(), filePath)));
|
|
132
|
+
(0, _child_process.exec)("npx eslint --fix ".concat(filePath));
|
|
133
|
+
} catch (error) {
|
|
134
|
+
this.logger.error("Error creating file at ".concat(filePath), error);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}, {
|
|
139
|
+
key: "generateController",
|
|
140
|
+
value: function () {
|
|
141
|
+
var _generateController = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(args, type, interactionType, commandType) {
|
|
142
|
+
var hasBuilder,
|
|
143
|
+
_yield$this$validateA,
|
|
144
|
+
parts,
|
|
145
|
+
kebabCaseName,
|
|
146
|
+
className,
|
|
147
|
+
controllerDir,
|
|
148
|
+
template,
|
|
149
|
+
_args3 = arguments;
|
|
150
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
151
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
152
|
+
case 0:
|
|
153
|
+
hasBuilder = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : false;
|
|
154
|
+
_context3.next = 3;
|
|
155
|
+
return this.validateAndFormatName(args.controllerName);
|
|
156
|
+
case 3:
|
|
157
|
+
_yield$this$validateA = _context3.sent;
|
|
158
|
+
parts = _yield$this$validateA.parts;
|
|
159
|
+
kebabCaseName = _yield$this$validateA.kebabCaseName;
|
|
160
|
+
className = _yield$this$validateA.className;
|
|
161
|
+
controllerDir = this.generateControllerPaths(parts, type);
|
|
162
|
+
_context3.next = 10;
|
|
163
|
+
return this.buildControllerTemplate(className, type, interactionType, commandType, hasBuilder);
|
|
164
|
+
case 10:
|
|
165
|
+
template = _context3.sent;
|
|
166
|
+
this.generateControllerStructure(controllerDir, hasBuilder, kebabCaseName, type, template);
|
|
167
|
+
case 12:
|
|
168
|
+
case "end":
|
|
169
|
+
return _context3.stop();
|
|
170
|
+
}
|
|
171
|
+
}, _callee3, this);
|
|
172
|
+
}));
|
|
173
|
+
function generateController(_x3, _x4, _x5, _x6) {
|
|
174
|
+
return _generateController.apply(this, arguments);
|
|
175
|
+
}
|
|
176
|
+
return generateController;
|
|
177
|
+
}()
|
|
178
|
+
}, {
|
|
179
|
+
key: "generateControllerPaths",
|
|
180
|
+
value: function generateControllerPaths(parts, type) {
|
|
181
|
+
return _path["default"].join.apply(_path["default"], [process.cwd(), 'src', 'controllers', type].concat(_toConsumableArray(parts)));
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "generateControllerFile",
|
|
185
|
+
value: function generateControllerFile(controllerDir, type, kebabCaseName) {
|
|
186
|
+
return _path["default"].join(controllerDir, "".concat(kebabCaseName, ".").concat(type, ".controller.ts"));
|
|
187
|
+
}
|
|
188
|
+
}, {
|
|
189
|
+
key: "buildControllerTemplate",
|
|
190
|
+
value: function () {
|
|
191
|
+
var _buildControllerTemplate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(className, type, interactionType, commandType) {
|
|
192
|
+
var hasBuilder,
|
|
193
|
+
_args4 = arguments;
|
|
194
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
195
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
196
|
+
case 0:
|
|
197
|
+
hasBuilder = _args4.length > 4 && _args4[4] !== undefined ? _args4[4] : false;
|
|
198
|
+
if (!hasBuilder) {
|
|
199
|
+
_context4.next = 9;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
_context4.t0 = "import { ".concat(interactionType, " } from 'discord.js'\nimport { Controller, Command } from 'meocord/decorator'\nimport { SampleCommandBuilder } from '@src/controllers/").concat(type, "/builders/sample.builder'\n\n@Controller()\nexport class ").concat(className);
|
|
203
|
+
_context4.next = 5;
|
|
204
|
+
return this.toClassName(type);
|
|
205
|
+
case 5:
|
|
206
|
+
_context4.t1 = _context4.sent;
|
|
207
|
+
return _context4.abrupt("return", _context4.t0.concat.call(_context4.t0, _context4.t1, "Controller {\n\n @Command('sample', SampleCommandBuilder)\n async sample(interaction: ").concat(interactionType.join(' | '), ") {\n await interaction.reply('This is sample reply of ").concat(type, " command')\n }\n}\n"));
|
|
208
|
+
case 9:
|
|
209
|
+
_context4.t2 = type;
|
|
210
|
+
_context4.next = _context4.t2 === _controller.ControllerType.BUTTON ? 12 : _context4.t2 === _controller.ControllerType.MODAL_SUBMIT ? 13 : _context4.t2 === _controller.ControllerType.SELECT_MENU ? 14 : _context4.t2 === _controller.ControllerType.REACTION ? 15 : _context4.t2 === _controller.ControllerType.SLASH ? 16 : _context4.t2 === _controller.ControllerType.CONTEXT_MENU ? 17 : 18;
|
|
211
|
+
break;
|
|
212
|
+
case 12:
|
|
213
|
+
return _context4.abrupt("return", "import { ".concat(interactionType.join(', '), " } from 'discord.js'\nimport { Controller, Command } from 'meocord/decorator'\nimport { CommandType } from 'meocord/enum'\n\n@Controller()\nexport class ").concat(className, "ButtonController {\n\n @Command('button-click', CommandType.BUTTON)\n async handleButton(interaction: ").concat(interactionType.join(' | '), ") {\n await interaction.reply('Button clicked!')\n }\n}"));
|
|
214
|
+
case 13:
|
|
215
|
+
return _context4.abrupt("return", "import { ".concat(interactionType.join(', '), " } from 'discord.js'\nimport { Controller, Command } from 'meocord/decorator'\nimport { CommandType } from 'meocord/enum'\n\n@Controller()\nexport class ").concat(className, "ModalController {\n\n @Command('submit-modal', CommandType.MODAL_SUBMIT)\n async handleModal(interaction: ").concat(interactionType.join(' | '), ") {\n await interaction.reply('Modal submitted!')\n }\n}"));
|
|
216
|
+
case 14:
|
|
217
|
+
return _context4.abrupt("return", "import { ".concat(interactionType.join(', '), " } from 'discord.js'\nimport { Controller, Command } from 'meocord/decorator'\nimport { CommandType } from 'meocord/enum'\n\n@Controller()\nexport class ").concat(className, "SelectMenuController {\n\n @Command('select-menu', CommandType.SELECT_MENU)\n async handleSelectMenu(interaction: ").concat(interactionType.join(' | '), ") {\n await interaction.reply('Select menu used!')\n }\n}"));
|
|
218
|
+
case 15:
|
|
219
|
+
return _context4.abrupt("return", "import { ".concat(interactionType.join(', '), ", User } from 'discord.js'\nimport { Controller, ReactionHandler } from 'meocord/decorator'\nimport { Logger } from 'meocord/common'\nimport { CommandType } from 'meocord/enum'\n\n@Controller()\nexport class HelloReactionController {\n private readonly logger = new Logger(HelloReactionController.name)\n\n @ReactionHandler()\n async handleAnyReaction(reaction: ").concat(interactionType.join(' | '), ", user: User) {\n this.logger.log('Reaction detected!')\n if (reaction.message) {\n await reaction.message.reply(`${user.username} reacted!`)\n }\n }\n\n @ReactionHandler('\uD83D\uDE0B')\n async handleReaction(reaction: ").concat(interactionType.join(' | '), ", user: User) {\n this.logger.log('Reaction \uD83D\uDE0B detected!')\n if (reaction.message) {\n await reaction.message.reply(`${user.username} reacted with \uD83D\uDE0B!`)\n }\n }\n}\n"));
|
|
220
|
+
case 16:
|
|
221
|
+
return _context4.abrupt("return", "import { ".concat(interactionType.join(', '), " } from 'discord.js'\nimport { Controller, Command, CommandType } from 'meocord/decorator'\n\n@Controller()\nexport class ").concat(className, "SlashController {\n\n @Command('ping', CommandType.SLASH)\n async replyWithPong(interaction: ").concat(interactionType.join(' | '), ") {\n await interaction.reply('Pong!')\n }\n}"));
|
|
222
|
+
case 17:
|
|
223
|
+
return _context4.abrupt("return", "import { ".concat(interactionType.join(', '), ", ApplicationCommandType } from 'discord.js'\nimport { Controller, Command, CommandType } from 'meocord/decorator'\n\n@Controller()\nexport class ").concat(className, "ContextMenuController {\n\n @Command('custom-context-menu', CommandType.CONTEXT_MENU)\n async handleContextMenu(interaction: ").concat(interactionType.join(' | '), ") {\n await interaction.reply('Context menu selected!')\n }\n}"));
|
|
224
|
+
case 18:
|
|
225
|
+
throw new Error("Unsupported controller type: ".concat(type));
|
|
226
|
+
case 19:
|
|
227
|
+
case "end":
|
|
228
|
+
return _context4.stop();
|
|
229
|
+
}
|
|
230
|
+
}, _callee4, this);
|
|
231
|
+
}));
|
|
232
|
+
function buildControllerTemplate(_x7, _x8, _x9, _x10) {
|
|
233
|
+
return _buildControllerTemplate.apply(this, arguments);
|
|
234
|
+
}
|
|
235
|
+
return buildControllerTemplate;
|
|
236
|
+
}()
|
|
237
|
+
}, {
|
|
238
|
+
key: "generateControllerStructure",
|
|
239
|
+
value: function generateControllerStructure(controllerDir, hasBuilder, kebabCaseName, type, controllerTemplate) {
|
|
240
|
+
this.createDirectoryIfNotExists(controllerDir);
|
|
241
|
+
if (hasBuilder) {
|
|
242
|
+
var builderFile = _path["default"].join(controllerDir, 'builders', "sample.builder.ts");
|
|
243
|
+
var builderTemplate = this.buildBuilderTemplate(type);
|
|
244
|
+
this.createDirectoryIfNotExists(_path["default"].join(controllerDir, 'builders'));
|
|
245
|
+
this.generateFileWithESLintFix(builderFile, builderTemplate);
|
|
246
|
+
}
|
|
247
|
+
var controllerFile = this.generateControllerFile(controllerDir, type, kebabCaseName);
|
|
248
|
+
this.generateFileWithESLintFix(controllerFile, controllerTemplate);
|
|
249
|
+
}
|
|
250
|
+
}, {
|
|
251
|
+
key: "buildBuilderTemplate",
|
|
252
|
+
value: function buildBuilderTemplate(type) {
|
|
253
|
+
var isSlashCommand = type === 'slash';
|
|
254
|
+
var importBuilder = isSlashCommand ? 'SlashCommandBuilder' : ['ApplicationCommandType', 'ContextMenuCommandBuilder'].join(', ');
|
|
255
|
+
var builderClass = isSlashCommand ? 'SlashCommandBuilder()' : 'ContextMenuCommandBuilder()';
|
|
256
|
+
var contextMenuSetting = type === 'context-menu' ? '.setType(ApplicationCommandType.User)' : '';
|
|
257
|
+
return "import { ".concat(importBuilder, " } from 'discord.js'\nimport { CommandBuilder } from 'meocord/decorator'\nimport { CommandType } from 'meocord/enum'\n\n@CommandBuilder(CommandType.").concat(type.toUpperCase().replace('-', '_'), ")\nexport class SampleCommandBuilder {\n build() {\n return new ").concat(builderClass, "\n .setName('sample')").concat(contextMenuSetting, "\n }\n}\n");
|
|
258
|
+
}
|
|
259
|
+
}]);
|
|
260
|
+
}();
|