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