@nocobase/plugin-multi-app-manager 0.9.4-alpha.1 → 0.10.0-alpha.2

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.
@@ -1 +1,2 @@
1
- export declare const AppManager: () => JSX.Element;
1
+ import React from 'react';
2
+ export declare const AppManager: () => React.JSX.Element;
@@ -1 +1,2 @@
1
- export declare const Settings: () => JSX.Element;
1
+ import React from 'react';
2
+ export declare const Settings: () => React.JSX.Element;
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  export { tableActionColumnSchema } from './settings/schemas/applications';
2
- declare const _default: (props: any) => JSX.Element;
3
+ declare const _default: (props: any) => React.JSX.Element;
3
4
  export default _default;
@@ -44,7 +44,6 @@ var _utils = require("./utils");
44
44
  var _applications = require("./settings/schemas/applications");
45
45
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
46
46
  const MultiAppManager = () => {
47
- const history = (0, _reactRouterDom().useHistory)();
48
47
  const _useRequest = (0, _client().useRequest)({
49
48
  resource: 'applications',
50
49
  action: 'listPinned'
@@ -56,28 +55,33 @@ const MultiAppManager = () => {
56
55
  run = _useRequest.run;
57
56
  const _usePluginUtils = (0, _utils.usePluginUtils)(),
58
57
  t = _usePluginUtils.t;
59
- const menu = _react().default.createElement(_antd().Menu, null, ((data === null || data === void 0 ? void 0 : data.data) || []).map(app => {
58
+ const items = [...((data === null || data === void 0 ? void 0 : data.data) || []).map(app => {
60
59
  var _app$options;
61
60
  let link = `/apps/${app.name}/admin/`;
62
61
  if (((_app$options = app.options) === null || _app$options === void 0 ? void 0 : _app$options.standaloneDeployment) && app.cname) {
63
62
  link = `//${app.cname}`;
64
63
  }
65
- return _react().default.createElement(_antd().Menu.Item, {
64
+ return {
66
65
  key: app.name,
67
- onClick: () => {
68
- window.open(link, '_blank');
69
- }
70
- }, app.displayName || app.name);
71
- }), ((data === null || data === void 0 ? void 0 : data.data) || []).length > 0 && _react().default.createElement(_antd().Menu.Divider, null), _react().default.createElement(_antd().Menu.Item, {
72
- onClick: () => {
73
- history.push('/admin/settings/multi-app-manager/applications');
74
- }
75
- }, t('Manage applications')));
66
+ label: _react().default.createElement("a", {
67
+ href: link,
68
+ target: "_blank",
69
+ rel: "noopener noreferrer"
70
+ }, app.displayName || app.name)
71
+ };
72
+ }), {
73
+ key: '.manager',
74
+ label: _react().default.createElement(_reactRouterDom().Link, {
75
+ to: "/admin/settings/multi-app-manager/applications"
76
+ }, t('Manage applications'))
77
+ }];
76
78
  return _react().default.createElement(_antd().Dropdown, {
77
- onVisibleChange: visible => {
79
+ onOpenChange: visible => {
78
80
  run();
79
81
  },
80
- overlay: menu
82
+ menu: {
83
+ items
84
+ }
81
85
  }, _react().default.createElement(_antd().Button, {
82
86
  title: 'Apps',
83
87
  icon: _react().default.createElement(_client().Icon, {
@@ -6,5 +6,7 @@ declare const _default: {
6
6
  'Pin to menu': string;
7
7
  'Custom domain': string;
8
8
  'Manage applications': string;
9
+ 'Standalone deployment': string;
10
+ 'Auto start': string;
9
11
  };
10
12
  export default _default;
@@ -11,6 +11,8 @@ var _default = {
11
11
  'App ID': '应用标识',
12
12
  'Pin to menu': '在菜单上显示',
13
13
  'Custom domain': '自定义域名',
14
- 'Manage applications': '管理应用'
14
+ 'Manage applications': '管理应用',
15
+ 'Standalone deployment': '独立部署',
16
+ 'Auto start': '自动启动'
15
17
  };
16
18
  exports.default = _default;
@@ -40,6 +40,11 @@ export declare const tableActionColumnSchema: {
40
40
  'x-decorator': string;
41
41
  'x-content': string;
42
42
  };
43
+ 'options.autoStart': {
44
+ 'x-component': string;
45
+ 'x-decorator': string;
46
+ 'x-content': string;
47
+ };
43
48
  cname: {
44
49
  title: string;
45
50
  'x-component': string;
@@ -155,7 +155,12 @@ const tableActionColumnSchema = {
155
155
  'options.standaloneDeployment': {
156
156
  'x-component': 'Checkbox',
157
157
  'x-decorator': 'FormItem',
158
- 'x-content': '{{t("Standalone deployment")}}'
158
+ 'x-content': (0, _utils.i18nText)('Standalone deployment')
159
+ },
160
+ 'options.autoStart': {
161
+ 'x-component': 'Checkbox',
162
+ 'x-decorator': 'FormItem',
163
+ 'x-content': (0, _utils.i18nText)('Auto start')
159
164
  },
160
165
  cname: {
161
166
  title: (0, _utils.i18nText)('Custom domain'),
@@ -288,7 +293,12 @@ const schema = {
288
293
  'options.standaloneDeployment': {
289
294
  'x-component': 'Checkbox',
290
295
  'x-decorator': 'FormItem',
291
- 'x-content': '{{t("Standalone deployment")}}'
296
+ 'x-content': (0, _utils.i18nText)('Standalone deployment')
297
+ },
298
+ 'options.autoStart': {
299
+ 'x-component': 'Checkbox',
300
+ 'x-decorator': 'FormItem',
301
+ 'x-content': (0, _utils.i18nText)('Auto start')
292
302
  },
293
303
  cname: {
294
304
  title: (0, _utils.i18nText)('Custom domain'),
@@ -5,6 +5,7 @@ export declare type AppOptionsFactory = (appName: string, mainApp: Application)
5
5
  export declare class PluginMultiAppManager extends Plugin {
6
6
  appDbCreator: AppDbCreator;
7
7
  appOptionsFactory: AppOptionsFactory;
8
+ private beforeGetApplicationMutex;
8
9
  setAppOptionsFactory(factory: AppOptionsFactory): void;
9
10
  setAppDbCreator(appDbCreator: AppDbCreator): void;
10
11
  static getDatabaseConfig(app: Application): IDatabaseOptions;
@@ -33,6 +33,13 @@ function path() {
33
33
  return data;
34
34
  }
35
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
+ }
36
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); }
37
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; }
38
45
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -113,6 +120,7 @@ class PluginMultiAppManager extends _server().Plugin {
113
120
  super(...args);
114
121
  this.appDbCreator = defaultDbCreator;
115
122
  this.appOptionsFactory = defaultAppOptionsFactory;
123
+ this.beforeGetApplicationMutex = new (_asyncMutex().Mutex)();
116
124
  }
117
125
  setAppOptionsFactory(factory) {
118
126
  this.appOptionsFactory = factory;
@@ -197,36 +205,88 @@ class PluginMultiAppManager extends _server().Plugin {
197
205
  name,
198
206
  options
199
207
  }) {
200
- if (appManager.applications.has(name)) {
201
- return;
202
- }
203
- const applicationRecord = yield _this.app.db.getRepository('applications').findOne({
204
- filter: {
205
- name
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 ? 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 ? 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);
206
256
  }
207
- });
208
- const instanceOptions = applicationRecord.get('options');
209
- // skip standalone deployment application
210
- if ((instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.standaloneDeployment) && appManager.runningMode !== 'single') {
211
- return;
212
- }
213
- if (!applicationRecord) {
214
257
  return;
215
258
  }
216
- const subApp = yield applicationRecord.registerToMainApp(_this.app, {
217
- appOptionsFactory: _this.appOptionsFactory
218
- });
219
- // must skip load on upgrade
220
- if (!(options === null || options === void 0 ? void 0 : options.upgrading)) {
221
- yield subApp.load();
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);
222
282
  }
223
283
  });
224
- return function (_x6) {
225
- return _ref5.apply(this, arguments);
284
+ return function (_x7) {
285
+ return _ref7.apply(this, arguments);
226
286
  };
227
287
  }());
228
288
  _this.app.on('afterUpgrade', /*#__PURE__*/function () {
229
- var _ref6 = _asyncToGenerator(function* (app, options) {
289
+ var _ref8 = _asyncToGenerator(function* (app, options) {
230
290
  const cliArgs = options === null || options === void 0 ? void 0 : options.cliArgs;
231
291
  const repository = _this.db.getRepository('applications');
232
292
  const findOptions = {};
@@ -237,11 +297,11 @@ class PluginMultiAppManager extends _server().Plugin {
237
297
  };
238
298
  }
239
299
  const instances = yield repository.find(findOptions);
240
- var _iterator = _createForOfIteratorHelper(instances),
241
- _step;
300
+ var _iterator2 = _createForOfIteratorHelper(instances),
301
+ _step2;
242
302
  try {
243
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
244
- const instance = _step.value;
303
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
304
+ const instance = _step2.value;
245
305
  const instanceOptions = instance.get('options');
246
306
  // skip standalone deployment application
247
307
  if ((instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.standaloneDeployment) && appManager.runningMode !== 'single') {
@@ -265,13 +325,13 @@ class PluginMultiAppManager extends _server().Plugin {
265
325
  }
266
326
  }
267
327
  } catch (err) {
268
- _iterator.e(err);
328
+ _iterator2.e(err);
269
329
  } finally {
270
- _iterator.f();
330
+ _iterator2.f();
271
331
  }
272
332
  });
273
- return function (_x7, _x8) {
274
- return _ref6.apply(this, arguments);
333
+ return function (_x8, _x9) {
334
+ return _ref8.apply(this, arguments);
275
335
  };
276
336
  }());
277
337
  _this.app.resourcer.registerActionHandlers({
@@ -284,7 +344,7 @@ class PluginMultiAppManager extends _server().Plugin {
284
344
  });
285
345
  ctx.body = items;
286
346
  });
287
- function applicationsListPinned(_x9, _x10) {
347
+ function applicationsListPinned(_x10, _x11) {
288
348
  return _applicationsListPinned.apply(this, arguments);
289
349
  }
290
350
  return applicationsListPinned;
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-multi-app-manager",
3
- "version": "0.9.4-alpha.1",
4
- "description": "",
3
+ "displayName": "multi app manager",
4
+ "displayName.zh-CN": "多应用管理",
5
+ "description": "manage app",
6
+ "description.zh-CN": "管理应用",
7
+ "version": "0.10.0-alpha.2",
5
8
  "license": "AGPL-3.0",
6
9
  "main": "./lib/index.js",
7
10
  "types": "./lib/index.d.ts",
8
11
  "dependencies": {
9
- "@nocobase/server": "0.9.4-alpha.1"
12
+ "@nocobase/server": "0.10.0-alpha.2",
13
+ "async-mutex": "^0.3.2"
10
14
  },
11
- "gitHead": "0b4936be557be918dbdf8196dadcbc7eb395906d"
15
+ "gitHead": "85028ae1733fcbd46ecd5d291dacbdc175f7f073"
12
16
  }