@nocobase/server 0.7.6-alpha.2 → 0.8.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,18 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="koa-bodyparser" />
3
3
  import { ACL } from '@nocobase/acl';
4
+ import { Cache, ICacheConfig } from '@nocobase/cache';
4
5
  import Database, { Collection, CollectionOptions, IDatabaseOptions } from '@nocobase/database';
5
6
  import Resourcer, { ResourceOptions } from '@nocobase/resourcer';
6
- import { AsyncEmitter } from '@nocobase/utils';
7
+ import { AsyncEmitter, ToposortOptions } from '@nocobase/utils';
7
8
  import { Command, CommandOptions, ParseOptions } from 'commander';
8
9
  import { Server } from 'http';
9
10
  import { i18n, InitOptions } from 'i18next';
10
- import Koa from 'koa';
11
+ import Koa, { DefaultContext as KoaDefaultContext, DefaultState as KoaDefaultState } from 'koa';
11
12
  import { AppManager } from './app-manager';
12
13
  import { Plugin } from './plugin';
13
14
  import { InstallOptions, PluginManager } from './plugin-manager';
14
- import { ICacheConfig, Cache } from '@nocobase/cache';
15
15
  export declare type PluginConfiguration = string | [string, any];
16
- export declare type PluginsConfigurations = Array<PluginConfiguration>;
17
16
  export interface ResourcerOptions {
18
17
  prefix?: string;
19
18
  }
@@ -26,25 +25,21 @@ export interface ApplicationOptions {
26
25
  dataWrapping?: boolean;
27
26
  registerActions?: boolean;
28
27
  i18n?: i18n | InitOptions;
29
- plugins?: PluginsConfigurations;
28
+ plugins?: PluginConfiguration[];
29
+ acl?: boolean;
30
+ pmSock?: string;
30
31
  }
31
- export interface DefaultState {
32
+ export interface DefaultState extends KoaDefaultState {
32
33
  currentUser?: any;
33
34
  [key: string]: any;
34
35
  }
35
- export interface DefaultContext {
36
+ export interface DefaultContext extends KoaDefaultContext {
36
37
  db: Database;
37
38
  cache: Cache;
38
39
  resourcer: Resourcer;
40
+ i18n: any;
39
41
  [key: string]: any;
40
42
  }
41
- interface MiddlewareOptions {
42
- name?: string;
43
- resourceName?: string;
44
- resourceNames?: string[];
45
- insertBefore?: string;
46
- insertAfter?: string;
47
- }
48
43
  interface ActionsOptions {
49
44
  resourceName?: string;
50
45
  resourceNames?: string[];
@@ -65,6 +60,7 @@ interface ListenOptions {
65
60
  }
66
61
  interface StartOptions {
67
62
  cliArgs?: any[];
63
+ dbSync?: boolean;
68
64
  listen?: ListenOptions;
69
65
  }
70
66
  export declare class ApplicationVersion {
@@ -77,32 +73,44 @@ export declare class ApplicationVersion {
77
73
  }
78
74
  export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {
79
75
  options: ApplicationOptions;
80
- readonly db: Database;
81
- readonly cache: Cache;
82
- readonly resourcer: Resourcer;
83
- readonly cli: Command;
84
- readonly i18n: i18n;
85
- readonly pm: PluginManager;
86
- readonly acl: ACL;
87
- readonly appManager: AppManager;
88
- readonly version: ApplicationVersion;
76
+ protected _db: Database;
77
+ protected _resourcer: Resourcer;
78
+ protected _cache: Cache;
79
+ protected _cli: Command;
80
+ protected _i18n: i18n;
81
+ protected _pm: PluginManager;
82
+ protected _acl: ACL;
83
+ protected _appManager: AppManager;
84
+ protected _version: ApplicationVersion;
89
85
  protected plugins: Map<string, Plugin<any>>;
90
86
  listenServer: Server;
87
+ middleware: any;
91
88
  constructor(options: ApplicationOptions);
89
+ get db(): Database;
90
+ get cache(): Cache;
91
+ get resourcer(): Resourcer;
92
+ get cli(): Command;
93
+ get acl(): ACL;
94
+ get i18n(): i18n;
95
+ get pm(): PluginManager;
96
+ get version(): ApplicationVersion;
97
+ get appManager(): AppManager;
98
+ protected init(): void;
92
99
  private createDatabase;
93
100
  getVersion(): any;
94
- plugin<O = any>(pluginClass: any, options?: O): Plugin<O>;
95
- loadPluginConfig(pluginsConfigurations: PluginsConfigurations): void;
96
- use<NewStateT = {}, NewContextT = {}>(middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>, options?: MiddlewareOptions): Koa<Koa.DefaultState & StateT & NewStateT, Koa.DefaultContext & ContextT & NewContextT>;
101
+ plugin<O = any>(pluginClass: any, options?: O): Plugin;
102
+ use<NewStateT = {}, NewContextT = {}>(middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>, options?: ToposortOptions): this;
103
+ callback(): (req: any, res: any) => any;
97
104
  collection(options: CollectionOptions): Collection<any, any>;
98
105
  resource(options: ResourceOptions): import("@nocobase/resourcer").Resource;
99
106
  actions(handlers: any, options?: ActionsOptions): void;
100
107
  command(name: string, desc?: string, opts?: CommandOptions): Command;
101
108
  findCommand(name: string): Command;
102
- load(): Promise<void>;
109
+ load(options?: any): Promise<void>;
110
+ reload(options?: any): Promise<void>;
103
111
  getPlugin<P extends Plugin>(name: string): P;
104
112
  parse(argv?: string[]): Promise<Command>;
105
- runAsCLI(argv?: readonly string[], options?: ParseOptions): Promise<Command>;
113
+ runAsCLI(argv?: string[], options?: ParseOptions): Promise<Command>;
106
114
  start(options?: StartOptions): Promise<void>;
107
115
  listen(...args: any[]): Server;
108
116
  stop(options?: any): Promise<void>;
@@ -15,6 +15,16 @@ function _actions() {
15
15
  return data;
16
16
  }
17
17
 
18
+ function _cache() {
19
+ const data = require("@nocobase/cache");
20
+
21
+ _cache = function _cache() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
18
28
  function _database() {
19
29
  const data = _interopRequireDefault(require("@nocobase/database"));
20
30
 
@@ -55,10 +65,10 @@ function _koa() {
55
65
  return data;
56
66
  }
57
67
 
58
- function _lodash() {
59
- const data = require("lodash");
68
+ function _koaCompose() {
69
+ const data = _interopRequireDefault(require("koa-compose"));
60
70
 
61
- _lodash = function _lodash() {
71
+ _koaCompose = function _koaCompose() {
62
72
  return data;
63
73
  };
64
74
 
@@ -75,6 +85,16 @@ function _semver() {
75
85
  return data;
76
86
  }
77
87
 
88
+ function _util() {
89
+ const data = require("util");
90
+
91
+ _util = function _util() {
92
+ return data;
93
+ };
94
+
95
+ return data;
96
+ }
97
+
78
98
  var _acl = require("./acl");
79
99
 
80
100
  var _appManager = require("./app-manager");
@@ -85,24 +105,8 @@ var _helper = require("./helper");
85
105
 
86
106
  var _pluginManager = require("./plugin-manager");
87
107
 
88
- function _cache() {
89
- const data = require("@nocobase/cache");
90
-
91
- _cache = function _cache() {
92
- return data;
93
- };
94
-
95
- return data;
96
- }
97
-
98
108
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
99
109
 
100
- 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; } } }; }
101
-
102
- 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); }
103
-
104
- 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; }
105
-
106
110
  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; }
107
111
 
108
112
  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; }
@@ -191,51 +195,118 @@ class Application extends _koa().default {
191
195
  constructor(options) {
192
196
  super();
193
197
  this.options = void 0;
194
- this.db = void 0;
195
- this.cache = void 0;
196
- this.resourcer = void 0;
197
- this.cli = void 0;
198
- this.i18n = void 0;
199
- this.pm = void 0;
200
- this.acl = void 0;
201
- this.appManager = void 0;
202
- this.version = void 0;
198
+ this._db = void 0;
199
+ this._resourcer = void 0;
200
+ this._cache = void 0;
201
+ this._cli = void 0;
202
+ this._i18n = void 0;
203
+ this._pm = void 0;
204
+ this._acl = void 0;
205
+ this._appManager = void 0;
206
+ this._version = void 0;
203
207
  this.plugins = new Map();
204
208
  this.listenServer = void 0;
205
209
  this.options = options;
206
- this.acl = (0, _acl.createACL)();
207
- this.db = this.createDatabase(options);
208
- this.cache = (0, _cache().createCache)(options.cache);
209
- this.resourcer = (0, _helper.createResourcer)(options);
210
- this.cli = new (_commander().Command)('nocobase').usage('[command] [options]');
211
- this.i18n = (0, _helper.createI18n)(options);
212
- this.pm = new _pluginManager.PluginManager({
213
- app: this
214
- });
215
- this.appManager = new _appManager.AppManager(this);
210
+ this.init();
211
+ }
212
+
213
+ get db() {
214
+ return this._db;
215
+ }
216
+
217
+ get cache() {
218
+ return this._cache;
219
+ }
220
+
221
+ get resourcer() {
222
+ return this._resourcer;
223
+ }
224
+
225
+ get cli() {
226
+ return this._cli;
227
+ }
228
+
229
+ get acl() {
230
+ return this._acl;
231
+ }
232
+
233
+ get i18n() {
234
+ return this._i18n;
235
+ }
236
+
237
+ get pm() {
238
+ return this._pm;
239
+ }
240
+
241
+ get version() {
242
+ return this._version;
243
+ }
244
+
245
+ get appManager() {
246
+ return this._appManager;
247
+ }
248
+
249
+ init() {
250
+ const options = this.options; // @ts-ignore
251
+
252
+ this._events = []; // @ts-ignore
253
+
254
+ this._eventsCount = [];
255
+ this.removeAllListeners();
256
+ this.middleware = new (_utils().Toposort)();
257
+ this.plugins = new Map();
258
+ this._acl = (0, _acl.createACL)();
259
+
260
+ if (this._db) {
261
+ // MaxListenersExceededWarning
262
+ this._db.removeAllListeners();
263
+ }
264
+
265
+ this._db = this.createDatabase(options);
266
+ this._resourcer = (0, _helper.createResourcer)(options);
267
+ this._cli = new (_commander().Command)('nocobase').usage('[command] [options]');
268
+ this._i18n = (0, _helper.createI18n)(options);
269
+ this._cache = (0, _cache().createCache)(options.cache);
270
+ this.context.db = this._db;
271
+ this.context.resourcer = this._resourcer;
272
+ this.context.cache = this._cache;
273
+
274
+ if (this._pm) {
275
+ this._pm = this._pm.clone();
276
+ } else {
277
+ this._pm = new _pluginManager.PluginManager({
278
+ app: this,
279
+ plugins: options.plugins
280
+ });
281
+ }
282
+
283
+ this._appManager = new _appManager.AppManager(this);
284
+
285
+ if (this.options.acl !== false) {
286
+ this._resourcer.use(this._acl.middleware(), {
287
+ tag: 'acl',
288
+ after: ['parseToken']
289
+ });
290
+ }
291
+
216
292
  (0, _helper.registerMiddlewares)(this, options);
217
293
 
218
294
  if (options.registerActions !== false) {
219
295
  (0, _actions().registerActions)(this);
220
296
  }
221
297
 
222
- this.loadPluginConfig(options.plugins || []);
223
298
  (0, _commands.registerCli)(this);
224
- this.version = new ApplicationVersion(this);
299
+ this._version = new ApplicationVersion(this);
225
300
  }
226
301
 
227
302
  createDatabase(options) {
228
- if (options.database instanceof _database().default) {
229
- return options.database;
230
- } else {
231
- return new (_database().default)(_objectSpread(_objectSpread({}, options.database), {}, {
232
- migrator: {
233
- context: {
234
- app: this
235
- }
303
+ return new (_database().default)(_objectSpread(_objectSpread({}, options.database instanceof _database().default ? options.database.options : options.database), {}, {
304
+ migrator: {
305
+ context: {
306
+ app: this
236
307
  }
237
- }));
238
- }
308
+ }
309
+ }));
239
310
  }
240
311
 
241
312
  getVersion() {
@@ -243,36 +314,26 @@ class Application extends _koa().default {
243
314
  }
244
315
 
245
316
  plugin(pluginClass, options) {
246
- return this.pm.add(pluginClass, options);
247
- }
317
+ return this.pm.addStatic(pluginClass, options);
318
+ } // @ts-ignore
248
319
 
249
- loadPluginConfig(pluginsConfigurations) {
250
- var _iterator = _createForOfIteratorHelper(pluginsConfigurations),
251
- _step;
252
320
 
253
- try {
254
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
255
- let pluginConfiguration = _step.value;
321
+ use(middleware, options) {
322
+ this.middleware.add(middleware, options);
323
+ return this;
324
+ }
256
325
 
257
- if (typeof pluginConfiguration == 'string') {
258
- pluginConfiguration = [pluginConfiguration, {}];
259
- }
326
+ callback() {
327
+ const fn = (0, _koaCompose().default)(this.middleware.nodes);
328
+ if (!this.listenerCount('error')) this.on('error', this.onerror);
260
329
 
261
- const plugin = _pluginManager.PluginManager.resolvePlugin(pluginConfiguration[0]);
330
+ const handleRequest = (req, res) => {
331
+ const ctx = this.createContext(req, res); // @ts-ignore
262
332
 
263
- const pluginOptions = pluginConfiguration[1];
264
- this.plugin(plugin, pluginOptions);
265
- }
266
- } catch (err) {
267
- _iterator.e(err);
268
- } finally {
269
- _iterator.f();
270
- }
271
- }
333
+ return this.handleRequest(ctx, fn);
334
+ };
272
335
 
273
- use(middleware, options) {
274
- // @ts-ignore
275
- return super.use(middleware);
336
+ return handleRequest;
276
337
  }
277
338
 
278
339
  collection(options) {
@@ -295,11 +356,32 @@ class Application extends _koa().default {
295
356
  return this.cli._findCommand(name);
296
357
  }
297
358
 
298
- load() {
359
+ load(options) {
299
360
  var _this4 = this;
300
361
 
301
362
  return _asyncToGenerator(function* () {
302
- yield _this4.pm.load();
363
+ if (options === null || options === void 0 ? void 0 : options.reload) {
364
+ console.log(`Reload the application configuration`);
365
+ const oldDb = _this4._db;
366
+
367
+ _this4.init();
368
+
369
+ yield oldDb.close();
370
+ }
371
+
372
+ yield _this4.emitAsync('beforeLoad', _this4, options);
373
+ yield _this4.pm.load(options);
374
+ yield _this4.emitAsync('afterLoad', _this4, options);
375
+ })();
376
+ }
377
+
378
+ reload(options) {
379
+ var _this5 = this;
380
+
381
+ return _asyncToGenerator(function* () {
382
+ yield _this5.load(_objectSpread(_objectSpread({}, options), {}, {
383
+ reload: true
384
+ }));
303
385
  })();
304
386
  }
305
387
 
@@ -308,56 +390,68 @@ class Application extends _koa().default {
308
390
  }
309
391
 
310
392
  parse(argv = process.argv) {
311
- var _this5 = this;
393
+ var _this6 = this;
312
394
 
313
395
  return _asyncToGenerator(function* () {
314
- return _this5.runAsCLI(argv);
396
+ return _this6.runAsCLI(argv);
315
397
  })();
316
398
  }
317
399
 
318
- runAsCLI(argv, options) {
319
- var _this6 = this;
400
+ runAsCLI(argv = process.argv, options) {
401
+ var _this7 = this;
320
402
 
321
403
  return _asyncToGenerator(function* () {
322
- yield _this6.load();
323
- return _this6.cli.parseAsync(argv, options);
404
+ yield _this7.load({
405
+ method: argv === null || argv === void 0 ? void 0 : argv[2]
406
+ });
407
+ return _this7.cli.parseAsync(argv, options);
324
408
  })();
325
409
  }
326
410
 
327
411
  start(options = {}) {
328
- var _this7 = this;
412
+ var _this8 = this;
329
413
 
330
414
  return _asyncToGenerator(function* () {
331
415
  var _options$listen;
332
416
 
333
417
  // reconnect database
334
- if (_this7.db.closed()) {
335
- yield _this7.db.reconnect();
418
+ if (_this8.db.closed()) {
419
+ yield _this8.db.reconnect();
336
420
  }
337
421
 
338
- yield _this7.emitAsync('beforeStart', _this7, options);
422
+ if (options.dbSync) {
423
+ console.log('db sync...');
424
+ yield _this8.db.sync();
425
+ }
426
+
427
+ yield _this8.emitAsync('beforeStart', _this8, options);
339
428
 
340
429
  if (options === null || options === void 0 ? void 0 : (_options$listen = options.listen) === null || _options$listen === void 0 ? void 0 : _options$listen.port) {
430
+ const pmServer = yield _this8.pm.listen();
431
+
341
432
  const listen = () => new Promise((resolve, reject) => {
342
- const Server = _this7.listen(options === null || options === void 0 ? void 0 : options.listen, () => {
433
+ const Server = _this8.listen(options === null || options === void 0 ? void 0 : options.listen, () => {
343
434
  resolve(Server);
344
435
  });
345
436
 
346
437
  Server.on('error', err => {
347
438
  reject(err);
348
439
  });
440
+ Server.on('close', () => {
441
+ pmServer.close();
442
+ });
349
443
  });
350
444
 
351
445
  try {
352
446
  //@ts-ignore
353
- _this7.listenServer = yield listen();
447
+ _this8.listenServer = yield listen();
354
448
  } catch (e) {
355
449
  console.error(e);
356
450
  process.exit(1);
357
451
  }
358
452
  }
359
453
 
360
- yield _this7.emitAsync('afterStart', _this7, options);
454
+ yield _this8.emitAsync('afterStart', _this8, options);
361
455
  })();
362
456
  }
363
457
 
@@ -366,55 +460,48 @@ class Application extends _koa().default {
366
460
  }
367
461
 
368
462
  stop(options = {}) {
369
- var _this8 = this;
463
+ var _this9 = this;
370
464
 
371
465
  return _asyncToGenerator(function* () {
372
- yield _this8.emitAsync('beforeStop', _this8, options);
466
+ yield _this9.emitAsync('beforeStop', _this9, options);
373
467
 
374
468
  try {
375
469
  // close database connection
376
470
  // silent if database already closed
377
- yield _this8.db.close();
471
+ if (!_this9.db.closed()) {
472
+ yield _this9.db.close();
473
+ }
378
474
  } catch (e) {
379
475
  console.log(e);
380
476
  } // close http server
381
477
 
382
478
 
383
- if (_this8.listenServer) {
384
- const closeServer = () => new Promise((resolve, reject) => {
385
- _this8.listenServer.close(err => {
386
- if (err) {
387
- return reject(err);
388
- }
389
-
390
- _this8.listenServer = null;
391
- resolve(true);
392
- });
393
- });
394
-
395
- yield closeServer();
479
+ if (_this9.listenServer) {
480
+ yield (0, _util().promisify)(_this9.listenServer.close).call(_this9.listenServer);
481
+ _this9.listenServer = null;
396
482
  }
397
483
 
398
- yield _this8.emitAsync('afterStop', _this8, options);
484
+ yield _this9.emitAsync('afterStop', _this9, options);
399
485
  })();
400
486
  }
401
487
 
402
488
  destroy(options = {}) {
403
- var _this9 = this;
489
+ var _this10 = this;
404
490
 
405
491
  return _asyncToGenerator(function* () {
406
- yield _this9.emitAsync('beforeDestroy', _this9, options);
407
- yield _this9.stop(options);
408
- yield _this9.emitAsync('afterDestroy', _this9, options);
492
+ yield _this10.emitAsync('beforeDestroy', _this10, options);
493
+ yield _this10.stop(options);
494
+ yield _this10.emitAsync('afterDestroy', _this10, options);
409
495
  })();
410
496
  }
411
497
 
412
498
  install(options = {}) {
413
- var _this10 = this;
499
+ var _this11 = this;
414
500
 
415
501
  return _asyncToGenerator(function* () {
416
- yield _this10.emitAsync('beforeInstall', _this10, options);
417
- const r = yield _this10.db.version.satisfies({
502
+ var _options$sync;
503
+
504
+ const r = yield _this11.db.version.satisfies({
418
505
  mysql: '>=8.0.17',
419
506
  sqlite: '3.x',
420
507
  postgres: '>=10'
@@ -425,34 +512,41 @@ class Application extends _koa().default {
425
512
  return;
426
513
  }
427
514
 
428
- if (options === null || options === void 0 ? void 0 : options.clean) {
429
- yield _this10.db.clean((0, _lodash().isBoolean)(options.clean) ? {
430
- drop: options.clean
431
- } : options.clean);
515
+ console.log('Database dialect: ' + _this11.db.sequelize.getDialect());
516
+
517
+ if ((options === null || options === void 0 ? void 0 : options.clean) || (options === null || options === void 0 ? void 0 : (_options$sync = options.sync) === null || _options$sync === void 0 ? void 0 : _options$sync.force)) {
518
+ console.log('Truncate database and reload app configuration');
519
+ yield _this11.db.clean({
520
+ drop: true
521
+ });
522
+ yield _this11.reload({
523
+ method: 'install'
524
+ });
432
525
  }
433
526
 
434
- yield _this10.db.sync(options === null || options === void 0 ? void 0 : options.sync);
435
- yield _this10.pm.install(options);
436
- yield _this10.version.update();
437
- yield _this10.emitAsync('afterInstall', _this10, options);
527
+ yield _this11.emitAsync('beforeInstall', _this11, options);
528
+ yield _this11.db.sync();
529
+ yield _this11.pm.install(options);
530
+ yield _this11.version.update();
531
+ yield _this11.emitAsync('afterInstall', _this11, options);
438
532
  })();
439
533
  }
440
534
 
441
535
  upgrade(options = {}) {
442
- var _this11 = this;
536
+ var _this12 = this;
443
537
 
444
538
  return _asyncToGenerator(function* () {
445
- yield _this11.emitAsync('beforeUpgrade', _this11, options);
539
+ yield _this12.emitAsync('beforeUpgrade', _this12, options);
446
540
  const force = false;
447
- yield _this11.db.migrator.up();
448
- yield _this11.db.sync({
541
+ yield _this12.db.migrator.up();
542
+ yield _this12.db.sync({
449
543
  force,
450
544
  alter: {
451
545
  drop: force
452
546
  }
453
547
  });
454
- yield _this11.version.update();
455
- yield _this11.emitAsync('afterUpgrade', _this11, options);
548
+ yield _this12.version.update();
549
+ yield _this12.emitAsync('afterUpgrade', _this12, options);
456
550
  })();
457
551
  }
458
552
 
@@ -13,7 +13,6 @@ var _default = app => {
13
13
  app.command('db:sync').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
14
14
  const opts = cliArgs[0];
15
15
  console.log('db sync...');
16
- yield app.emitAsync('cli.beforeDbSync', ...cliArgs);
17
16
  const force = false;
18
17
  yield app.db.sync({
19
18
  force,
@@ -20,7 +20,9 @@ function registerCli(app) {
20
20
 
21
21
  require('./start').default(app);
22
22
 
23
- require('./upgrade').default(app); // development only with @nocobase/cli
23
+ require('./upgrade').default(app);
24
+
25
+ require('./pm').default(app); // development only with @nocobase/cli
24
26
 
25
27
 
26
28
  app.command('build').argument('[packages...]');
@@ -45,6 +45,8 @@ var _default = app => {
45
45
  let command = '$ yarn nocobase install -f';
46
46
  console.log(_chalk().default.yellow(command));
47
47
  console.log();
48
+ console.log(_chalk().default.red('This operation will clear the database!!!'));
49
+ console.log();
48
50
  }
49
51
 
50
52
  return;
@@ -0,0 +1,3 @@
1
+ import Application from '../application';
2
+ declare const _default: (app: Application) => void;
3
+ export default _default;