@nocobase/plugin-multi-app-manager 0.11.1-alpha.4 → 0.12.0-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/client.d.ts +1 -3
- package/client.js +1 -1
- package/dist/client/index.js +500 -0
- package/{lib → dist}/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/locale/es-ES.js +13 -0
- package/dist/locale/pt-BR.js +13 -0
- package/dist/locale/zh-CN.js +15 -0
- package/dist/server/collections/applications.js +49 -0
- package/dist/server/index.js +21 -0
- package/dist/server/models/application.js +22 -0
- package/dist/server/server.js +260 -0
- package/package.json +15 -24
- package/server.d.ts +2 -3
- package/server.js +1 -1
- package/lib/client/AppManager.js +0 -61
- package/lib/client/AppNameInput.js +0 -40
- package/lib/client/MultiAppManagerProvider.js +0 -119
- package/lib/client/Settings.js +0 -39
- package/lib/client/index.js +0 -34
- package/lib/client/settings/schemas/applications.js +0 -404
- package/lib/client/utils.js +0 -25
- package/lib/index.js +0 -13
- package/lib/locale/es-ES.js +0 -16
- package/lib/locale/pt-BR.js +0 -16
- package/lib/locale/zh-CN.js +0 -18
- package/lib/server/collections/applications.js +0 -49
- package/lib/server/index.js +0 -19
- package/lib/server/models/application.js +0 -39
- package/lib/server/server.js +0 -367
- package/src/client/AppManager.tsx +0 -31
- package/src/client/AppNameInput.tsx +0 -22
- package/src/client/MultiAppManagerProvider.tsx +0 -93
- package/src/client/Settings.tsx +0 -15
- package/src/client/index.ts +0 -11
- package/src/client/settings/schemas/applications.ts +0 -376
- package/src/client/utils.tsx +0 -10
- package/src/index.ts +0 -1
- package/src/locale/es-ES.ts +0 -9
- package/src/locale/pt-BR.ts +0 -9
- package/src/locale/zh-CN.ts +0 -11
- package/src/server/__tests__/mock-get-schema.test.ts +0 -146
- package/src/server/__tests__/multiple-apps.test.ts +0 -209
- package/src/server/collections/applications.ts +0 -45
- package/src/server/index.ts +0 -4
- package/src/server/models/application.ts +0 -28
- package/src/server/server.ts +0 -297
- package/{lib → dist}/client/AppManager.d.ts +0 -0
- package/{lib → dist}/client/AppNameInput.d.ts +0 -0
- package/{lib → dist}/client/MultiAppManagerProvider.d.ts +0 -0
- package/{lib → dist}/client/Settings.d.ts +0 -0
- package/{lib → dist}/client/index.d.ts +1 -1
- /package/{lib → dist}/client/settings/schemas/applications.d.ts +0 -0
- /package/{lib → dist}/client/utils.d.ts +0 -0
- /package/{lib → dist}/locale/es-ES.d.ts +0 -0
- /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
- /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
- /package/{lib → dist}/server/collections/applications.d.ts +0 -0
- /package/{lib → dist}/server/index.d.ts +0 -0
- /package/{lib → dist}/server/models/application.d.ts +0 -0
- /package/{lib → dist}/server/server.d.ts +0 -0
package/lib/server/server.js
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PluginMultiAppManager = void 0;
|
|
7
|
-
function _database() {
|
|
8
|
-
const data = _interopRequireDefault(require("@nocobase/database"));
|
|
9
|
-
_database = function _database() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _server() {
|
|
15
|
-
const data = require("@nocobase/server");
|
|
16
|
-
_server = function _server() {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _utils() {
|
|
22
|
-
const data = require("@nocobase/utils");
|
|
23
|
-
_utils = function _utils() {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function path() {
|
|
29
|
-
const data = _interopRequireWildcard(require("path"));
|
|
30
|
-
path = function path() {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
var _application = require("./models/application");
|
|
36
|
-
function _asyncMutex() {
|
|
37
|
-
const data = require("async-mutex");
|
|
38
|
-
_asyncMutex = function _asyncMutex() {
|
|
39
|
-
return data;
|
|
40
|
-
};
|
|
41
|
-
return data;
|
|
42
|
-
}
|
|
43
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
44
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
45
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
46
|
-
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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
47
|
-
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); }
|
|
48
|
-
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; }
|
|
49
|
-
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; }
|
|
50
|
-
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; }
|
|
51
|
-
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; }
|
|
52
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
53
|
-
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); }
|
|
54
|
-
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); } }
|
|
55
|
-
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); }); }; }
|
|
56
|
-
const defaultDbCreator = /*#__PURE__*/function () {
|
|
57
|
-
var _ref = _asyncToGenerator(function* (app) {
|
|
58
|
-
const databaseOptions = app.options.database;
|
|
59
|
-
const host = databaseOptions.host,
|
|
60
|
-
port = databaseOptions.port,
|
|
61
|
-
username = databaseOptions.username,
|
|
62
|
-
password = databaseOptions.password,
|
|
63
|
-
dialect = databaseOptions.dialect,
|
|
64
|
-
database = databaseOptions.database;
|
|
65
|
-
if (dialect === 'mysql') {
|
|
66
|
-
const mysql = require('mysql2/promise');
|
|
67
|
-
const connection = yield mysql.createConnection({
|
|
68
|
-
host,
|
|
69
|
-
port,
|
|
70
|
-
user: username,
|
|
71
|
-
password
|
|
72
|
-
});
|
|
73
|
-
yield connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
|
|
74
|
-
yield connection.close();
|
|
75
|
-
}
|
|
76
|
-
if (dialect === 'postgres') {
|
|
77
|
-
const _require = require('pg'),
|
|
78
|
-
Client = _require.Client;
|
|
79
|
-
const client = new Client({
|
|
80
|
-
host,
|
|
81
|
-
port,
|
|
82
|
-
user: username,
|
|
83
|
-
password,
|
|
84
|
-
database: 'postgres'
|
|
85
|
-
});
|
|
86
|
-
yield client.connect();
|
|
87
|
-
try {
|
|
88
|
-
yield client.query(`CREATE DATABASE "${database}"`);
|
|
89
|
-
} catch (e) {}
|
|
90
|
-
yield client.end();
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
return function defaultDbCreator(_x) {
|
|
94
|
-
return _ref.apply(this, arguments);
|
|
95
|
-
};
|
|
96
|
-
}();
|
|
97
|
-
const defaultAppOptionsFactory = (appName, mainApp) => {
|
|
98
|
-
const rawDatabaseOptions = PluginMultiAppManager.getDatabaseConfig(mainApp);
|
|
99
|
-
if (rawDatabaseOptions.dialect === 'sqlite') {
|
|
100
|
-
const mainAppStorage = rawDatabaseOptions.storage;
|
|
101
|
-
if (mainAppStorage !== ':memory:') {
|
|
102
|
-
const mainStorageDir = path().dirname(mainAppStorage);
|
|
103
|
-
rawDatabaseOptions.storage = path().join(mainStorageDir, `${appName}.sqlite`);
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
rawDatabaseOptions.database = appName;
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
database: _objectSpread(_objectSpread({}, rawDatabaseOptions), {}, {
|
|
110
|
-
tablePrefix: ''
|
|
111
|
-
}),
|
|
112
|
-
plugins: ['nocobase'],
|
|
113
|
-
resourcer: {
|
|
114
|
-
prefix: '/api'
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
class PluginMultiAppManager extends _server().Plugin {
|
|
119
|
-
constructor(...args) {
|
|
120
|
-
super(...args);
|
|
121
|
-
this.appDbCreator = defaultDbCreator;
|
|
122
|
-
this.appOptionsFactory = defaultAppOptionsFactory;
|
|
123
|
-
this.beforeGetApplicationMutex = new (_asyncMutex().Mutex)();
|
|
124
|
-
}
|
|
125
|
-
setAppOptionsFactory(factory) {
|
|
126
|
-
this.appOptionsFactory = factory;
|
|
127
|
-
}
|
|
128
|
-
setAppDbCreator(appDbCreator) {
|
|
129
|
-
this.appDbCreator = appDbCreator;
|
|
130
|
-
}
|
|
131
|
-
static getDatabaseConfig(app) {
|
|
132
|
-
const oldConfig = app.options.database instanceof _database().default ? app.options.database.options : app.options.database;
|
|
133
|
-
return _utils().lodash.cloneDeep(_utils().lodash.omit(oldConfig, ['migrator']));
|
|
134
|
-
}
|
|
135
|
-
beforeLoad() {
|
|
136
|
-
this.db.registerModels({
|
|
137
|
-
ApplicationModel: _application.ApplicationModel
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
load() {
|
|
141
|
-
var _this = this;
|
|
142
|
-
return _asyncToGenerator(function* () {
|
|
143
|
-
_this.app.appManager.setAppSelector( /*#__PURE__*/function () {
|
|
144
|
-
var _ref2 = _asyncToGenerator(function* (req) {
|
|
145
|
-
if (req.headers['x-app']) {
|
|
146
|
-
return req.headers['x-app'];
|
|
147
|
-
}
|
|
148
|
-
if (req.headers['x-hostname']) {
|
|
149
|
-
const repository = _this.db.getRepository('applications');
|
|
150
|
-
if (!repository) {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
const appInstance = yield repository.findOne({
|
|
154
|
-
filter: {
|
|
155
|
-
cname: req.headers['x-hostname']
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
if (appInstance) {
|
|
159
|
-
return appInstance.name;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return null;
|
|
163
|
-
});
|
|
164
|
-
return function (_x2) {
|
|
165
|
-
return _ref2.apply(this, arguments);
|
|
166
|
-
};
|
|
167
|
-
}());
|
|
168
|
-
yield _this.db.import({
|
|
169
|
-
directory: (0, path().resolve)(__dirname, 'collections')
|
|
170
|
-
});
|
|
171
|
-
// after application created
|
|
172
|
-
_this.db.on('applications.afterCreateWithAssociations', /*#__PURE__*/function () {
|
|
173
|
-
var _ref3 = _asyncToGenerator(function* (model, options) {
|
|
174
|
-
const transaction = options.transaction;
|
|
175
|
-
const subApp = model.registerToMainApp(_this.app, {
|
|
176
|
-
appOptionsFactory: _this.appOptionsFactory
|
|
177
|
-
});
|
|
178
|
-
// create database
|
|
179
|
-
yield _this.appDbCreator(subApp, transaction);
|
|
180
|
-
// reload subApp plugin
|
|
181
|
-
yield subApp.reload();
|
|
182
|
-
// sync subApp collections
|
|
183
|
-
yield subApp.db.sync();
|
|
184
|
-
// install subApp
|
|
185
|
-
yield subApp.install();
|
|
186
|
-
yield subApp.reload();
|
|
187
|
-
});
|
|
188
|
-
return function (_x3, _x4) {
|
|
189
|
-
return _ref3.apply(this, arguments);
|
|
190
|
-
};
|
|
191
|
-
}());
|
|
192
|
-
_this.db.on('applications.afterDestroy', /*#__PURE__*/function () {
|
|
193
|
-
var _ref4 = _asyncToGenerator(function* (model) {
|
|
194
|
-
yield _this.app.appManager.removeApplication(model.get('name'));
|
|
195
|
-
});
|
|
196
|
-
return function (_x5) {
|
|
197
|
-
return _ref4.apply(this, arguments);
|
|
198
|
-
};
|
|
199
|
-
}());
|
|
200
|
-
// lazy load application
|
|
201
|
-
// if application not in appManager, load it from database
|
|
202
|
-
_this.app.on('beforeGetApplication', /*#__PURE__*/function () {
|
|
203
|
-
var _ref5 = _asyncToGenerator(function* ({
|
|
204
|
-
appManager,
|
|
205
|
-
name,
|
|
206
|
-
options
|
|
207
|
-
}) {
|
|
208
|
-
yield _this.beforeGetApplicationMutex.runExclusive( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
209
|
-
if (appManager.applications.has(name)) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const applicationRecord = yield _this.app.db.getRepository('applications').findOne({
|
|
213
|
-
filter: {
|
|
214
|
-
name
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
const instanceOptions = applicationRecord.get('options');
|
|
218
|
-
// skip standalone deployment application
|
|
219
|
-
if (instanceOptions !== null && instanceOptions !== void 0 && instanceOptions.standaloneDeployment && appManager.runningMode !== 'single') {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
if (!applicationRecord) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const subApp = yield applicationRecord.registerToMainApp(_this.app, {
|
|
226
|
-
appOptionsFactory: _this.appOptionsFactory
|
|
227
|
-
});
|
|
228
|
-
// must skip load on upgrade
|
|
229
|
-
if (!(options !== null && options !== void 0 && options.upgrading)) {
|
|
230
|
-
yield subApp.load();
|
|
231
|
-
}
|
|
232
|
-
}));
|
|
233
|
-
});
|
|
234
|
-
return function (_x6) {
|
|
235
|
-
return _ref5.apply(this, arguments);
|
|
236
|
-
};
|
|
237
|
-
}());
|
|
238
|
-
_this.app.on('afterStart', /*#__PURE__*/function () {
|
|
239
|
-
var _ref7 = _asyncToGenerator(function* (app) {
|
|
240
|
-
const repository = _this.db.getRepository('applications');
|
|
241
|
-
const appManager = _this.app.appManager;
|
|
242
|
-
if (appManager.runningMode == 'single') {
|
|
243
|
-
// If the sub application is running in single mode, register the application automatically
|
|
244
|
-
try {
|
|
245
|
-
const subApp = yield repository.findOne({
|
|
246
|
-
filter: {
|
|
247
|
-
name: appManager.singleAppName
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
const registeredApp = yield subApp.registerToMainApp(_this.app, {
|
|
251
|
-
appOptionsFactory: _this.appOptionsFactory
|
|
252
|
-
});
|
|
253
|
-
yield registeredApp.load();
|
|
254
|
-
} catch (err) {
|
|
255
|
-
console.error('Auto register sub application in single mode failed: ', appManager.singleAppName, err);
|
|
256
|
-
}
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
try {
|
|
260
|
-
const subApps = yield repository.find({
|
|
261
|
-
filter: {
|
|
262
|
-
'options.autoStart': true
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
var _iterator = _createForOfIteratorHelper(subApps),
|
|
266
|
-
_step;
|
|
267
|
-
try {
|
|
268
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
269
|
-
const subApp = _step.value;
|
|
270
|
-
const registeredApp = yield subApp.registerToMainApp(_this.app, {
|
|
271
|
-
appOptionsFactory: _this.appOptionsFactory
|
|
272
|
-
});
|
|
273
|
-
yield registeredApp.load();
|
|
274
|
-
}
|
|
275
|
-
} catch (err) {
|
|
276
|
-
_iterator.e(err);
|
|
277
|
-
} finally {
|
|
278
|
-
_iterator.f();
|
|
279
|
-
}
|
|
280
|
-
} catch (err) {
|
|
281
|
-
console.error('Auto register sub applications failed: ', err);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
return function (_x7) {
|
|
285
|
-
return _ref7.apply(this, arguments);
|
|
286
|
-
};
|
|
287
|
-
}());
|
|
288
|
-
_this.app.on('afterUpgrade', /*#__PURE__*/function () {
|
|
289
|
-
var _ref8 = _asyncToGenerator(function* (app, options) {
|
|
290
|
-
const cliArgs = options === null || options === void 0 ? void 0 : options.cliArgs;
|
|
291
|
-
const repository = _this.db.getRepository('applications');
|
|
292
|
-
const findOptions = {};
|
|
293
|
-
const appManager = _this.app.appManager;
|
|
294
|
-
if (appManager.runningMode == 'single') {
|
|
295
|
-
findOptions['filter'] = {
|
|
296
|
-
name: appManager.singleAppName
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
const instances = yield repository.find(findOptions);
|
|
300
|
-
var _iterator2 = _createForOfIteratorHelper(instances),
|
|
301
|
-
_step2;
|
|
302
|
-
try {
|
|
303
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
304
|
-
const instance = _step2.value;
|
|
305
|
-
const instanceOptions = instance.get('options');
|
|
306
|
-
// skip standalone deployment application
|
|
307
|
-
if (instanceOptions !== null && instanceOptions !== void 0 && instanceOptions.standaloneDeployment && appManager.runningMode !== 'single') {
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
const subApp = yield appManager.getApplication(instance.name, {
|
|
311
|
-
upgrading: true
|
|
312
|
-
});
|
|
313
|
-
try {
|
|
314
|
-
console.log(`${instance.name}: upgrading...`);
|
|
315
|
-
yield subApp.upgrade({
|
|
316
|
-
cliArgs
|
|
317
|
-
});
|
|
318
|
-
yield subApp.stop({
|
|
319
|
-
cliArgs
|
|
320
|
-
});
|
|
321
|
-
} catch (error) {
|
|
322
|
-
console.log(`${instance.name}: upgrade failed`);
|
|
323
|
-
_this.app.logger.error(error);
|
|
324
|
-
console.error(error);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
} catch (err) {
|
|
328
|
-
_iterator2.e(err);
|
|
329
|
-
} finally {
|
|
330
|
-
_iterator2.f();
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
return function (_x8, _x9) {
|
|
334
|
-
return _ref8.apply(this, arguments);
|
|
335
|
-
};
|
|
336
|
-
}());
|
|
337
|
-
_this.app.resourcer.registerActionHandlers({
|
|
338
|
-
'applications:listPinned': function () {
|
|
339
|
-
var _applicationsListPinned = _asyncToGenerator(function* (ctx, next) {
|
|
340
|
-
const items = yield _this.db.getRepository('applications').find({
|
|
341
|
-
filter: {
|
|
342
|
-
pinned: true
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
ctx.body = items;
|
|
346
|
-
});
|
|
347
|
-
function applicationsListPinned(_x10, _x11) {
|
|
348
|
-
return _applicationsListPinned.apply(this, arguments);
|
|
349
|
-
}
|
|
350
|
-
return applicationsListPinned;
|
|
351
|
-
}()
|
|
352
|
-
});
|
|
353
|
-
_this.app.acl.allow('applications', 'listPinned', 'loggedIn');
|
|
354
|
-
_this.app.acl.registerSnippet({
|
|
355
|
-
name: `
|
|
356
|
-
pm.$;
|
|
357
|
-
{
|
|
358
|
-
this.name;
|
|
359
|
-
}
|
|
360
|
-
.
|
|
361
|
-
applications`,
|
|
362
|
-
actions: ['applications:*']
|
|
363
|
-
});
|
|
364
|
-
})();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
exports.PluginMultiAppManager = PluginMultiAppManager;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { SchemaComponent, useRecord } from '@nocobase/client';
|
|
2
|
-
import { Card } from 'antd';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { schema } from './settings/schemas/applications';
|
|
5
|
-
import { usePluginUtils } from './utils';
|
|
6
|
-
|
|
7
|
-
const useLink = () => {
|
|
8
|
-
const record = useRecord();
|
|
9
|
-
if (record.options?.standaloneDeployment && record.cname) {
|
|
10
|
-
return `//${record.cname}`;
|
|
11
|
-
}
|
|
12
|
-
return `/apps/${record.name}/admin/`;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const AppVisitor = () => {
|
|
16
|
-
const { t } = usePluginUtils();
|
|
17
|
-
const link = useLink();
|
|
18
|
-
return (
|
|
19
|
-
<a href={link} target={'_blank'} rel="noreferrer">
|
|
20
|
-
{t('View', { ns: 'client' })}
|
|
21
|
-
</a>
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const AppManager = () => {
|
|
26
|
-
return (
|
|
27
|
-
<Card bordered={false}>
|
|
28
|
-
<SchemaComponent schema={schema} components={{ AppVisitor }} />
|
|
29
|
-
</Card>
|
|
30
|
-
);
|
|
31
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { connect, mapReadPretty } from '@formily/react';
|
|
2
|
-
import { Input as AntdInput } from 'antd';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
|
|
5
|
-
const ReadPretty = (props) => {
|
|
6
|
-
const content = props.value && (
|
|
7
|
-
<a target={'_blank'} href={`/apps/${props.value}/admin`} rel="noreferrer">
|
|
8
|
-
{props.value}
|
|
9
|
-
</a>
|
|
10
|
-
);
|
|
11
|
-
return (
|
|
12
|
-
<div style={props.style}>
|
|
13
|
-
{props.addonBefore}
|
|
14
|
-
{props.prefix}
|
|
15
|
-
{content}
|
|
16
|
-
{props.suffix}
|
|
17
|
-
{props.addonAfter}
|
|
18
|
-
</div>
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const AppNameInput = connect(AntdInput, mapReadPretty(ReadPretty));
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Icon,
|
|
3
|
-
PinnedPluginListProvider,
|
|
4
|
-
SchemaComponentOptions,
|
|
5
|
-
SettingsCenterProvider,
|
|
6
|
-
useRequest,
|
|
7
|
-
} from '@nocobase/client';
|
|
8
|
-
import { Button, Dropdown } from 'antd';
|
|
9
|
-
import React from 'react';
|
|
10
|
-
import { Link } from 'react-router-dom';
|
|
11
|
-
import { AppManager } from './AppManager';
|
|
12
|
-
import { AppNameInput } from './AppNameInput';
|
|
13
|
-
import { usePluginUtils } from './utils';
|
|
14
|
-
|
|
15
|
-
const MultiAppManager = () => {
|
|
16
|
-
const { data, run } = useRequest<{
|
|
17
|
-
data: any[];
|
|
18
|
-
}>(
|
|
19
|
-
{
|
|
20
|
-
resource: 'applications',
|
|
21
|
-
action: 'listPinned',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
manual: true,
|
|
25
|
-
},
|
|
26
|
-
);
|
|
27
|
-
const { t } = usePluginUtils();
|
|
28
|
-
const items = [
|
|
29
|
-
...(data?.data || []).map((app) => {
|
|
30
|
-
let link = `/apps/${app.name}/admin/`;
|
|
31
|
-
if (app.options?.standaloneDeployment && app.cname) {
|
|
32
|
-
link = `//${app.cname}`;
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
key: app.name,
|
|
36
|
-
label: (
|
|
37
|
-
<a href={link} target="_blank" rel="noopener noreferrer">
|
|
38
|
-
{app.displayName || app.name}
|
|
39
|
-
</a>
|
|
40
|
-
),
|
|
41
|
-
};
|
|
42
|
-
}),
|
|
43
|
-
{
|
|
44
|
-
key: '.manager',
|
|
45
|
-
label: <Link to="/admin/settings/multi-app-manager/applications">{t('Manage applications')}</Link>,
|
|
46
|
-
},
|
|
47
|
-
];
|
|
48
|
-
return (
|
|
49
|
-
<Dropdown
|
|
50
|
-
onOpenChange={(visible) => {
|
|
51
|
-
run();
|
|
52
|
-
}}
|
|
53
|
-
menu={{ items }}
|
|
54
|
-
>
|
|
55
|
-
<Button title={'Apps'} icon={<Icon type={'AppstoreOutlined'} />} />
|
|
56
|
-
</Dropdown>
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
export const MultiAppManagerProvider = (props) => {
|
|
62
|
-
const { t } = usePluginUtils();
|
|
63
|
-
return (
|
|
64
|
-
<PinnedPluginListProvider
|
|
65
|
-
items={{
|
|
66
|
-
am: { order: 201, component: 'MultiAppManager', pin: true },
|
|
67
|
-
}}
|
|
68
|
-
>
|
|
69
|
-
<SchemaComponentOptions components={{ MultiAppManager, AppNameInput }}>
|
|
70
|
-
<SettingsCenterProvider
|
|
71
|
-
settings={{
|
|
72
|
-
'multi-app-manager': {
|
|
73
|
-
title: t('Multi-app manager'),
|
|
74
|
-
icon: 'AppstoreOutlined',
|
|
75
|
-
tabs: {
|
|
76
|
-
applications: {
|
|
77
|
-
title: t('Applications'),
|
|
78
|
-
component: () => <AppManager />,
|
|
79
|
-
},
|
|
80
|
-
// settings: {
|
|
81
|
-
// title: 'Settings',
|
|
82
|
-
// component: () => <Settings />,
|
|
83
|
-
// },
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
}}
|
|
87
|
-
>
|
|
88
|
-
{props.children}
|
|
89
|
-
</SettingsCenterProvider>
|
|
90
|
-
</SchemaComponentOptions>
|
|
91
|
-
</PinnedPluginListProvider>
|
|
92
|
-
);
|
|
93
|
-
};
|
package/src/client/Settings.tsx
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { SchemaComponent } from '@nocobase/client';
|
|
2
|
-
import { Card } from 'antd';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
|
|
5
|
-
const schema = {
|
|
6
|
-
type: 'object',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const Settings = () => {
|
|
10
|
-
return (
|
|
11
|
-
<Card bordered={false}>
|
|
12
|
-
<SchemaComponent schema={schema} />
|
|
13
|
-
</Card>
|
|
14
|
-
);
|
|
15
|
-
};
|
package/src/client/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '@nocobase/client';
|
|
2
|
-
import { MultiAppManagerProvider } from './MultiAppManagerProvider';
|
|
3
|
-
export { tableActionColumnSchema } from './settings/schemas/applications';
|
|
4
|
-
|
|
5
|
-
export class MultiAppManagerPlugin extends Plugin {
|
|
6
|
-
async load() {
|
|
7
|
-
this.app.use(MultiAppManagerProvider);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default MultiAppManagerPlugin;
|