@nocobase/server 0.9.1-alpha.2 → 0.9.2-alpha.1
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/lib/acl/index.js +3 -18
- package/lib/app-manager.d.ts +9 -9
- package/lib/app-manager.js +58 -89
- package/lib/application.js +25 -171
- package/lib/commands/console.js +0 -7
- package/lib/commands/db-auth.js +0 -5
- package/lib/commands/db-clean.js +0 -5
- package/lib/commands/db-sync.js +0 -4
- package/lib/commands/index.js +2 -12
- package/lib/commands/install.js +0 -14
- package/lib/commands/migrator.js +0 -5
- package/lib/commands/pm.js +3 -10
- package/lib/commands/start.js +0 -5
- package/lib/commands/upgrade.js +0 -8
- package/lib/helper.js +13 -36
- package/lib/index.js +0 -15
- package/lib/middlewares/data-template.d.ts +2 -0
- package/lib/middlewares/data-template.js +147 -0
- package/lib/middlewares/data-wrapping.js +4 -26
- package/lib/middlewares/db2resource.js +7 -25
- package/lib/middlewares/i18n.js +0 -8
- package/lib/middlewares/index.d.ts +1 -0
- package/lib/middlewares/index.js +13 -5
- package/lib/middlewares/parse-variables.d.ts +1 -0
- package/lib/middlewares/parse-variables.js +79 -0
- package/lib/migration.js +0 -7
- package/lib/plugin-manager/index.d.ts +1 -1
- package/lib/plugin-manager/index.js +4 -6
- package/lib/plugin-manager/options/collection.d.ts +1 -15
- package/lib/plugin-manager/options/collection.js +10 -3
- package/lib/plugin-manager/options/resource.js +0 -16
- package/lib/plugin-manager/{PluginManagerRepository.d.ts → plugin-manager-repository.d.ts} +1 -1
- package/lib/plugin-manager/{PluginManagerRepository.js → plugin-manager-repository.js} +49 -32
- package/lib/plugin-manager/{PluginManager.d.ts → plugin-manager.d.ts} +1 -1
- package/lib/plugin-manager/{PluginManager.js → plugin-manager.js} +83 -202
- package/lib/plugin.d.ts +2 -0
- package/lib/plugin.js +6 -20
- package/lib/read-config.js +5 -48
- package/package.json +9 -7
|
@@ -4,109 +4,72 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.PluginManager = void 0;
|
|
7
|
-
|
|
8
7
|
function _utils() {
|
|
9
8
|
const data = require("@nocobase/utils");
|
|
10
|
-
|
|
11
9
|
_utils = function _utils() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _execa() {
|
|
19
15
|
const data = _interopRequireDefault(require("execa"));
|
|
20
|
-
|
|
21
16
|
_execa = function _execa() {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _fs() {
|
|
29
22
|
const data = _interopRequireDefault(require("fs"));
|
|
30
|
-
|
|
31
23
|
_fs = function _fs() {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _net() {
|
|
39
29
|
const data = _interopRequireDefault(require("net"));
|
|
40
|
-
|
|
41
30
|
_net = function _net() {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _path() {
|
|
49
36
|
const data = require("path");
|
|
50
|
-
|
|
51
37
|
_path = function _path() {
|
|
52
38
|
return data;
|
|
53
39
|
};
|
|
54
|
-
|
|
55
40
|
return data;
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
function _xpipe() {
|
|
59
43
|
const data = _interopRequireDefault(require("xpipe"));
|
|
60
|
-
|
|
61
44
|
_xpipe = function _xpipe() {
|
|
62
45
|
return data;
|
|
63
46
|
};
|
|
64
|
-
|
|
65
47
|
return data;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
var _collection = _interopRequireDefault(require("./options/collection"));
|
|
69
|
-
|
|
70
50
|
var _resource = _interopRequireDefault(require("./options/resource"));
|
|
71
|
-
|
|
72
|
-
var _PluginManagerRepository = require("./PluginManagerRepository");
|
|
73
|
-
|
|
51
|
+
var _pluginManagerRepository = require("./plugin-manager-repository");
|
|
74
52
|
const _excluded = ["enabled", "builtIn", "installed"];
|
|
75
|
-
|
|
76
53
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
77
|
-
|
|
78
54
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
79
|
-
|
|
80
55
|
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."); }
|
|
81
|
-
|
|
82
|
-
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; }
|
|
83
|
-
|
|
56
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
84
57
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
85
|
-
|
|
86
58
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
87
|
-
|
|
88
59
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
89
|
-
|
|
90
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
91
|
-
|
|
92
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
93
|
-
|
|
94
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
95
|
-
|
|
96
60
|
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; } } }; }
|
|
97
|
-
|
|
98
61
|
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); }
|
|
99
|
-
|
|
100
62
|
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; }
|
|
101
|
-
|
|
63
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
64
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
65
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
66
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
67
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
102
68
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
103
|
-
|
|
104
69
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
105
|
-
|
|
106
70
|
class PluginManager {
|
|
107
71
|
constructor(options) {
|
|
108
72
|
var _this = this;
|
|
109
|
-
|
|
110
73
|
this.app = void 0;
|
|
111
74
|
this.collection = void 0;
|
|
112
75
|
this.repository = void 0;
|
|
@@ -118,55 +81,56 @@ class PluginManager {
|
|
|
118
81
|
const f = (0, _path().resolve)(process.cwd(), 'storage', 'pm.sock');
|
|
119
82
|
this.pmSock = _xpipe().default.eq(this.app.options.pmSock || f);
|
|
120
83
|
this.app.db.registerRepositories({
|
|
121
|
-
PluginManagerRepository:
|
|
84
|
+
PluginManagerRepository: _pluginManagerRepository.PluginManagerRepository
|
|
122
85
|
});
|
|
123
86
|
this.collection = this.app.db.collection(_collection.default);
|
|
124
87
|
this.repository = this.collection.repository;
|
|
125
88
|
this.repository.setPluginManager(this);
|
|
126
89
|
this.app.resourcer.define(_resource.default);
|
|
90
|
+
this.app.resourcer.use( /*#__PURE__*/function () {
|
|
91
|
+
var _ref = _asyncToGenerator(function* (ctx, next) {
|
|
92
|
+
yield next();
|
|
93
|
+
const _ctx$action = ctx.action,
|
|
94
|
+
resourceName = _ctx$action.resourceName,
|
|
95
|
+
actionName = _ctx$action.actionName;
|
|
96
|
+
if (resourceName === 'applicationPlugins' && actionName === 'list') {
|
|
97
|
+
const lng = ctx.getCurrentLocale();
|
|
98
|
+
if (Array.isArray(ctx.body)) {
|
|
99
|
+
ctx.body = ctx.body.map(plugin => {
|
|
100
|
+
const json = plugin.toJSON();
|
|
101
|
+
const packageName = PluginManager.getPackageName(json.name);
|
|
102
|
+
const packageJson = PluginManager.getPackageJson(packageName);
|
|
103
|
+
return _objectSpread({
|
|
104
|
+
displayName: packageJson[`displayName.${lng}`] || packageJson.displayName,
|
|
105
|
+
description: packageJson[`description.${lng}`] || packageJson.description
|
|
106
|
+
}, json);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return function (_x, _x2) {
|
|
112
|
+
return _ref.apply(this, arguments);
|
|
113
|
+
};
|
|
114
|
+
}());
|
|
127
115
|
this.app.acl.registerSnippet({
|
|
128
116
|
name: 'pm',
|
|
129
117
|
actions: ['pm:*', 'applicationPlugins:list']
|
|
130
118
|
});
|
|
131
|
-
this.server = _net().default.createServer(socket => {
|
|
132
|
-
socket.on('data', /*#__PURE__*/function () {
|
|
133
|
-
var _ref = _asyncToGenerator(function* (data) {
|
|
134
|
-
const _JSON$parse = JSON.parse(data.toString()),
|
|
135
|
-
method = _JSON$parse.method,
|
|
136
|
-
plugins = _JSON$parse.plugins;
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
console.log(method, plugins);
|
|
140
|
-
yield _this[method](plugins);
|
|
141
|
-
} catch (error) {
|
|
142
|
-
console.error(error.message);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
return function (_x) {
|
|
147
|
-
return _ref.apply(this, arguments);
|
|
148
|
-
};
|
|
149
|
-
}());
|
|
150
|
-
socket.pipe(socket);
|
|
151
|
-
});
|
|
152
119
|
this.app.on('beforeLoad', /*#__PURE__*/function () {
|
|
153
120
|
var _ref2 = _asyncToGenerator(function* (app, options) {
|
|
154
121
|
if ((options === null || options === void 0 ? void 0 : options.method) && ['install', 'upgrade'].includes(options.method)) {
|
|
155
122
|
yield _this.collection.sync();
|
|
156
123
|
}
|
|
157
|
-
|
|
158
124
|
const exists = yield _this.app.db.collectionExistsInDb('applicationPlugins');
|
|
159
|
-
|
|
160
125
|
if (!exists) {
|
|
126
|
+
_this.app.log.warn(`applicationPlugins collection not exists in ${_this.app.name}`);
|
|
161
127
|
return;
|
|
162
128
|
}
|
|
163
|
-
|
|
164
129
|
if ((options === null || options === void 0 ? void 0 : options.method) !== 'install' || options.reload) {
|
|
165
130
|
yield _this.repository.load();
|
|
166
131
|
}
|
|
167
132
|
});
|
|
168
|
-
|
|
169
|
-
return function (_x2, _x3) {
|
|
133
|
+
return function (_x3, _x4) {
|
|
170
134
|
return _ref2.apply(this, arguments);
|
|
171
135
|
};
|
|
172
136
|
}());
|
|
@@ -175,15 +139,12 @@ class PluginManager {
|
|
|
175
139
|
}));
|
|
176
140
|
this.addStaticMultiple(options.plugins);
|
|
177
141
|
}
|
|
178
|
-
|
|
179
142
|
addStaticMultiple(plugins) {
|
|
180
143
|
var _iterator = _createForOfIteratorHelper(plugins || []),
|
|
181
|
-
|
|
182
|
-
|
|
144
|
+
_step;
|
|
183
145
|
try {
|
|
184
146
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
185
147
|
let plugin = _step.value;
|
|
186
|
-
|
|
187
148
|
if (typeof plugin == 'string') {
|
|
188
149
|
this.addStatic(plugin);
|
|
189
150
|
} else {
|
|
@@ -196,25 +157,19 @@ class PluginManager {
|
|
|
196
157
|
_iterator.f();
|
|
197
158
|
}
|
|
198
159
|
}
|
|
199
|
-
|
|
200
160
|
getPlugins() {
|
|
201
161
|
return this.plugins;
|
|
202
162
|
}
|
|
203
|
-
|
|
204
163
|
get(name) {
|
|
205
164
|
return this.plugins.get(name);
|
|
206
165
|
}
|
|
207
|
-
|
|
208
166
|
has(name) {
|
|
209
167
|
return this.plugins.has(name);
|
|
210
168
|
}
|
|
211
|
-
|
|
212
169
|
clientWrite(data) {
|
|
213
170
|
var _this2 = this;
|
|
214
|
-
|
|
215
171
|
const method = data.method,
|
|
216
|
-
|
|
217
|
-
|
|
172
|
+
plugins = data.plugins;
|
|
218
173
|
if (method === 'create') {
|
|
219
174
|
try {
|
|
220
175
|
console.log(method, plugins);
|
|
@@ -222,10 +177,8 @@ class PluginManager {
|
|
|
222
177
|
} catch (error) {
|
|
223
178
|
console.error(error.message);
|
|
224
179
|
}
|
|
225
|
-
|
|
226
180
|
return;
|
|
227
181
|
}
|
|
228
|
-
|
|
229
182
|
const client = new (_net().default.Socket)();
|
|
230
183
|
client.connect(this.pmSock, () => {
|
|
231
184
|
client.write(JSON.stringify(data));
|
|
@@ -240,15 +193,31 @@ class PluginManager {
|
|
|
240
193
|
}
|
|
241
194
|
}));
|
|
242
195
|
}
|
|
243
|
-
|
|
244
196
|
listen() {
|
|
245
197
|
var _this3 = this;
|
|
246
|
-
|
|
247
198
|
return _asyncToGenerator(function* () {
|
|
199
|
+
_this3.server = _net().default.createServer(socket => {
|
|
200
|
+
socket.on('data', /*#__PURE__*/function () {
|
|
201
|
+
var _ref5 = _asyncToGenerator(function* (data) {
|
|
202
|
+
const _JSON$parse = JSON.parse(data.toString()),
|
|
203
|
+
method = _JSON$parse.method,
|
|
204
|
+
plugins = _JSON$parse.plugins;
|
|
205
|
+
try {
|
|
206
|
+
console.log(method, plugins);
|
|
207
|
+
yield _this3[method](plugins);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
console.error(error.message);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
return function (_x5) {
|
|
213
|
+
return _ref5.apply(this, arguments);
|
|
214
|
+
};
|
|
215
|
+
}());
|
|
216
|
+
socket.pipe(socket);
|
|
217
|
+
});
|
|
248
218
|
if (_fs().default.existsSync(_this3.pmSock)) {
|
|
249
219
|
yield _fs().default.promises.unlink(_this3.pmSock);
|
|
250
220
|
}
|
|
251
|
-
|
|
252
221
|
return new Promise(resolve => {
|
|
253
222
|
_this3.server.listen(_this3.pmSock, () => {
|
|
254
223
|
resolve(_this3.server);
|
|
@@ -256,20 +225,16 @@ class PluginManager {
|
|
|
256
225
|
});
|
|
257
226
|
})();
|
|
258
227
|
}
|
|
259
|
-
|
|
260
228
|
create(name) {
|
|
261
229
|
return _asyncToGenerator(function* () {
|
|
262
230
|
console.log('creating...');
|
|
263
231
|
const pluginNames = Array.isArray(name) ? name : [name];
|
|
264
|
-
|
|
265
232
|
const _require = require('@nocobase/cli/src/util'),
|
|
266
|
-
|
|
267
|
-
|
|
233
|
+
run = _require.run;
|
|
268
234
|
const createPlugin = /*#__PURE__*/function () {
|
|
269
|
-
var
|
|
235
|
+
var _ref6 = _asyncToGenerator(function* (name) {
|
|
270
236
|
const _require2 = require('@nocobase/cli/src/plugin-generator'),
|
|
271
|
-
|
|
272
|
-
|
|
237
|
+
PluginGenerator = _require2.PluginGenerator;
|
|
273
238
|
const generator = new PluginGenerator({
|
|
274
239
|
cwd: (0, _path().resolve)(process.cwd(), name),
|
|
275
240
|
args: {},
|
|
@@ -279,25 +244,20 @@ class PluginManager {
|
|
|
279
244
|
});
|
|
280
245
|
yield generator.run();
|
|
281
246
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return _ref5.apply(this, arguments);
|
|
247
|
+
return function createPlugin(_x6) {
|
|
248
|
+
return _ref6.apply(this, arguments);
|
|
285
249
|
};
|
|
286
250
|
}();
|
|
287
|
-
|
|
288
251
|
yield Promise.all(pluginNames.map(pluginName => createPlugin(pluginName)));
|
|
289
252
|
yield run('yarn', ['install']);
|
|
290
253
|
})();
|
|
291
254
|
}
|
|
292
|
-
|
|
293
255
|
clone() {
|
|
294
256
|
const pm = new PluginManager({
|
|
295
257
|
app: this.app
|
|
296
258
|
});
|
|
297
|
-
|
|
298
259
|
var _iterator2 = _createForOfIteratorHelper(this._tmpPluginArgs),
|
|
299
|
-
|
|
300
|
-
|
|
260
|
+
_step2;
|
|
301
261
|
try {
|
|
302
262
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
303
263
|
const arg = _step2.value;
|
|
@@ -308,74 +268,56 @@ class PluginManager {
|
|
|
308
268
|
} finally {
|
|
309
269
|
_iterator2.f();
|
|
310
270
|
}
|
|
311
|
-
|
|
312
271
|
return pm;
|
|
313
272
|
}
|
|
314
|
-
|
|
315
273
|
addStatic(plugin, options) {
|
|
316
274
|
if (!(options === null || options === void 0 ? void 0 : options.async)) {
|
|
317
275
|
this._tmpPluginArgs.push([plugin, options]);
|
|
318
276
|
}
|
|
319
|
-
|
|
320
277
|
let name;
|
|
321
|
-
|
|
322
278
|
if (typeof plugin === 'string') {
|
|
323
279
|
name = plugin;
|
|
324
280
|
plugin = PluginManager.resolvePlugin(plugin);
|
|
325
281
|
} else {
|
|
326
282
|
name = plugin.name;
|
|
327
|
-
|
|
328
283
|
if (!name) {
|
|
329
284
|
throw new Error(`plugin name invalid`);
|
|
330
285
|
}
|
|
331
286
|
}
|
|
332
|
-
|
|
333
287
|
const instance = new plugin(this.app, _objectSpread({
|
|
334
288
|
name,
|
|
335
289
|
enabled: true
|
|
336
290
|
}, options));
|
|
337
291
|
const pluginName = instance.getName();
|
|
338
|
-
|
|
339
292
|
if (this.plugins.has(pluginName)) {
|
|
340
293
|
throw new Error(`plugin name [${pluginName}] already exists`);
|
|
341
294
|
}
|
|
342
|
-
|
|
343
295
|
this.plugins.set(pluginName, instance);
|
|
344
296
|
return instance;
|
|
345
297
|
}
|
|
346
|
-
|
|
347
298
|
generateClientFile(plugin, packageName) {
|
|
348
299
|
return _asyncToGenerator(function* () {
|
|
349
300
|
const file = (0, _path().resolve)(process.cwd(), 'packages', process.env.APP_PACKAGE_ROOT || 'app', 'client/src/plugins', `${plugin}.ts`);
|
|
350
|
-
|
|
351
301
|
if (!_fs().default.existsSync(file)) {
|
|
352
302
|
try {
|
|
353
303
|
require.resolve(`${packageName}/client`);
|
|
354
|
-
|
|
355
304
|
yield _fs().default.promises.writeFile(file, `export { default } from '${packageName}/client';`);
|
|
356
|
-
|
|
357
305
|
const _require3 = require('@nocobase/cli/src/util'),
|
|
358
|
-
|
|
359
|
-
|
|
306
|
+
run = _require3.run;
|
|
360
307
|
yield run('yarn', ['nocobase', 'postinstall']);
|
|
361
308
|
} catch (error) {}
|
|
362
309
|
}
|
|
363
310
|
})();
|
|
364
311
|
}
|
|
365
|
-
|
|
366
312
|
add(plugin, options = {}, transaction) {
|
|
367
313
|
var _this4 = this;
|
|
368
|
-
|
|
369
314
|
return _asyncToGenerator(function* () {
|
|
370
315
|
if (Array.isArray(plugin)) {
|
|
371
316
|
const t = transaction || (yield _this4.app.db.sequelize.transaction());
|
|
372
|
-
|
|
373
317
|
try {
|
|
374
318
|
const items = [];
|
|
375
|
-
|
|
376
319
|
var _iterator3 = _createForOfIteratorHelper(plugin),
|
|
377
|
-
|
|
378
|
-
|
|
320
|
+
_step3;
|
|
379
321
|
try {
|
|
380
322
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
381
323
|
const p = _step3.value;
|
|
@@ -386,7 +328,6 @@ class PluginManager {
|
|
|
386
328
|
} finally {
|
|
387
329
|
_iterator3.f();
|
|
388
330
|
}
|
|
389
|
-
|
|
390
331
|
yield t.commit();
|
|
391
332
|
return items;
|
|
392
333
|
} catch (error) {
|
|
@@ -394,14 +335,11 @@ class PluginManager {
|
|
|
394
335
|
throw error;
|
|
395
336
|
}
|
|
396
337
|
}
|
|
397
|
-
|
|
398
338
|
const packageName = yield PluginManager.findPackage(plugin);
|
|
399
339
|
yield _this4.generateClientFile(plugin, packageName);
|
|
400
|
-
|
|
401
340
|
const instance = _this4.addStatic(plugin, _objectSpread(_objectSpread({}, options), {}, {
|
|
402
341
|
async: true
|
|
403
342
|
}));
|
|
404
|
-
|
|
405
343
|
let model = yield _this4.repository.findOne({
|
|
406
344
|
transaction,
|
|
407
345
|
filter: {
|
|
@@ -409,13 +347,11 @@ class PluginManager {
|
|
|
409
347
|
}
|
|
410
348
|
});
|
|
411
349
|
const packageJson = PluginManager.getPackageJson(packageName);
|
|
412
|
-
|
|
413
350
|
if (!model) {
|
|
414
351
|
const enabled = options.enabled,
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
352
|
+
builtIn = options.builtIn,
|
|
353
|
+
installed = options.installed,
|
|
354
|
+
others = _objectWithoutProperties(options, _excluded);
|
|
419
355
|
yield _this4.repository.create({
|
|
420
356
|
transaction,
|
|
421
357
|
values: {
|
|
@@ -428,28 +364,22 @@ class PluginManager {
|
|
|
428
364
|
}
|
|
429
365
|
});
|
|
430
366
|
}
|
|
431
|
-
|
|
432
367
|
return instance;
|
|
433
368
|
})();
|
|
434
369
|
}
|
|
435
|
-
|
|
436
370
|
load(options = {}) {
|
|
437
371
|
var _this5 = this;
|
|
438
|
-
|
|
439
372
|
return _asyncToGenerator(function* () {
|
|
440
373
|
var _iterator4 = _createForOfIteratorHelper(_this5.plugins),
|
|
441
|
-
|
|
442
|
-
|
|
374
|
+
_step4;
|
|
443
375
|
try {
|
|
444
376
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
445
377
|
const _step4$value = _slicedToArray(_step4.value, 2),
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
378
|
+
name = _step4$value[0],
|
|
379
|
+
plugin = _step4$value[1];
|
|
449
380
|
if (!plugin.enabled) {
|
|
450
381
|
continue;
|
|
451
382
|
}
|
|
452
|
-
|
|
453
383
|
yield plugin.beforeLoad();
|
|
454
384
|
}
|
|
455
385
|
} catch (err) {
|
|
@@ -457,20 +387,16 @@ class PluginManager {
|
|
|
457
387
|
} finally {
|
|
458
388
|
_iterator4.f();
|
|
459
389
|
}
|
|
460
|
-
|
|
461
390
|
var _iterator5 = _createForOfIteratorHelper(_this5.plugins),
|
|
462
|
-
|
|
463
|
-
|
|
391
|
+
_step5;
|
|
464
392
|
try {
|
|
465
393
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
466
394
|
const _step5$value = _slicedToArray(_step5.value, 2),
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
395
|
+
name = _step5$value[0],
|
|
396
|
+
plugin = _step5$value[1];
|
|
470
397
|
if (!plugin.enabled) {
|
|
471
398
|
continue;
|
|
472
399
|
}
|
|
473
|
-
|
|
474
400
|
yield _this5.app.emitAsync('beforeLoadPlugin', plugin, options);
|
|
475
401
|
yield plugin.load();
|
|
476
402
|
yield _this5.app.emitAsync('afterLoadPlugin', plugin, options);
|
|
@@ -482,24 +408,19 @@ class PluginManager {
|
|
|
482
408
|
}
|
|
483
409
|
})();
|
|
484
410
|
}
|
|
485
|
-
|
|
486
411
|
install(options = {}) {
|
|
487
412
|
var _this6 = this;
|
|
488
|
-
|
|
489
413
|
return _asyncToGenerator(function* () {
|
|
490
414
|
var _iterator6 = _createForOfIteratorHelper(_this6.plugins),
|
|
491
|
-
|
|
492
|
-
|
|
415
|
+
_step6;
|
|
493
416
|
try {
|
|
494
417
|
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
495
418
|
const _step6$value = _slicedToArray(_step6.value, 2),
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
419
|
+
name = _step6$value[0],
|
|
420
|
+
plugin = _step6$value[1];
|
|
499
421
|
if (!plugin.enabled) {
|
|
500
422
|
continue;
|
|
501
423
|
}
|
|
502
|
-
|
|
503
424
|
yield _this6.app.emitAsync('beforeInstallPlugin', plugin, options);
|
|
504
425
|
yield plugin.install(options);
|
|
505
426
|
yield _this6.app.emitAsync('afterInstallPlugin', plugin, options);
|
|
@@ -511,29 +432,22 @@ class PluginManager {
|
|
|
511
432
|
}
|
|
512
433
|
})();
|
|
513
434
|
}
|
|
514
|
-
|
|
515
435
|
enable(name) {
|
|
516
436
|
var _this7 = this;
|
|
517
|
-
|
|
518
437
|
return _asyncToGenerator(function* () {
|
|
519
438
|
try {
|
|
520
439
|
const pluginNames = yield _this7.repository.enable(name);
|
|
521
440
|
yield _this7.app.reload();
|
|
522
441
|
yield _this7.app.db.sync();
|
|
523
|
-
|
|
524
442
|
var _iterator7 = _createForOfIteratorHelper(pluginNames),
|
|
525
|
-
|
|
526
|
-
|
|
443
|
+
_step7;
|
|
527
444
|
try {
|
|
528
445
|
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
529
446
|
const pluginName = _step7.value;
|
|
530
|
-
|
|
531
447
|
const plugin = _this7.app.getPlugin(pluginName);
|
|
532
|
-
|
|
533
448
|
if (!plugin) {
|
|
534
449
|
throw new Error(`${name} plugin does not exist`);
|
|
535
450
|
}
|
|
536
|
-
|
|
537
451
|
yield plugin.install();
|
|
538
452
|
yield plugin.afterEnable();
|
|
539
453
|
}
|
|
@@ -542,33 +456,27 @@ class PluginManager {
|
|
|
542
456
|
} finally {
|
|
543
457
|
_iterator7.f();
|
|
544
458
|
}
|
|
459
|
+
yield _this7.app.emitAsync('afterEnablePlugin', name);
|
|
545
460
|
} catch (error) {
|
|
546
461
|
throw error;
|
|
547
462
|
}
|
|
548
463
|
})();
|
|
549
464
|
}
|
|
550
|
-
|
|
551
465
|
disable(name) {
|
|
552
466
|
var _this8 = this;
|
|
553
|
-
|
|
554
467
|
return _asyncToGenerator(function* () {
|
|
555
468
|
try {
|
|
556
469
|
const pluginNames = yield _this8.repository.disable(name);
|
|
557
470
|
yield _this8.app.reload();
|
|
558
|
-
|
|
559
471
|
var _iterator8 = _createForOfIteratorHelper(pluginNames),
|
|
560
|
-
|
|
561
|
-
|
|
472
|
+
_step8;
|
|
562
473
|
try {
|
|
563
474
|
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
564
475
|
const pluginName = _step8.value;
|
|
565
|
-
|
|
566
476
|
const plugin = _this8.app.getPlugin(pluginName);
|
|
567
|
-
|
|
568
477
|
if (!plugin) {
|
|
569
478
|
throw new Error(`${name} plugin does not exist`);
|
|
570
479
|
}
|
|
571
|
-
|
|
572
480
|
yield plugin.afterDisable();
|
|
573
481
|
}
|
|
574
482
|
} catch (err) {
|
|
@@ -576,31 +484,25 @@ class PluginManager {
|
|
|
576
484
|
} finally {
|
|
577
485
|
_iterator8.f();
|
|
578
486
|
}
|
|
487
|
+
yield _this8.app.emitAsync('afterDisablePlugin', name);
|
|
579
488
|
} catch (error) {
|
|
580
489
|
throw error;
|
|
581
490
|
}
|
|
582
491
|
})();
|
|
583
492
|
}
|
|
584
|
-
|
|
585
493
|
remove(name) {
|
|
586
494
|
var _this9 = this;
|
|
587
|
-
|
|
588
495
|
return _asyncToGenerator(function* () {
|
|
589
496
|
const pluginNames = typeof name === 'string' ? [name] : name;
|
|
590
|
-
|
|
591
497
|
var _iterator9 = _createForOfIteratorHelper(pluginNames),
|
|
592
|
-
|
|
593
|
-
|
|
498
|
+
_step9;
|
|
594
499
|
try {
|
|
595
500
|
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
596
501
|
const pluginName = _step9.value;
|
|
597
|
-
|
|
598
502
|
const plugin = _this9.app.getPlugin(pluginName);
|
|
599
|
-
|
|
600
503
|
if (!plugin) {
|
|
601
504
|
throw new Error(`${name} plugin does not exist`);
|
|
602
505
|
}
|
|
603
|
-
|
|
604
506
|
yield plugin.remove();
|
|
605
507
|
}
|
|
606
508
|
} catch (err) {
|
|
@@ -608,30 +510,22 @@ class PluginManager {
|
|
|
608
510
|
} finally {
|
|
609
511
|
_iterator9.f();
|
|
610
512
|
}
|
|
611
|
-
|
|
612
513
|
yield _this9.repository.remove(name);
|
|
613
|
-
|
|
614
514
|
_this9.app.reload();
|
|
615
515
|
})();
|
|
616
516
|
}
|
|
617
|
-
|
|
618
517
|
static getPackageJson(packageName) {
|
|
619
518
|
return require(`${packageName}/package.json`);
|
|
620
519
|
}
|
|
621
|
-
|
|
622
520
|
static getPackageName(name) {
|
|
623
521
|
const prefixes = this.getPluginPkgPrefix();
|
|
624
|
-
|
|
625
522
|
var _iterator10 = _createForOfIteratorHelper(prefixes),
|
|
626
|
-
|
|
627
|
-
|
|
523
|
+
_step10;
|
|
628
524
|
try {
|
|
629
525
|
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
630
526
|
const prefix = _step10.value;
|
|
631
|
-
|
|
632
527
|
try {
|
|
633
528
|
require.resolve(`${prefix}${name}`);
|
|
634
|
-
|
|
635
529
|
return `${prefix}${name}`;
|
|
636
530
|
} catch (error) {
|
|
637
531
|
continue;
|
|
@@ -642,34 +536,25 @@ class PluginManager {
|
|
|
642
536
|
} finally {
|
|
643
537
|
_iterator10.f();
|
|
644
538
|
}
|
|
645
|
-
|
|
646
539
|
throw new Error(`${name} plugin does not exist`);
|
|
647
540
|
}
|
|
648
|
-
|
|
649
541
|
static getPluginPkgPrefix() {
|
|
650
542
|
return (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-').split(',');
|
|
651
543
|
}
|
|
652
|
-
|
|
653
544
|
static findPackage(name) {
|
|
654
545
|
var _this10 = this;
|
|
655
|
-
|
|
656
546
|
return _asyncToGenerator(function* () {
|
|
657
547
|
try {
|
|
658
548
|
const packageName = _this10.getPackageName(name);
|
|
659
|
-
|
|
660
549
|
return packageName;
|
|
661
550
|
} catch (error) {
|
|
662
551
|
console.log(`\`${name}\` plugin not found locally`);
|
|
663
|
-
|
|
664
552
|
const prefixes = _this10.getPluginPkgPrefix();
|
|
665
|
-
|
|
666
553
|
var _iterator11 = _createForOfIteratorHelper(prefixes),
|
|
667
|
-
|
|
668
|
-
|
|
554
|
+
_step11;
|
|
669
555
|
try {
|
|
670
556
|
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
671
557
|
const prefix = _step11.value;
|
|
672
|
-
|
|
673
558
|
try {
|
|
674
559
|
const packageName = `${prefix}${name}`;
|
|
675
560
|
console.log(`Try to find ${packageName}`);
|
|
@@ -688,18 +573,14 @@ class PluginManager {
|
|
|
688
573
|
_iterator11.f();
|
|
689
574
|
}
|
|
690
575
|
}
|
|
691
|
-
|
|
692
576
|
throw new Error(`No available packages found, ${name} plugin does not exist`);
|
|
693
577
|
})();
|
|
694
578
|
}
|
|
695
|
-
|
|
696
579
|
static resolvePlugin(pluginName) {
|
|
697
580
|
const packageName = this.getPackageName(pluginName);
|
|
698
581
|
return (0, _utils().requireModule)(packageName);
|
|
699
582
|
}
|
|
700
|
-
|
|
701
583
|
}
|
|
702
|
-
|
|
703
584
|
exports.PluginManager = PluginManager;
|
|
704
585
|
var _default = PluginManager;
|
|
705
586
|
exports.default = _default;
|