@nocobase/server 0.5.0-alpha.38 → 0.7.0-alpha.10
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/LICENSE +201 -21
- package/esm/acl/available-action.d.ts +5 -0
- package/esm/acl/available-action.js +36 -0
- package/esm/acl/available-action.js.map +1 -0
- package/esm/acl/index.d.ts +2 -0
- package/esm/acl/index.js +19 -0
- package/esm/acl/index.js.map +1 -0
- package/esm/app-manager.d.ts +19 -0
- package/esm/app-manager.js +69 -0
- package/esm/app-manager.js.map +1 -0
- package/esm/application.d.ts +97 -0
- package/esm/application.js +156 -0
- package/esm/application.js.map +1 -0
- package/esm/commands/console.d.ts +4 -0
- package/esm/commands/console.js +25 -0
- package/esm/commands/console.js.map +1 -0
- package/esm/commands/create-plugin/create-plugin.d.ts +2 -0
- package/esm/commands/create-plugin/create-plugin.js +29 -0
- package/esm/commands/create-plugin/create-plugin.js.map +1 -0
- package/esm/commands/create-plugin/index.d.ts +5 -0
- package/esm/commands/create-plugin/index.js +6 -0
- package/esm/commands/create-plugin/index.js.map +1 -0
- package/esm/commands/create-plugin/resources/templates/package-json.d.ts +11 -0
- package/esm/commands/create-plugin/resources/templates/package-json.js +11 -0
- package/esm/commands/create-plugin/resources/templates/package-json.js.map +1 -0
- package/esm/commands/create-plugin/resources/templates/plugin.d.ts +4 -0
- package/esm/commands/create-plugin/resources/templates/plugin.js +12 -0
- package/esm/commands/create-plugin/resources/templates/plugin.js.map +1 -0
- package/esm/commands/db-sync.d.ts +5 -0
- package/esm/commands/db-sync.js +25 -0
- package/esm/commands/db-sync.js.map +1 -0
- package/esm/commands/index.d.ts +3 -0
- package/esm/commands/index.js +26 -0
- package/esm/commands/index.js.map +1 -0
- package/esm/commands/install.d.ts +5 -0
- package/esm/commands/install.js +23 -0
- package/esm/commands/install.js.map +1 -0
- package/esm/commands/start.d.ts +5 -0
- package/esm/commands/start.js +23 -0
- package/esm/commands/start.js.map +1 -0
- package/esm/helper.d.ts +7 -0
- package/esm/helper.js +59 -0
- package/esm/helper.js.map +1 -0
- package/esm/index.d.ts +7 -0
- package/esm/index.js +9 -0
- package/esm/index.js.map +1 -0
- package/esm/middlewares/data-wrapping.d.ts +3 -0
- package/esm/middlewares/data-wrapping.js +54 -0
- package/esm/middlewares/data-wrapping.js.map +1 -0
- package/esm/middlewares/index.d.ts +2 -0
- package/esm/middlewares/index.js +3 -0
- package/esm/middlewares/index.js.map +1 -0
- package/esm/middlewares/table2resource.d.ts +6 -0
- package/esm/middlewares/table2resource.js +51 -0
- package/esm/middlewares/table2resource.js.map +1 -0
- package/esm/plugin-manager.d.ts +23 -0
- package/esm/plugin-manager.js +57 -0
- package/esm/plugin-manager.js.map +1 -0
- package/esm/plugin.d.ts +32 -0
- package/esm/plugin.js +43 -0
- package/esm/plugin.js.map +1 -0
- package/esm/read-config.d.ts +8 -0
- package/esm/read-config.js +63 -0
- package/esm/read-config.js.map +1 -0
- package/lib/acl/available-action.d.ts +5 -0
- package/lib/acl/available-action.js +39 -0
- package/lib/acl/available-action.js.map +1 -0
- package/lib/acl/index.d.ts +2 -0
- package/lib/acl/index.js +23 -0
- package/lib/acl/index.js.map +1 -0
- package/lib/app-manager.d.ts +19 -0
- package/lib/app-manager.js +76 -0
- package/lib/app-manager.js.map +1 -0
- package/lib/application.d.ts +51 -12
- package/lib/application.js +147 -245
- package/lib/application.js.map +1 -1
- package/lib/commands/console.d.ts +4 -0
- package/lib/commands/console.js +27 -0
- package/lib/commands/console.js.map +1 -0
- package/lib/commands/create-plugin/create-plugin.d.ts +2 -0
- package/lib/commands/create-plugin/create-plugin.js +31 -0
- package/lib/commands/create-plugin/create-plugin.js.map +1 -0
- package/lib/commands/create-plugin/index.d.ts +5 -0
- package/lib/commands/create-plugin/index.js +8 -0
- package/lib/commands/create-plugin/index.js.map +1 -0
- package/lib/commands/create-plugin/resources/templates/package-json.d.ts +11 -0
- package/lib/commands/create-plugin/resources/templates/package-json.js +13 -0
- package/lib/commands/create-plugin/resources/templates/package-json.js.map +1 -0
- package/lib/commands/create-plugin/resources/templates/plugin.d.ts +4 -0
- package/lib/commands/create-plugin/resources/templates/plugin.js +33 -0
- package/lib/commands/create-plugin/resources/templates/plugin.js.map +1 -0
- package/lib/commands/db-sync.d.ts +5 -0
- package/lib/commands/db-sync.js +27 -0
- package/lib/commands/db-sync.js.map +1 -0
- package/lib/commands/index.d.ts +3 -0
- package/lib/commands/index.js +30 -0
- package/lib/commands/index.js.map +1 -0
- package/lib/commands/install.d.ts +5 -0
- package/lib/commands/install.js +25 -0
- package/lib/commands/install.js.map +1 -0
- package/lib/commands/start.d.ts +5 -0
- package/lib/commands/start.js +25 -0
- package/lib/commands/start.js.map +1 -0
- package/lib/helper.d.ts +1 -3
- package/lib/helper.js +50 -185
- package/lib/helper.js.map +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.js +28 -63
- package/lib/index.js.map +1 -1
- package/lib/middlewares/data-wrapping.js +49 -97
- package/lib/middlewares/data-wrapping.js.map +1 -1
- package/lib/middlewares/index.js +11 -35
- package/lib/middlewares/index.js.map +1 -1
- package/lib/middlewares/table2resource.d.ts +4 -1
- package/lib/middlewares/table2resource.js +45 -129
- package/lib/middlewares/table2resource.js.map +1 -1
- package/lib/plugin-manager.d.ts +23 -0
- package/lib/plugin-manager.js +61 -0
- package/lib/plugin-manager.js.map +1 -0
- package/lib/plugin.d.ts +17 -16
- package/lib/plugin.js +42 -99
- package/lib/plugin.js.map +1 -1
- package/lib/read-config.d.ts +8 -0
- package/lib/read-config.js +72 -0
- package/lib/read-config.js.map +1 -0
- package/package.json +22 -9
- package/tsconfig.build.json +9 -0
- package/lib/application.d.ts.map +0 -1
- package/lib/helper.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/middlewares/data-wrapping.d.ts.map +0 -1
- package/lib/middlewares/index.d.ts.map +0 -1
- package/lib/middlewares/table2resource.d.ts.map +0 -1
- package/lib/plugin.d.ts.map +0 -1
package/lib/application.js
CHANGED
|
@@ -1,261 +1,163 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
-
|
|
17
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
-
|
|
19
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
20
|
-
|
|
21
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
|
-
|
|
23
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
24
|
-
|
|
25
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
26
|
-
|
|
27
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
28
|
-
|
|
29
|
-
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
30
|
-
function adopt(value) {
|
|
31
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
32
|
-
resolve(value);
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
9
|
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
-
function fulfilled(value) {
|
|
38
|
-
try {
|
|
39
|
-
step(generator.next(value));
|
|
40
|
-
} catch (e) {
|
|
41
|
-
reject(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function rejected(value) {
|
|
46
|
-
try {
|
|
47
|
-
step(generator["throw"](value));
|
|
48
|
-
} catch (e) {
|
|
49
|
-
reject(e);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function step(result) {
|
|
54
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
58
|
-
});
|
|
59
10
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return mod && mod.__esModule ? mod : {
|
|
63
|
-
"default": mod
|
|
64
|
-
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
65
13
|
};
|
|
66
|
-
|
|
67
|
-
Object.defineProperty(exports, "__esModule", {
|
|
68
|
-
value: true
|
|
69
|
-
});
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
15
|
exports.Application = void 0;
|
|
71
|
-
|
|
72
|
-
const koa_1 = __importDefault(require("koa"));
|
|
73
|
-
|
|
74
|
-
const plugin_1 = require("./plugin");
|
|
75
|
-
|
|
76
16
|
const actions_1 = require("@nocobase/actions");
|
|
77
|
-
|
|
17
|
+
const utils_1 = require("@nocobase/utils");
|
|
18
|
+
const koa_1 = __importDefault(require("koa"));
|
|
19
|
+
const lodash_1 = require("lodash");
|
|
20
|
+
const acl_1 = require("./acl");
|
|
21
|
+
const app_manager_1 = require("./app-manager");
|
|
22
|
+
const commands_1 = require("./commands");
|
|
78
23
|
const helper_1 = require("./helper");
|
|
79
|
-
|
|
24
|
+
const plugin_manager_1 = require("./plugin-manager");
|
|
80
25
|
class Application extends koa_1.default {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
26
|
+
constructor(options) {
|
|
27
|
+
super();
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.plugins = new Map();
|
|
30
|
+
this.acl = (0, acl_1.createACL)();
|
|
31
|
+
this.db = (0, helper_1.createDatabase)(options);
|
|
32
|
+
this.resourcer = (0, helper_1.createResourcer)(options);
|
|
33
|
+
this.cli = (0, commands_1.createCli)(this);
|
|
34
|
+
this.i18n = (0, helper_1.createI18n)(options);
|
|
35
|
+
this.pm = new plugin_manager_1.PluginManager({
|
|
36
|
+
app: this,
|
|
37
|
+
});
|
|
38
|
+
this.appManager = new app_manager_1.AppManager(this);
|
|
39
|
+
(0, helper_1.registerMiddlewares)(this, options);
|
|
40
|
+
if (options.registerActions !== false) {
|
|
41
|
+
(0, actions_1.registerActions)(this);
|
|
42
|
+
}
|
|
43
|
+
this.loadPluginConfig(options.plugins || []);
|
|
92
44
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
use(middleware, options) {
|
|
96
|
-
return super.use(middleware);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
collection(options) {
|
|
100
|
-
return this.db.table(options);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
resource(options) {
|
|
104
|
-
return this.resourcer.define(options);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
actions(handlers, options) {
|
|
108
|
-
return this.resourcer.registerActions(handlers);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
command(nameAndArgs, opts) {
|
|
112
|
-
return this.cli.command(nameAndArgs, opts);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
findCommand(name) {
|
|
116
|
-
return this.cli._findCommand(name);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
plugin(options, ext) {
|
|
120
|
-
if (typeof options === 'string') {
|
|
121
|
-
return this.plugin(require(options).default, ext);
|
|
45
|
+
plugin(pluginClass, options) {
|
|
46
|
+
return this.pm.add(pluginClass, options);
|
|
122
47
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
app: this
|
|
132
|
-
}));
|
|
133
|
-
|
|
134
|
-
if (!(instance instanceof plugin_1.Plugin)) {
|
|
135
|
-
throw new Error('plugin must be instanceof Plugin');
|
|
48
|
+
loadPluginConfig(pluginsConfigurations) {
|
|
49
|
+
for (let pluginConfiguration of pluginsConfigurations) {
|
|
50
|
+
if (typeof pluginConfiguration == 'string') {
|
|
51
|
+
pluginConfiguration = [pluginConfiguration, {}];
|
|
52
|
+
}
|
|
53
|
+
const plugin = plugin_manager_1.PluginManager.resolvePlugin(pluginConfiguration[0]);
|
|
54
|
+
const pluginOptions = pluginConfiguration[1];
|
|
55
|
+
this.plugin(plugin, pluginOptions);
|
|
136
56
|
}
|
|
137
|
-
} catch (err) {
|
|
138
|
-
instance = new plugin_1.Plugin(Object.assign(Object.assign({
|
|
139
|
-
name: options.name
|
|
140
|
-
}, ext), {
|
|
141
|
-
load: options,
|
|
142
|
-
app: this
|
|
143
|
-
}));
|
|
144
|
-
}
|
|
145
|
-
} else if (typeof options === 'object') {
|
|
146
|
-
const plugin = options.plugin || plugin_1.Plugin;
|
|
147
|
-
instance = new plugin(Object.assign(Object.assign(Object.assign({
|
|
148
|
-
name: options.plugin ? plugin.name : undefined
|
|
149
|
-
}, options), ext), {
|
|
150
|
-
app: this
|
|
151
|
-
}));
|
|
152
57
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
58
|
+
use(middleware, options) {
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
return super.use(middleware);
|
|
61
|
+
}
|
|
62
|
+
collection(options) {
|
|
63
|
+
return this.db.collection(options);
|
|
64
|
+
}
|
|
65
|
+
resource(options) {
|
|
66
|
+
return this.resourcer.define(options);
|
|
67
|
+
}
|
|
68
|
+
actions(handlers, options) {
|
|
69
|
+
return this.resourcer.registerActions(handlers);
|
|
70
|
+
}
|
|
71
|
+
command(name, desc, opts) {
|
|
72
|
+
return this.cli.command(name, desc, opts);
|
|
73
|
+
}
|
|
74
|
+
findCommand(name) {
|
|
75
|
+
return this.cli._findCommand(name);
|
|
76
|
+
}
|
|
77
|
+
load() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
yield this.pm.load();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
getPlugin(name) {
|
|
83
|
+
return this.pm.get(name);
|
|
84
|
+
}
|
|
85
|
+
parse(argv = process.argv) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
yield this.load();
|
|
88
|
+
return this.cli.parseAsync(argv);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
start(options) {
|
|
92
|
+
var _a;
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
// reconnect database
|
|
95
|
+
if (this.db.closed()) {
|
|
96
|
+
yield this.db.reconnect();
|
|
97
|
+
}
|
|
98
|
+
yield this.emitAsync('beforeStart', this, options);
|
|
99
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.listen) === null || _a === void 0 ? void 0 : _a.port) {
|
|
100
|
+
const listen = () => new Promise((resolve) => {
|
|
101
|
+
const Server = this.listen(options === null || options === void 0 ? void 0 : options.listen, () => {
|
|
102
|
+
resolve(Server);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
this.listenServer = yield listen();
|
|
107
|
+
}
|
|
108
|
+
yield this.emitAsync('afterStart', this, options);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
listen(...args) {
|
|
112
|
+
return this.appManager.listen(...args);
|
|
113
|
+
}
|
|
114
|
+
stop(options) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
yield this.emitAsync('beforeStop', this, options);
|
|
117
|
+
try {
|
|
118
|
+
// close database connection
|
|
119
|
+
// silent if database already closed
|
|
120
|
+
yield this.db.close();
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
console.log(e);
|
|
124
|
+
}
|
|
125
|
+
// close http server
|
|
126
|
+
if (this.listenServer) {
|
|
127
|
+
const closeServer = () => new Promise((resolve, reject) => {
|
|
128
|
+
this.listenServer.close((err) => {
|
|
129
|
+
if (err) {
|
|
130
|
+
return reject(err);
|
|
131
|
+
}
|
|
132
|
+
this.listenServer = null;
|
|
133
|
+
resolve(true);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
yield closeServer();
|
|
137
|
+
}
|
|
138
|
+
yield this.emitAsync('afterStop', this, options);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
destroy(options) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
yield this.emitAsync('beforeDestroy', this, options);
|
|
144
|
+
yield this.stop(options);
|
|
145
|
+
yield this.emitAsync('afterDestroy', this, options);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
install(options) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
yield this.emitAsync('beforeInstall', this, options);
|
|
151
|
+
if (options === null || options === void 0 ? void 0 : options.clean) {
|
|
152
|
+
yield this.db.clean((0, lodash_1.isBoolean)(options.clean) ? { drop: options.clean } : options.clean);
|
|
153
|
+
}
|
|
154
|
+
yield this.db.sync(options === null || options === void 0 ? void 0 : options.sync);
|
|
155
|
+
yield this.pm.install(options);
|
|
156
|
+
yield this.emitAsync('afterInstall', this, options);
|
|
157
|
+
});
|
|
158
158
|
}
|
|
159
|
-
|
|
160
|
-
this.plugins.set(name, instance);
|
|
161
|
-
return instance;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
load() {
|
|
165
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
-
yield this.emitAsync('plugins.beforeLoad');
|
|
167
|
-
|
|
168
|
-
var _iterator = _createForOfIteratorHelper(this.plugins),
|
|
169
|
-
_step;
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
173
|
-
const _step$value = _slicedToArray(_step.value, 2),
|
|
174
|
-
name = _step$value[0],
|
|
175
|
-
plugin = _step$value[1];
|
|
176
|
-
|
|
177
|
-
yield this.emitAsync(`plugins.${name}.beforeLoad`);
|
|
178
|
-
yield plugin.load();
|
|
179
|
-
yield this.emitAsync(`plugins.${name}.afterLoad`);
|
|
180
|
-
}
|
|
181
|
-
} catch (err) {
|
|
182
|
-
_iterator.e(err);
|
|
183
|
-
} finally {
|
|
184
|
-
_iterator.f();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
yield this.emitAsync('plugins.afterLoad');
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
emitAsync(event, ...args) {
|
|
192
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
const events = this._events;
|
|
194
|
-
let callbacks = events[event];
|
|
195
|
-
|
|
196
|
-
if (!callbacks) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const run = cb => {
|
|
201
|
-
switch (args.length) {
|
|
202
|
-
case 0:
|
|
203
|
-
cb = cb.call(this);
|
|
204
|
-
break;
|
|
205
|
-
|
|
206
|
-
case 1:
|
|
207
|
-
cb = cb.call(this, args[0]);
|
|
208
|
-
break;
|
|
209
|
-
|
|
210
|
-
case 2:
|
|
211
|
-
cb = cb.call(this, args[0], args[1]);
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
|
-
case 3:
|
|
215
|
-
cb = cb.call(this, args[0], args[1], args[2]);
|
|
216
|
-
break;
|
|
217
|
-
|
|
218
|
-
default:
|
|
219
|
-
cb = cb.apply(this, args);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (cb && (cb instanceof Promise || typeof cb.then === 'function')) {
|
|
223
|
-
return cb;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return Promise.resolve(true);
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
if (typeof callbacks === 'function') {
|
|
230
|
-
yield run(callbacks);
|
|
231
|
-
} else if (typeof callbacks === 'object') {
|
|
232
|
-
callbacks = callbacks.slice().filter(Boolean);
|
|
233
|
-
yield callbacks.reduce((prev, next) => {
|
|
234
|
-
return prev.then(res => {
|
|
235
|
-
return run(next).then(result => Promise.resolve(res.concat(result)));
|
|
236
|
-
});
|
|
237
|
-
}, Promise.resolve([]));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return true;
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
parse(argv = process.argv) {
|
|
245
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
yield this.load();
|
|
247
|
-
return this.cli.parseAsync(argv);
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
destroy() {
|
|
252
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
-
yield this.db.close();
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
159
|
}
|
|
258
|
-
|
|
259
160
|
exports.Application = Application;
|
|
161
|
+
(0, utils_1.applyMixins)(Application, [utils_1.AsyncEmitter]);
|
|
260
162
|
exports.default = Application;
|
|
261
|
-
//# sourceMappingURL=application.js.map
|
|
163
|
+
//# sourceMappingURL=application.js.map
|
package/lib/application.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8CAAsB;AAItB,qCAA6D;AAC7D,+CAAoD;AACpD,qCAMkB;AAyClB,MAAa,WAGX,SAAQ,aAAG;IAWX,YAAY,OAA2B;QACrC,KAAK,EAAE,CAAC;QAHA,YAAO,GAAG,IAAI,GA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from 'koa';\nimport { Command, CommandOptions } from 'commander';\nimport Database, { DatabaseOptions, TableOptions } from '@nocobase/database';\nimport Resourcer, { ResourceOptions } from '@nocobase/resourcer';\nimport { PluginType, Plugin, PluginOptions } from './plugin';\nimport { registerActions } from '@nocobase/actions';\nimport {\n createCli,\n createI18n,\n createDatabase,\n createResourcer,\n registerMiddlewares,\n} from './helper';\nimport { i18n, InitOptions } from 'i18next';\n\nexport interface ResourcerOptions {\n prefix?: string;\n}\n\nexport interface ApplicationOptions {\n database?: DatabaseOptions;\n resourcer?: ResourcerOptions;\n bodyParser?: any;\n cors?: any;\n dataWrapping?: boolean;\n registerActions?: boolean;\n i18n?: i18n | InitOptions;\n}\n\ninterface DefaultState {\n currentUser?: any;\n [key: string]: any;\n}\n\ninterface DefaultContext {\n db: Database;\n resourcer: Resourcer;\n [key: string]: any;\n}\n\ninterface MiddlewareOptions {\n name?: string;\n resourceName?: string;\n resourceNames?: string[];\n insertBefore?: string;\n insertAfter?: string;\n}\n\ninterface ActionsOptions {\n resourceName?: string;\n resourceNames?: string[];\n}\n\nexport class Application<\n StateT = DefaultState,\n ContextT = DefaultContext\n> extends Koa {\n public readonly db: Database;\n\n public readonly resourcer: Resourcer;\n\n public readonly cli: Command;\n\n public readonly i18n: i18n;\n\n protected plugins = new Map<string, Plugin>();\n\n constructor(options: ApplicationOptions) {\n super();\n\n this.db = createDatabase(options);\n this.resourcer = createResourcer(options);\n this.cli = createCli(this, options);\n this.i18n = createI18n(options);\n\n registerMiddlewares(this, options);\n if (options.registerActions !== false) {\n registerActions(this);\n }\n }\n\n use<NewStateT = {}, NewContextT = {}>(\n middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>,\n options?: MiddlewareOptions,\n ) {\n // @ts-ignore\n return super.use(middleware);\n }\n\n collection(options: TableOptions) {\n return this.db.table(options);\n }\n\n resource(options: ResourceOptions) {\n return this.resourcer.define(options);\n }\n\n actions(handlers: any, options?: ActionsOptions) {\n return this.resourcer.registerActions(handlers);\n }\n\n command(nameAndArgs: string, opts?: CommandOptions) {\n return this.cli.command(nameAndArgs, opts);\n }\n\n findCommand(name: string): Command {\n return (this.cli as any)._findCommand(name);\n }\n\n plugin(options?: PluginType | PluginOptions, ext?: PluginOptions): Plugin {\n if (typeof options === 'string') {\n return this.plugin(require(options).default, ext);\n }\n let instance: Plugin;\n if (typeof options === 'function') {\n try {\n // @ts-ignore\n instance = new options({\n name: options.name,\n ...ext,\n app: this,\n });\n if (!(instance instanceof Plugin)) {\n throw new Error('plugin must be instanceof Plugin');\n }\n } catch (err) {\n // console.log(err);\n instance = new Plugin({\n name: options.name,\n ...ext,\n // @ts-ignore\n load: options,\n app: this,\n });\n }\n } else if (typeof options === 'object') {\n const plugin = options.plugin || Plugin;\n instance = new plugin({\n name: options.plugin ? plugin.name : undefined,\n ...options,\n ...ext,\n app: this,\n });\n }\n const name = instance.getName();\n if (this.plugins.has(name)) {\n throw new Error(`plugin name [${name}] is repeated`);\n }\n this.plugins.set(name, instance);\n return instance;\n }\n\n async load() {\n await this.emitAsync('plugins.beforeLoad');\n for (const [name, plugin] of this.plugins) {\n await this.emitAsync(`plugins.${name}.beforeLoad`);\n await plugin.load();\n await this.emitAsync(`plugins.${name}.afterLoad`);\n }\n await this.emitAsync('plugins.afterLoad');\n }\n\n async emitAsync(event: string | symbol, ...args: any[]): Promise<boolean> {\n // @ts-ignore\n const events = this._events;\n let callbacks = events[event];\n if (!callbacks) {\n return false;\n }\n // helper function to reuse as much code as possible\n const run = (cb) => {\n switch (args.length) {\n // fast cases\n case 0:\n cb = cb.call(this);\n break;\n case 1:\n cb = cb.call(this, args[0]);\n break;\n case 2:\n cb = cb.call(this, args[0], args[1]);\n break;\n case 3:\n cb = cb.call(this, args[0], args[1], args[2]);\n break;\n // slower\n default:\n cb = cb.apply(this, args);\n }\n\n if (cb && (cb instanceof Promise || typeof cb.then === 'function')) {\n return cb;\n }\n\n return Promise.resolve(true);\n };\n\n if (typeof callbacks === 'function') {\n await run(callbacks);\n } else if (typeof callbacks === 'object') {\n callbacks = callbacks.slice().filter(Boolean);\n await callbacks.reduce((prev, next) => {\n return prev.then((res) => {\n return run(next).then((result) =>\n Promise.resolve(res.concat(result)),\n );\n });\n }, Promise.resolve([]));\n }\n\n return true;\n }\n\n async parse(argv = process.argv) {\n await this.load();\n return this.cli.parseAsync(argv);\n }\n\n async destroy() {\n await this.db.close();\n }\n}\n\nexport default Application;\n"]}
|
|
1
|
+
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+CAAoD;AAGpD,2CAA4D;AAI5D,8CAAsB;AACtB,mCAAmC;AACnC,+BAAkC;AAClC,+CAA2C;AAC3C,yCAAuC;AACvC,qCAA4F;AAE5F,qDAAiE;AAgEjE,MAAa,WAA8D,SAAQ,aAAG;IAmBpF,YAAmB,OAA2B;QAC5C,KAAK,EAAE,CAAC;QADS,YAAO,GAAP,OAAO,CAAoB;QAJpC,YAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAO5C,IAAI,CAAC,GAAG,GAAG,IAAA,eAAS,GAAE,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,IAAA,uBAAc,EAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,IAAA,wBAAe,EAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,GAAG,GAAG,IAAA,oBAAS,EAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAA,mBAAU,EAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,EAAE,GAAG,IAAI,8BAAa,CAAC;YAC1B,GAAG,EAAE,IAAI;SACV,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,GAAG,IAAI,wBAAU,CAAC,IAAI,CAAC,CAAC;QAEvC,IAAA,4BAAmB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAEnC,IAAI,OAAO,CAAC,eAAe,KAAK,K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AAC;KAAA;IAEK,OAAO,CAAC,OAAwB;;YACpC,MAAM,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YAErD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,EAAE;gBAClB,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAA,kBAAS,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;aACzF;YAED,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,CAAC;YAClC,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC/B,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;KAAA;CAGF;AAjLD,kCAiLC;AAED,IAAA,mBAAW,EAAC,WAAW,EAAE,CAAC,oBAAY,CAAC,CAAC,CAAC;AAEzC,kBAAe,WAAW,CAAC","sourcesContent":["import { ACL } from '@nocobase/acl';\nimport { registerActions } from '@nocobase/actions';\nimport Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';\nimport Resourcer, { ResourceOptions } from '@nocobase/resourcer';\nimport { applyMixins, AsyncEmitter } from '@nocobase/utils';\nimport { Command, CommandOptions } from 'commander';\nimport { Server } from 'http';\nimport { i18n, InitOptions } from 'i18next';\nimport Koa from 'koa';\nimport { isBoolean } from 'lodash';\nimport { createACL } from './acl';\nimport { AppManager } from './app-manager';\nimport { createCli } from './commands';\nimport { createDatabase, createI18n, createResourcer, registerMiddlewares } from './helper';\nimport { Plugin } from './plugin';\nimport { InstallOptions, PluginManager } from './plugin-manager';\n\nexport type PluginConfiguration = string | [string, any];\nexport type PluginsConfigurations = Array<PluginConfiguration>;\n\nexport interface ResourcerOptions {\n prefix?: string;\n}\n\nexport interface ApplicationOptions {\n database?: IDatabaseOptions | Database;\n resourcer?: ResourcerOptions;\n bodyParser?: any;\n cors?: any;\n dataWrapping?: boolean;\n registerActions?: boolean;\n i18n?: i18n | InitOptions;\n plugins?: PluginsConfigurations;\n}\n\ninterface DefaultState {\n currentUser?: any;\n [key: string]: any;\n}\n\ninterface DefaultContext {\n db: Database;\n resourcer: Resourcer;\n [key: string]: any;\n}\n\ninterface MiddlewareOptions {\n name?: string;\n resourceName?: string;\n resourceNames?: string[];\n insertBefore?: string;\n insertAfter?: string;\n}\n\ninterface ActionsOptions {\n resourceName?: string;\n resourceNames?: string[];\n}\n\ninterface ListenOptions {\n port?: number | undefined;\n host?: string | undefined;\n backlog?: number | undefined;\n path?: string | undefined;\n exclusive?: boolean | undefined;\n readableAll?: boolean | undefined;\n writableAll?: boolean | undefined;\n /**\n * @default false\n */\n ipv6Only?: boolean | undefined;\n signal?: AbortSignal | undefined;\n}\n\ninterface StartOptions {\n cliArgs?: any[];\n listen?: ListenOptions;\n}\n\nexport class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {\n public readonly db: Database;\n\n public readonly resourcer: Resourcer;\n\n public readonly cli: Command;\n\n public readonly i18n: i18n;\n\n public readonly pm: PluginManager;\n\n public readonly acl: ACL;\n\n public readonly appManager: AppManager;\n\n protected plugins = new Map<string, Plugin>();\n\n public listenServer: Server;\n\n constructor(public options: ApplicationOptions) {\n super();\n\n this.acl = createACL();\n this.db = createDatabase(options);\n this.resourcer = createResourcer(options);\n this.cli = createCli(this);\n this.i18n = createI18n(options);\n\n this.pm = new PluginManager({\n app: this,\n });\n\n this.appManager = new AppManager(this);\n\n registerMiddlewares(this, options);\n\n if (options.registerActions !== false) {\n registerActions(this);\n }\n\n this.loadPluginConfig(options.plugins || []);\n }\n\n plugin<O = any>(pluginClass: any, options?: O): Plugin<O> {\n return this.pm.add(pluginClass, options);\n }\n\n loadPluginConfig(pluginsConfigurations: PluginsConfigurations) {\n for (let pluginConfiguration of pluginsConfigurations) {\n if (typeof pluginConfiguration == 'string') {\n pluginConfiguration = [pluginConfiguration, {}];\n }\n\n const plugin = PluginManager.resolvePlugin(pluginConfiguration[0]);\n const pluginOptions = pluginConfiguration[1];\n\n this.plugin(plugin, pluginOptions);\n }\n }\n\n use<NewStateT = {}, NewContextT = {}>(\n middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>,\n options?: MiddlewareOptions,\n ) {\n // @ts-ignore\n return super.use(middleware);\n }\n\n collection(options: CollectionOptions) {\n return this.db.collection(options);\n }\n\n resource(options: ResourceOptions) {\n return this.resourcer.define(options);\n }\n\n actions(handlers: any, options?: ActionsOptions) {\n return this.resourcer.registerActions(handlers);\n }\n\n command(name: string, desc?: string, opts?: CommandOptions): Command {\n return this.cli.command(name, desc, opts);\n }\n\n findCommand(name: string): Command {\n return (<any>this.cli)._findCommand(name);\n }\n\n async load() {\n await this.pm.load();\n }\n\n getPlugin<P extends Plugin>(name: string) {\n return this.pm.get(name) as P;\n }\n\n async parse(argv = process.argv) {\n await this.load();\n return this.cli.parseAsync(argv);\n }\n\n async start(options?: StartOptions) {\n // reconnect database\n if (this.db.closed()) {\n await this.db.reconnect();\n }\n\n await this.emitAsync('beforeStart', this, options);\n\n if (options?.listen?.port) {\n const listen = () =>\n new Promise((resolve) => {\n const Server = this.listen(options?.listen, () => {\n resolve(Server);\n });\n });\n\n // @ts-ignore\n this.listenServer = await listen();\n }\n\n await this.emitAsync('afterStart', this, options);\n }\n\n listen(...args): Server {\n return this.appManager.listen(...args);\n }\n\n async stop(options?: any) {\n await this.emitAsync('beforeStop', this, options);\n\n try {\n // close database connection\n // silent if database already closed\n await this.db.close();\n } catch (e) {\n console.log(e);\n }\n\n // close http server\n if (this.listenServer) {\n const closeServer = () =>\n new Promise((resolve, reject) => {\n this.listenServer.close((err) => {\n if (err) {\n return reject(err);\n }\n this.listenServer = null;\n resolve(true);\n });\n });\n\n await closeServer();\n }\n\n await this.emitAsync('afterStop', this, options);\n }\n\n async destroy(options?: any) {\n await this.emitAsync('beforeDestroy', this, options);\n await this.stop(options);\n await this.emitAsync('afterDestroy', this, options);\n }\n\n async install(options?: InstallOptions) {\n await this.emitAsync('beforeInstall', this, options);\n\n if (options?.clean) {\n await this.db.clean(isBoolean(options.clean) ? { drop: options.clean } : options.clean);\n }\n\n await this.db.sync(options?.sync);\n await this.pm.install(options);\n await this.emitAsync('afterInstall', this, options);\n }\n\n emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;\n}\n\napplyMixins(Application, [AsyncEmitter]);\n\nexport default Application;\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const REPL = require('repl');
|
|
13
|
+
exports.default = ({ app }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
yield app.start();
|
|
15
|
+
const repl = (REPL.start('nocobase > ').context.app = app);
|
|
16
|
+
repl.on('exit', function (err) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (err) {
|
|
19
|
+
console.log(err);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
yield app.stop();
|
|
23
|
+
process.exit(0);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/commands/console.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE7B,kBAAe,CAAO,EAAE,GAAG,EAAE,EAAE,EAAE;IAC/B,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IAClB,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;IAE3D,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,UAAgB,GAAG;;YACjC,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;YAED,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;KAAA,CAAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["const REPL = require('repl');\n\nexport default async ({ app }) => {\n await app.start();\n const repl = (REPL.start('nocobase > ').context.app = app);\n\n repl.on('exit', async function (err) {\n if (err) {\n console.log(err);\n process.exit(1);\n }\n\n await app.stop();\n process.exit(0);\n });\n};\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const chalk = require('chalk');
|
|
13
|
+
const fse = require('fs-extra');
|
|
14
|
+
const { join } = require('path');
|
|
15
|
+
const createPackageJson = require('./resources/templates/package-json');
|
|
16
|
+
const createPluginClass = require('./resources/templates/plugin');
|
|
17
|
+
exports.default = (name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const pluginName = `plugin-${name}`;
|
|
19
|
+
const pluginPath = join(process.cwd(), `packages/${pluginName}`);
|
|
20
|
+
const resourcePath = join(__dirname, 'resources');
|
|
21
|
+
console.log(`Creating a new NocoBase plugin at ${chalk.green(pluginPath)}.`);
|
|
22
|
+
yield fse.copy(join(resourcePath, 'files'), pluginPath);
|
|
23
|
+
yield fse.outputFile(join(pluginPath, 'src/server/index.ts'), createPluginClass({ name }));
|
|
24
|
+
// write server package.json
|
|
25
|
+
yield fse.writeJson(join(pluginPath, 'package.json'), createPackageJson({
|
|
26
|
+
name: pluginName,
|
|
27
|
+
}), {
|
|
28
|
+
spaces: 2,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=create-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-plugin.js","sourceRoot":"","sources":["../../../src/commands/create-plugin/create-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAChC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AACjC,MAAM,iBAAiB,GAAG,OAAO,CAAC,oCAAoC,CAAC,CAAC;AACxE,MAAM,iBAAiB,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAElE,kBAAe,CAAO,IAAI,EAAE,EAAE;IAC5B,MAAM,UAAU,GAAG,UAAU,IAAI,EAAE,CAAC;IAEpC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,UAAU,EAAE,CAAC,CAAC;IACjE,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAElD,OAAO,CAAC,GAAG,CAAC,qCAAqC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7E,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC;IAExD,MAAM,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,qBAAqB,CAAC,EAAE,iBAAiB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE3F,4BAA4B;IAC5B,MAAM,GAAG,CAAC,SAAS,CACjB,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,EAChC,iBAAiB,CAAC;QAChB,IAAI,EAAE,UAAU;KACjB,CAAC,EACF;QACE,MAAM,EAAE,CAAC;KACV,CACF,CAAC;AACJ,CAAC,CAAA,CAAC","sourcesContent":["const chalk = require('chalk');\nconst fse = require('fs-extra');\nconst { join } = require('path');\nconst createPackageJson = require('./resources/templates/package-json');\nconst createPluginClass = require('./resources/templates/plugin');\n\nexport default async (name) => {\n const pluginName = `plugin-${name}`;\n\n const pluginPath = join(process.cwd(), `packages/${pluginName}`);\n const resourcePath = join(__dirname, 'resources');\n\n console.log(`Creating a new NocoBase plugin at ${chalk.green(pluginPath)}.`);\n await fse.copy(join(resourcePath, 'files'), pluginPath);\n\n await fse.outputFile(join(pluginPath, 'src/server/index.ts'), createPluginClass({ name }));\n\n // write server package.json\n await fse.writeJson(\n join(pluginPath, 'package.json'),\n createPackageJson({\n name: pluginName,\n }),\n {\n spaces: 2,\n },\n );\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/create-plugin/index.ts"],"names":[],"mappings":";;AAAA,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAChD,kBAAe,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACxB,YAAY,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC,CAAC","sourcesContent":["const createPlugin = require('./create-plugin');\nexport default ({ app, cliArgs }) => {\n const name = cliArgs[0];\n createPlugin(name);\n};\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = ({ name }) => {
|
|
4
|
+
return {
|
|
5
|
+
name: name,
|
|
6
|
+
version: '0.1.0',
|
|
7
|
+
main: 'server.js',
|
|
8
|
+
dependencies: {
|
|
9
|
+
'@nocobase/server': '^0.6.0-alpha.0',
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=package-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../../../../src/commands/create-plugin/resources/templates/package-json.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC1B,OAAO;QACL,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,WAAW;QACjB,YAAY,EAAE;YACZ,kBAAkB,EAAE,gBAAgB;SACrC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["export default ({ name }) => {\n return {\n name: name,\n version: '0.1.0',\n main: 'server.js',\n dependencies: {\n '@nocobase/server': '^0.6.0-alpha.0',\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const _ = __importStar(require("lodash"));
|
|
23
|
+
const fs = __importStar(require("fs"));
|
|
24
|
+
const path = __importStar(require("path"));
|
|
25
|
+
exports.default = ({ name }) => {
|
|
26
|
+
const tmpl = fs.readFileSync(path.join(__dirname, 'plugin-class.template'), { encoding: 'utf-8' });
|
|
27
|
+
const compile = _.template(tmpl);
|
|
28
|
+
return compile({
|
|
29
|
+
name,
|
|
30
|
+
className: _.startCase(_.camelCase(name)),
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../../../src/commands/create-plugin/resources/templates/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,0CAA4B;AAC5B,uCAAyB;AACzB,2CAA6B;AAE7B,kBAAe,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC1B,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACnG,MAAM,OAAO,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEjC,OAAO,OAAO,CAAC;QACb,IAAI;QACJ,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import * as _ from 'lodash';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nexport default ({ name }) => {\n const tmpl = fs.readFileSync(path.join(__dirname, 'plugin-class.template'), { encoding: 'utf-8' });\n const compile = _.template(tmpl);\n\n return compile({\n name,\n className: _.startCase(_.camelCase(name)),\n });\n};\n"]}
|