@nocobase/server 0.8.0-alpha.8 → 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.
- package/lib/application.d.ts +10 -0
- package/lib/application.js +126 -32
- package/lib/commands/db-sync.js +0 -1
- package/lib/commands/install.js +9 -9
- package/lib/commands/pm.js +8 -0
- package/lib/commands/start.js +2 -1
- package/lib/helper.js +4 -2
- package/lib/middlewares/data-wrapping.js +4 -0
- package/lib/plugin-manager/PluginManager.d.ts +2 -0
- package/lib/plugin-manager/PluginManager.js +47 -47
- package/lib/plugin.d.ts +1 -2
- package/lib/plugin.js +4 -2
- package/package.json +7 -6
package/lib/application.d.ts
CHANGED
|
@@ -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>;
|
package/lib/application.js
CHANGED
|
@@ -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;
|
|
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
|
-
|
|
414
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
518
|
-
yield _this11.db.
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
|
|
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
|
|
527
|
-
yield
|
|
528
|
-
yield
|
|
529
|
-
yield
|
|
530
|
-
yield
|
|
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
|
|
629
|
+
var _this14 = this;
|
|
536
630
|
|
|
537
631
|
return _asyncToGenerator(function* () {
|
|
538
|
-
yield
|
|
632
|
+
yield _this14.emitAsync('beforeUpgrade', _this14, options);
|
|
539
633
|
const force = false;
|
|
540
|
-
yield
|
|
541
|
-
yield
|
|
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
|
|
548
|
-
yield
|
|
641
|
+
yield _this14.version.update();
|
|
642
|
+
yield _this14.emitAsync('afterUpgrade', _this14, options);
|
|
549
643
|
})();
|
|
550
644
|
}
|
|
551
645
|
|
package/lib/commands/db-sync.js
CHANGED
|
@@ -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,
|
package/lib/commands/install.js
CHANGED
|
@@ -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
|
-
|
|
30
|
-
yield app.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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 (
|
|
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;
|
package/lib/commands/pm.js
CHANGED
|
@@ -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
|
package/lib/commands/start.js
CHANGED
|
@@ -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
|
-
|
|
119
|
+
const token = ctx.get('Authorization').replace(/^Bearer\s+/gi, '');
|
|
120
|
+
return token || ctx.query.token;
|
|
119
121
|
};
|
|
120
122
|
|
|
121
123
|
yield next();
|
|
@@ -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
|
}
|
|
@@ -124,24 +124,11 @@ class PluginManager {
|
|
|
124
124
|
this.repository = this.collection.repository;
|
|
125
125
|
this.repository.setPluginManager(this);
|
|
126
126
|
this.app.resourcer.define(_resource.default);
|
|
127
|
-
this.app.acl.
|
|
128
|
-
|
|
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
|
-
}());
|
|
127
|
+
this.app.acl.allow('pm', ['enable', 'disable', 'remove'], 'allowConfigure');
|
|
128
|
+
this.app.acl.allow('applicationPlugins', 'list', 'allowConfigure');
|
|
142
129
|
this.server = _net().default.createServer(socket => {
|
|
143
130
|
socket.on('data', /*#__PURE__*/function () {
|
|
144
|
-
var
|
|
131
|
+
var _ref = _asyncToGenerator(function* (data) {
|
|
145
132
|
const _JSON$parse = JSON.parse(data.toString()),
|
|
146
133
|
method = _JSON$parse.method,
|
|
147
134
|
plugins = _JSON$parse.plugins;
|
|
@@ -154,14 +141,14 @@ class PluginManager {
|
|
|
154
141
|
}
|
|
155
142
|
});
|
|
156
143
|
|
|
157
|
-
return function (
|
|
158
|
-
return
|
|
144
|
+
return function (_x) {
|
|
145
|
+
return _ref.apply(this, arguments);
|
|
159
146
|
};
|
|
160
147
|
}());
|
|
161
148
|
socket.pipe(socket);
|
|
162
149
|
});
|
|
163
150
|
this.app.on('beforeLoad', /*#__PURE__*/function () {
|
|
164
|
-
var
|
|
151
|
+
var _ref2 = _asyncToGenerator(function* (app, options) {
|
|
165
152
|
if ((options === null || options === void 0 ? void 0 : options.method) && ['install', 'upgrade'].includes(options.method)) {
|
|
166
153
|
yield _this.collection.sync();
|
|
167
154
|
}
|
|
@@ -177,10 +164,13 @@ class PluginManager {
|
|
|
177
164
|
}
|
|
178
165
|
});
|
|
179
166
|
|
|
180
|
-
return function (
|
|
181
|
-
return
|
|
167
|
+
return function (_x2, _x3) {
|
|
168
|
+
return _ref2.apply(this, arguments);
|
|
182
169
|
};
|
|
183
170
|
}());
|
|
171
|
+
this.app.on('beforeUpgrade', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
172
|
+
yield _this.collection.sync();
|
|
173
|
+
}));
|
|
184
174
|
this.addStaticMultiple(options.plugins);
|
|
185
175
|
}
|
|
186
176
|
|
|
@@ -213,6 +203,10 @@ class PluginManager {
|
|
|
213
203
|
return this.plugins.get(name);
|
|
214
204
|
}
|
|
215
205
|
|
|
206
|
+
has(name) {
|
|
207
|
+
return this.plugins.has(name);
|
|
208
|
+
}
|
|
209
|
+
|
|
216
210
|
clientWrite(data) {
|
|
217
211
|
var _this2 = this;
|
|
218
212
|
|
|
@@ -284,7 +278,7 @@ class PluginManager {
|
|
|
284
278
|
yield generator.run();
|
|
285
279
|
});
|
|
286
280
|
|
|
287
|
-
return function createPlugin(
|
|
281
|
+
return function createPlugin(_x4) {
|
|
288
282
|
return _ref5.apply(this, arguments);
|
|
289
283
|
};
|
|
290
284
|
}();
|
|
@@ -341,7 +335,7 @@ class PluginManager {
|
|
|
341
335
|
const pluginName = instance.getName();
|
|
342
336
|
|
|
343
337
|
if (this.plugins.has(pluginName)) {
|
|
344
|
-
throw new Error(`plugin name [${pluginName}] exists`);
|
|
338
|
+
throw new Error(`plugin name [${pluginName}] already exists`);
|
|
345
339
|
}
|
|
346
340
|
|
|
347
341
|
this.plugins.set(pluginName, instance);
|
|
@@ -363,8 +357,7 @@ class PluginManager {
|
|
|
363
357
|
yield t.rollback();
|
|
364
358
|
throw error;
|
|
365
359
|
}
|
|
366
|
-
}
|
|
367
|
-
|
|
360
|
+
}
|
|
368
361
|
|
|
369
362
|
const packageName = yield PluginManager.findPackage(plugin);
|
|
370
363
|
|
|
@@ -381,26 +374,25 @@ class PluginManager {
|
|
|
381
374
|
}
|
|
382
375
|
});
|
|
383
376
|
|
|
384
|
-
if (model) {
|
|
385
|
-
|
|
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
|
+
});
|
|
386
394
|
}
|
|
387
395
|
|
|
388
|
-
const enabled = options.enabled,
|
|
389
|
-
builtIn = options.builtIn,
|
|
390
|
-
installed = options.installed,
|
|
391
|
-
others = _objectWithoutProperties(options, _excluded);
|
|
392
|
-
|
|
393
|
-
yield _this4.repository.create({
|
|
394
|
-
transaction,
|
|
395
|
-
values: {
|
|
396
|
-
name: plugin,
|
|
397
|
-
version: packageJson.version,
|
|
398
|
-
enabled: !!enabled,
|
|
399
|
-
builtIn: !!builtIn,
|
|
400
|
-
installed: !!installed,
|
|
401
|
-
options: _objectSpread({}, others)
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
396
|
const file = (0, _path().resolve)(process.cwd(), 'packages', process.env.APP_PACKAGE_ROOT || 'app', 'client/src/plugins', `${plugin}.ts`);
|
|
405
397
|
|
|
406
398
|
if (!_fs().default.existsSync(file)) {
|
|
@@ -603,7 +595,7 @@ class PluginManager {
|
|
|
603
595
|
}
|
|
604
596
|
|
|
605
597
|
static getPackageName(name) {
|
|
606
|
-
const prefixes =
|
|
598
|
+
const prefixes = this.getPluginPkgPrefix();
|
|
607
599
|
|
|
608
600
|
var _iterator9 = _createForOfIteratorHelper(prefixes),
|
|
609
601
|
_step9;
|
|
@@ -629,6 +621,10 @@ class PluginManager {
|
|
|
629
621
|
throw new Error(`${name} plugin does not exist`);
|
|
630
622
|
}
|
|
631
623
|
|
|
624
|
+
static getPluginPkgPrefix() {
|
|
625
|
+
return (process.env.PLUGIN_PACKAGE_PREFIX || '@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-').split(',');
|
|
626
|
+
}
|
|
627
|
+
|
|
632
628
|
static findPackage(name) {
|
|
633
629
|
var _this10 = this;
|
|
634
630
|
|
|
@@ -638,7 +634,9 @@ class PluginManager {
|
|
|
638
634
|
|
|
639
635
|
return packageName;
|
|
640
636
|
} catch (error) {
|
|
641
|
-
|
|
637
|
+
console.log(`\`${name}\` plugin not found locally`);
|
|
638
|
+
|
|
639
|
+
const prefixes = _this10.getPluginPkgPrefix();
|
|
642
640
|
|
|
643
641
|
var _iterator10 = _createForOfIteratorHelper(prefixes),
|
|
644
642
|
_step10;
|
|
@@ -649,9 +647,11 @@ class PluginManager {
|
|
|
649
647
|
|
|
650
648
|
try {
|
|
651
649
|
const packageName = `${prefix}${name}`;
|
|
650
|
+
console.log(`Try to find ${packageName}`);
|
|
652
651
|
yield (0, _execa().default)('npm', ['v', packageName, 'versions']);
|
|
653
|
-
console.log(`${packageName}
|
|
652
|
+
console.log(`${packageName} downloading`);
|
|
654
653
|
yield (0, _execa().default)('yarn', ['add', packageName, '-W']);
|
|
654
|
+
console.log(`${packageName} downloaded`);
|
|
655
655
|
return packageName;
|
|
656
656
|
} catch (error) {
|
|
657
657
|
continue;
|
|
@@ -664,7 +664,7 @@ class PluginManager {
|
|
|
664
664
|
}
|
|
665
665
|
}
|
|
666
666
|
|
|
667
|
-
throw new Error(
|
|
667
|
+
throw new Error(`No available packages found, ${name} plugin does not exist`);
|
|
668
668
|
})();
|
|
669
669
|
}
|
|
670
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.
|
|
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.
|
|
18
|
-
"@nocobase/actions": "0.8.
|
|
19
|
-
"@nocobase/database": "0.8.
|
|
20
|
-
"@nocobase/
|
|
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": "
|
|
36
|
+
"gitHead": "e03df3df5962b99d9fbf5b6e33fbe2b23f14f3d3"
|
|
36
37
|
}
|