@nocobase/server 0.8.0-alpha.9 → 0.8.1-alpha.3

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.
@@ -3,6 +3,7 @@
3
3
  import { ACL } from '@nocobase/acl';
4
4
  import { Cache, ICacheConfig } from '@nocobase/cache';
5
5
  import Database, { Collection, CollectionOptions, IDatabaseOptions } from '@nocobase/database';
6
+ import { AppLoggerOptions, Logger } from '@nocobase/logger';
6
7
  import Resourcer, { ResourceOptions } from '@nocobase/resourcer';
7
8
  import { AsyncEmitter, ToposortOptions } from '@nocobase/utils';
8
9
  import { Command, CommandOptions, ParseOptions } from 'commander';
@@ -27,6 +28,7 @@ export interface ApplicationOptions {
27
28
  i18n?: i18n | InitOptions;
28
29
  plugins?: PluginConfiguration[];
29
30
  acl?: boolean;
31
+ logger?: AppLoggerOptions;
30
32
  pmSock?: string;
31
33
  }
32
34
  export interface DefaultState extends KoaDefaultState {
@@ -60,6 +62,7 @@ interface ListenOptions {
60
62
  }
61
63
  interface StartOptions {
62
64
  cliArgs?: any[];
65
+ dbSync?: boolean;
63
66
  listen?: ListenOptions;
64
67
  }
65
68
  export declare class ApplicationVersion {
@@ -73,6 +76,7 @@ export declare class ApplicationVersion {
73
76
  export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {
74
77
  options: ApplicationOptions;
75
78
  protected _db: Database;
79
+ protected _logger: Logger;
76
80
  protected _resourcer: Resourcer;
77
81
  protected _cache: Cache;
78
82
  protected _cli: Command;
@@ -94,6 +98,8 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
94
98
  get pm(): PluginManager;
95
99
  get version(): ApplicationVersion;
96
100
  get appManager(): AppManager;
101
+ get logger(): Logger;
102
+ get log(): Logger;
97
103
  protected init(): void;
98
104
  private createDatabase;
99
105
  getVersion(): any;
@@ -114,6 +120,10 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
114
120
  listen(...args: any[]): Server;
115
121
  stop(options?: any): Promise<void>;
116
122
  destroy(options?: any): Promise<void>;
123
+ dbVersionCheck(options?: {
124
+ exit?: boolean;
125
+ }): Promise<boolean>;
126
+ isInstalled(): Promise<boolean>;
117
127
  install(options?: InstallOptions): Promise<void>;
118
128
  upgrade(options?: any): Promise<void>;
119
129
  emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
@@ -35,6 +35,16 @@ function _database() {
35
35
  return data;
36
36
  }
37
37
 
38
+ function _logger() {
39
+ const data = require("@nocobase/logger");
40
+
41
+ _logger = function _logger() {
42
+ return data;
43
+ };
44
+
45
+ return data;
46
+ }
47
+
38
48
  function _utils() {
39
49
  const data = require("@nocobase/utils");
40
50
 
@@ -45,6 +55,16 @@ function _utils() {
45
55
  return data;
46
56
  }
47
57
 
58
+ function _chalk() {
59
+ const data = _interopRequireDefault(require("chalk"));
60
+
61
+ _chalk = function _chalk() {
62
+ return data;
63
+ };
64
+
65
+ return data;
66
+ }
67
+
48
68
  function _commander() {
49
69
  const data = require("commander");
50
70
 
@@ -75,16 +95,6 @@ function _koaCompose() {
75
95
  return data;
76
96
  }
77
97
 
78
- function _lodash() {
79
- const data = require("lodash");
80
-
81
- _lodash = function _lodash() {
82
- return data;
83
- };
84
-
85
- return data;
86
- }
87
-
88
98
  function _semver() {
89
99
  const data = _interopRequireDefault(require("semver"));
90
100
 
@@ -155,6 +165,11 @@ class ApplicationVersion {
155
165
  return _asyncToGenerator(function* () {
156
166
  if (yield _this.app.db.collectionExistsInDb('applicationVersion')) {
157
167
  const model = yield _this.collection.model.findOne();
168
+
169
+ if (!model) {
170
+ return null;
171
+ }
172
+
158
173
  return model.get('value');
159
174
  }
160
175
 
@@ -206,6 +221,7 @@ class Application extends _koa().default {
206
221
  super();
207
222
  this.options = void 0;
208
223
  this._db = void 0;
224
+ this._logger = void 0;
209
225
  this._resourcer = void 0;
210
226
  this._cache = void 0;
211
227
  this._cli = void 0;
@@ -256,8 +272,18 @@ class Application extends _koa().default {
256
272
  return this._appManager;
257
273
  }
258
274
 
275
+ get logger() {
276
+ return this._logger;
277
+ }
278
+
279
+ get log() {
280
+ return this._logger;
281
+ }
282
+
259
283
  init() {
260
- const options = this.options; // @ts-ignore
284
+ const options = this.options;
285
+ const logger = (0, _logger().createAppLogger)(options.logger);
286
+ this._logger = logger.instance; // @ts-ignore
261
287
 
262
288
  this._events = []; // @ts-ignore
263
289
 
@@ -266,6 +292,9 @@ class Application extends _koa().default {
266
292
  this.middleware = new (_utils().Toposort)();
267
293
  this.plugins = new Map();
268
294
  this._acl = (0, _acl.createACL)();
295
+ this.use(logger.middleware, {
296
+ tag: 'logger'
297
+ });
269
298
 
270
299
  if (this._db) {
271
300
  // MaxListenersExceededWarning
@@ -278,6 +307,7 @@ class Application extends _koa().default {
278
307
  this._i18n = (0, _helper.createI18n)(options);
279
308
  this._cache = (0, _cache().createCache)(options.cache);
280
309
  this.context.db = this._db;
310
+ this.context.logger = this._logger;
281
311
  this.context.resourcer = this._resourcer;
282
312
  this.context.cache = this._cache;
283
313
 
@@ -371,6 +401,7 @@ class Application extends _koa().default {
371
401
 
372
402
  return _asyncToGenerator(function* () {
373
403
  if (options === null || options === void 0 ? void 0 : options.reload) {
404
+ console.log(`Reload the application configuration`);
374
405
  const oldDb = _this4._db;
375
406
 
376
407
  _this4.init();
@@ -410,9 +441,25 @@ class Application extends _koa().default {
410
441
  var _this7 = this;
411
442
 
412
443
  return _asyncToGenerator(function* () {
413
- yield _this7.load({
414
- method: argv === null || argv === void 0 ? void 0 : argv[2]
444
+ try {
445
+ yield _this7.db.auth({
446
+ retry: 30
447
+ });
448
+ } catch (error) {
449
+ console.log(_chalk().default.red(error.message));
450
+ process.exit(1);
451
+ }
452
+
453
+ yield _this7.dbVersionCheck({
454
+ exit: true
415
455
  });
456
+
457
+ if ((argv === null || argv === void 0 ? void 0 : argv[2]) !== 'upgrade') {
458
+ yield _this7.load({
459
+ method: argv === null || argv === void 0 ? void 0 : argv[2]
460
+ });
461
+ }
462
+
416
463
  return _this7.cli.parseAsync(argv, options);
417
464
  })();
418
465
  }
@@ -428,6 +475,11 @@ class Application extends _koa().default {
428
475
  yield _this8.db.reconnect();
429
476
  }
430
477
 
478
+ if (options.dbSync) {
479
+ console.log('db sync...');
480
+ yield _this8.db.sync();
481
+ }
482
+
431
483
  yield _this8.emitAsync('beforeStart', _this8, options);
432
484
 
433
485
  if (options === null || options === void 0 ? void 0 : (_options$listen = options.listen) === null || _options$listen === void 0 ? void 0 : _options$listen.port) {
@@ -499,7 +551,7 @@ class Application extends _koa().default {
499
551
  })();
500
552
  }
501
553
 
502
- install(options = {}) {
554
+ dbVersionCheck(options) {
503
555
  var _this11 = this;
504
556
 
505
557
  return _asyncToGenerator(function* () {
@@ -510,42 +562,84 @@ class Application extends _koa().default {
510
562
  });
511
563
 
512
564
  if (!r) {
513
- console.log('The database only supports MySQL 8.0.17 and above, SQLite 3.x and PostgreSQL 10+');
514
- return;
565
+ console.log(_chalk().default.red('The database only supports MySQL 8.0.17 and above, SQLite 3.x and PostgreSQL 10+'));
566
+
567
+ if (options === null || options === void 0 ? void 0 : options.exit) {
568
+ process.exit();
569
+ }
570
+
571
+ return false;
515
572
  }
516
573
 
517
- if (options === null || options === void 0 ? void 0 : options.clean) {
518
- yield _this11.db.clean((0, _lodash().isBoolean)(options.clean) ? {
519
- drop: options.clean
520
- } : options.clean);
521
- yield _this11.reload({
574
+ if (_this11.db.inDialect('mysql')) {
575
+ const result = yield _this11.db.sequelize.query(`SHOW VARIABLES LIKE 'lower_case_table_names'`, {
576
+ plain: true
577
+ });
578
+
579
+ if ((result === null || result === void 0 ? void 0 : result.Value) === '1') {
580
+ console.log(_chalk().default.red(`mysql variable 'lower_case_table_names' must be set to '0' or '2'`));
581
+
582
+ if (options === null || options === void 0 ? void 0 : options.exit) {
583
+ process.exit();
584
+ }
585
+
586
+ return false;
587
+ }
588
+ }
589
+
590
+ return true;
591
+ })();
592
+ }
593
+
594
+ isInstalled() {
595
+ var _this12 = this;
596
+
597
+ return _asyncToGenerator(function* () {
598
+ return (yield _this12.db.collectionExistsInDb('applicationVersion')) || (yield _this12.db.collectionExistsInDb('collections'));
599
+ })();
600
+ }
601
+
602
+ install(options = {}) {
603
+ var _this13 = this;
604
+
605
+ return _asyncToGenerator(function* () {
606
+ var _options$sync;
607
+
608
+ console.log('Database dialect: ' + _this13.db.sequelize.getDialect());
609
+
610
+ 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)) {
611
+ console.log('Truncate database and reload app configuration');
612
+ yield _this13.db.clean({
613
+ drop: true
614
+ });
615
+ yield _this13.reload({
522
616
  method: 'install'
523
617
  });
524
618
  }
525
619
 
526
- yield _this11.emitAsync('beforeInstall', _this11, options);
527
- yield _this11.db.sync(options === null || options === void 0 ? void 0 : options.sync);
528
- yield _this11.pm.install(options);
529
- yield _this11.version.update();
530
- yield _this11.emitAsync('afterInstall', _this11, options);
620
+ yield _this13.emitAsync('beforeInstall', _this13, options);
621
+ yield _this13.db.sync();
622
+ yield _this13.pm.install(options);
623
+ yield _this13.version.update();
624
+ yield _this13.emitAsync('afterInstall', _this13, options);
531
625
  })();
532
626
  }
533
627
 
534
628
  upgrade(options = {}) {
535
- var _this12 = this;
629
+ var _this14 = this;
536
630
 
537
631
  return _asyncToGenerator(function* () {
538
- yield _this12.emitAsync('beforeUpgrade', _this12, options);
632
+ yield _this14.emitAsync('beforeUpgrade', _this14, options);
539
633
  const force = false;
540
- yield _this12.db.migrator.up();
541
- yield _this12.db.sync({
634
+ yield _this14.db.migrator.up();
635
+ yield _this14.db.sync({
542
636
  force,
543
637
  alter: {
544
638
  drop: force
545
639
  }
546
640
  });
547
- yield _this12.version.update();
548
- yield _this12.emitAsync('afterUpgrade', _this12, options);
641
+ yield _this14.version.update();
642
+ yield _this14.emitAsync('afterUpgrade', _this14, options);
549
643
  })();
550
644
  }
551
645
 
@@ -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,
@@ -22,21 +22,19 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
22
22
  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); }); }; }
23
23
 
24
24
  var _default = app => {
25
- app.command('install').option('-f, --force').option('-c, --clean').option('-s, --silent').option('-r, --retry [retry]').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
25
+ app.command('install').option('-f, --force').option('-c, --clean').option('-s, --silent').option('-r, --retry [retry]').option('-I, --ignore-installed').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
26
26
  let installed = false;
27
27
  const opts = cliArgs[0];
28
28
 
29
- try {
30
- yield app.db.auth({
31
- retry: opts.retry || 1
32
- });
33
- } catch (error) {
34
- console.log(_chalk().default.red('Unable to connect to the database. Please check the database environment variables in the .env file.'));
35
- return;
29
+ if (opts.ignoreInstalled) {
30
+ if (yield app.isInstalled()) {
31
+ console.log('Application installed');
32
+ return;
33
+ }
36
34
  }
37
35
 
38
36
  if (!(opts === null || opts === void 0 ? void 0 : opts.clean) && !(opts === null || opts === void 0 ? void 0 : opts.force)) {
39
- if ((yield app.db.collectionExistsInDb('applicationVersion')) || (yield app.db.collectionExistsInDb('collections'))) {
37
+ if (yield app.isInstalled()) {
40
38
  installed = true;
41
39
 
42
40
  if (!opts.silent) {
@@ -45,6 +43,8 @@ var _default = app => {
45
43
  let command = '$ yarn nocobase install -f';
46
44
  console.log(_chalk().default.yellow(command));
47
45
  console.log();
46
+ console.log(_chalk().default.red('This operation will clear the database!!!'));
47
+ console.log();
48
48
  }
49
49
 
50
50
  return;
@@ -12,6 +12,14 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
12
12
  var _default = app => {
13
13
  app.command('pm').argument('<method>').arguments('<plugins...>').action( /*#__PURE__*/function () {
14
14
  var _ref = _asyncToGenerator(function* (method, plugins, options, ...args) {
15
+ if (method === 'add') {
16
+ const _require = require('@nocobase/cli/src/util'),
17
+ run = _require.run;
18
+
19
+ console.log('Install dependencies and rebuild workspaces');
20
+ yield run('yarn', ['install']);
21
+ }
22
+
15
23
  app.pm.clientWrite({
16
24
  method,
17
25
  plugins
@@ -10,11 +10,12 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
10
10
  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); }); }; }
11
11
 
12
12
  var _default = app => {
13
- app.command('start').option('-s, --silent').option('-p, --port [post]').option('-h, --host [host]').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
13
+ app.command('start').option('-s, --silent').option('-p, --port [post]').option('-h, --host [host]').option('--db-sync').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
14
14
  const opts = cliArgs[0];
15
15
  const port = opts.port || process.env.APP_PORT || 13000;
16
16
  const host = opts.host || process.env.APP_HOST || '0.0.0.0';
17
17
  yield app.start({
18
+ dbSync: opts === null || opts === void 0 ? void 0 : opts.dbSync,
18
19
  cliArgs,
19
20
  listen: {
20
21
  port,
package/lib/helper.js CHANGED
@@ -108,14 +108,16 @@ function registerMiddlewares(app, options) {
108
108
 
109
109
  if (options.bodyParser !== false) {
110
110
  app.use((0, _koaBodyparser().default)(_objectSpread({}, options.bodyParser)), {
111
- tag: 'bodyParser'
111
+ tag: 'bodyParser',
112
+ after: 'logger'
112
113
  });
113
114
  }
114
115
 
115
116
  app.use( /*#__PURE__*/function () {
116
117
  var _ref = _asyncToGenerator(function* (ctx, next) {
117
118
  ctx.getBearerToken = () => {
118
- return ctx.get('Authorization').replace(/^Bearer\s+/gi, '');
119
+ const token = ctx.get('Authorization').replace(/^Bearer\s+/gi, '');
120
+ return token || ctx.query.token;
119
121
  };
120
122
 
121
123
  yield next();
@@ -78,6 +78,10 @@ function dataWrapping() {
78
78
  data: ctx.body
79
79
  };
80
80
  }
81
+ } else if (ctx.action) {
82
+ ctx.body = {
83
+ data: ctx.body
84
+ };
81
85
  }
82
86
  });
83
87
 
@@ -25,6 +25,7 @@ export declare class PluginManager {
25
25
  addStaticMultiple(plugins: any): void;
26
26
  getPlugins(): Map<string, Plugin<any>>;
27
27
  get(name: string): Plugin<any>;
28
+ has(name: string): boolean;
28
29
  clientWrite(data: any): void;
29
30
  listen(): Promise<net.Server>;
30
31
  create(name: string | string[]): Promise<void>;
@@ -37,6 +38,7 @@ export declare class PluginManager {
37
38
  disable(name: string | string[]): Promise<void>;
38
39
  remove(name: string | string[]): Promise<void>;
39
40
  static getPackageName(name: string): string;
41
+ static getPluginPkgPrefix(): string[];
40
42
  static findPackage(name: string): Promise<string>;
41
43
  static resolvePlugin(pluginName: string): any;
42
44
  }
@@ -125,6 +125,7 @@ class PluginManager {
125
125
  this.repository.setPluginManager(this);
126
126
  this.app.resourcer.define(_resource.default);
127
127
  this.app.acl.allow('pm', ['enable', 'disable', 'remove'], 'allowConfigure');
128
+ this.app.acl.allow('applicationPlugins', 'list', 'allowConfigure');
128
129
  this.server = _net().default.createServer(socket => {
129
130
  socket.on('data', /*#__PURE__*/function () {
130
131
  var _ref = _asyncToGenerator(function* (data) {
@@ -167,6 +168,9 @@ class PluginManager {
167
168
  return _ref2.apply(this, arguments);
168
169
  };
169
170
  }());
171
+ this.app.on('beforeUpgrade', /*#__PURE__*/_asyncToGenerator(function* () {
172
+ yield _this.collection.sync();
173
+ }));
170
174
  this.addStaticMultiple(options.plugins);
171
175
  }
172
176
 
@@ -199,6 +203,10 @@ class PluginManager {
199
203
  return this.plugins.get(name);
200
204
  }
201
205
 
206
+ has(name) {
207
+ return this.plugins.has(name);
208
+ }
209
+
202
210
  clientWrite(data) {
203
211
  var _this2 = this;
204
212
 
@@ -256,7 +264,7 @@ class PluginManager {
256
264
  run = _require.run;
257
265
 
258
266
  const createPlugin = /*#__PURE__*/function () {
259
- var _ref4 = _asyncToGenerator(function* (name) {
267
+ var _ref5 = _asyncToGenerator(function* (name) {
260
268
  const _require2 = require('@nocobase/cli/src/plugin-generator'),
261
269
  PluginGenerator = _require2.PluginGenerator;
262
270
 
@@ -271,7 +279,7 @@ class PluginManager {
271
279
  });
272
280
 
273
281
  return function createPlugin(_x4) {
274
- return _ref4.apply(this, arguments);
282
+ return _ref5.apply(this, arguments);
275
283
  };
276
284
  }();
277
285
 
@@ -327,7 +335,7 @@ class PluginManager {
327
335
  const pluginName = instance.getName();
328
336
 
329
337
  if (this.plugins.has(pluginName)) {
330
- throw new Error(`plugin name [${pluginName}] exists`);
338
+ throw new Error(`plugin name [${pluginName}] already exists`);
331
339
  }
332
340
 
333
341
  this.plugins.set(pluginName, instance);
@@ -349,8 +357,7 @@ class PluginManager {
349
357
  yield t.rollback();
350
358
  throw error;
351
359
  }
352
- } // console.log(`adding ${plugin} plugin`);
353
-
360
+ }
354
361
 
355
362
  const packageName = yield PluginManager.findPackage(plugin);
356
363
 
@@ -367,26 +374,25 @@ class PluginManager {
367
374
  }
368
375
  });
369
376
 
370
- if (model) {
371
- throw new Error(`${plugin} plugin already exists`);
377
+ if (!model) {
378
+ const enabled = options.enabled,
379
+ builtIn = options.builtIn,
380
+ installed = options.installed,
381
+ others = _objectWithoutProperties(options, _excluded);
382
+
383
+ model = yield _this4.repository.create({
384
+ transaction,
385
+ values: {
386
+ name: plugin,
387
+ version: packageJson.version,
388
+ enabled: !!enabled,
389
+ builtIn: !!builtIn,
390
+ installed: !!installed,
391
+ options: _objectSpread({}, others)
392
+ }
393
+ });
372
394
  }
373
395
 
374
- const enabled = options.enabled,
375
- builtIn = options.builtIn,
376
- installed = options.installed,
377
- others = _objectWithoutProperties(options, _excluded);
378
-
379
- yield _this4.repository.create({
380
- transaction,
381
- values: {
382
- name: plugin,
383
- version: packageJson.version,
384
- enabled: !!enabled,
385
- builtIn: !!builtIn,
386
- installed: !!installed,
387
- options: _objectSpread({}, others)
388
- }
389
- });
390
396
  const file = (0, _path().resolve)(process.cwd(), 'packages', process.env.APP_PACKAGE_ROOT || 'app', 'client/src/plugins', `${plugin}.ts`);
391
397
 
392
398
  if (!_fs().default.existsSync(file)) {
@@ -589,7 +595,7 @@ class PluginManager {
589
595
  }
590
596
 
591
597
  static getPackageName(name) {
592
- const prefixes = (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-').split(',');
598
+ const prefixes = this.getPluginPkgPrefix();
593
599
 
594
600
  var _iterator9 = _createForOfIteratorHelper(prefixes),
595
601
  _step9;
@@ -615,6 +621,10 @@ class PluginManager {
615
621
  throw new Error(`${name} plugin does not exist`);
616
622
  }
617
623
 
624
+ static getPluginPkgPrefix() {
625
+ return (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-').split(',');
626
+ }
627
+
618
628
  static findPackage(name) {
619
629
  var _this10 = this;
620
630
 
@@ -624,7 +634,9 @@ class PluginManager {
624
634
 
625
635
  return packageName;
626
636
  } catch (error) {
627
- const prefixes = (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-').split(',');
637
+ console.log(`\`${name}\` plugin not found locally`);
638
+
639
+ const prefixes = _this10.getPluginPkgPrefix();
628
640
 
629
641
  var _iterator10 = _createForOfIteratorHelper(prefixes),
630
642
  _step10;
@@ -635,9 +647,11 @@ class PluginManager {
635
647
 
636
648
  try {
637
649
  const packageName = `${prefix}${name}`;
650
+ console.log(`Try to find ${packageName}`);
638
651
  yield (0, _execa().default)('npm', ['v', packageName, 'versions']);
639
- console.log(`${packageName} is downloading...`);
652
+ console.log(`${packageName} downloading`);
640
653
  yield (0, _execa().default)('yarn', ['add', packageName, '-W']);
654
+ console.log(`${packageName} downloaded`);
641
655
  return packageName;
642
656
  } catch (error) {
643
657
  continue;
@@ -650,7 +664,7 @@ class PluginManager {
650
664
  }
651
665
  }
652
666
 
653
- throw new Error(`${name} plugin does not exist`);
667
+ throw new Error(`No available packages found, ${name} plugin does not exist`);
654
668
  })();
655
669
  }
656
670
 
package/lib/plugin.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { Database } from '@nocobase/database';
2
1
  import { Application } from './application';
3
2
  import { InstallOptions } from './plugin-manager';
4
3
  export interface PluginInterface {
@@ -21,8 +20,8 @@ export declare type PluginType = typeof Plugin;
21
20
  export declare abstract class Plugin<O = any> implements PluginInterface {
22
21
  options: any;
23
22
  app: Application;
24
- db: Database;
25
23
  constructor(app: Application, options?: any);
24
+ get db(): import("@nocobase/database").default;
26
25
  get enabled(): any;
27
26
  set enabled(value: any);
28
27
  setOptions(options: any): void;
package/lib/plugin.js CHANGED
@@ -13,13 +13,15 @@ class Plugin {
13
13
  constructor(app, options) {
14
14
  this.options = void 0;
15
15
  this.app = void 0;
16
- this.db = void 0;
17
16
  this.app = app;
18
- this.db = app.db;
19
17
  this.setOptions(options);
20
18
  this.afterAdd();
21
19
  }
22
20
 
21
+ get db() {
22
+ return this.app.db;
23
+ }
24
+
23
25
  get enabled() {
24
26
  return this.options.enabled;
25
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "0.8.0-alpha.9",
3
+ "version": "0.8.1-alpha.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -14,10 +14,11 @@
14
14
  "@hapi/topo": "^6.0.0",
15
15
  "@koa/cors": "^3.1.0",
16
16
  "@koa/router": "^9.4.0",
17
- "@nocobase/acl": "0.8.0-alpha.9",
18
- "@nocobase/actions": "0.8.0-alpha.9",
19
- "@nocobase/database": "0.8.0-alpha.9",
20
- "@nocobase/resourcer": "0.8.0-alpha.9",
17
+ "@nocobase/acl": "0.8.1-alpha.3",
18
+ "@nocobase/actions": "0.8.1-alpha.3",
19
+ "@nocobase/database": "0.8.1-alpha.3",
20
+ "@nocobase/logger": "0.8.1-alpha.3",
21
+ "@nocobase/resourcer": "0.8.1-alpha.3",
21
22
  "chalk": "^4.1.1",
22
23
  "commander": "^9.2.0",
23
24
  "find-package-json": "^1.2.0",
@@ -32,5 +33,5 @@
32
33
  "devDependencies": {
33
34
  "@types/semver": "^7.3.9"
34
35
  },
35
- "gitHead": "6afe02d59bb22df0f96a7605c9001dcc17a30d6a"
36
+ "gitHead": "e03df3df5962b99d9fbf5b6e33fbe2b23f14f3d3"
36
37
  }