@nocobase/server 0.18.0-alpha.9 → 0.19.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.
- package/lib/app-command.d.ts +4 -0
- package/lib/app-command.js +14 -0
- package/lib/app-supervisor.js +11 -3
- package/lib/application.d.ts +29 -2
- package/lib/application.js +156 -44
- package/lib/commands/create-migration.d.ts +3 -0
- package/lib/commands/create-migration.js +67 -0
- package/lib/commands/db-clean.js +1 -1
- package/lib/commands/db-sync.js +1 -1
- package/lib/commands/destroy.js +1 -1
- package/lib/commands/index.js +5 -5
- package/lib/commands/install.js +7 -9
- package/lib/commands/migrator.js +1 -1
- package/lib/commands/pm.js +7 -7
- package/lib/commands/refresh.d.ts +3 -0
- package/lib/commands/refresh.js +31 -0
- package/lib/commands/restart.js +5 -0
- package/lib/commands/start.js +19 -8
- package/lib/commands/stop.js +4 -0
- package/lib/commands/upgrade.js +3 -16
- package/lib/errors/handler.js +3 -0
- package/lib/gateway/index.d.ts +3 -2
- package/lib/gateway/index.js +25 -9
- package/lib/gateway/ipc-socket-client.d.ts +2 -2
- package/lib/gateway/ipc-socket-client.js +6 -3
- package/lib/gateway/ipc-socket-server.d.ts +1 -1
- package/lib/gateway/ipc-socket-server.js +35 -7
- package/lib/helpers/application-version.js +17 -25
- package/lib/middlewares/data-wrapping.js +21 -18
- package/lib/migration.d.ts +5 -0
- package/lib/migration.js +6 -0
- package/lib/migrations/20230912193824-package-name-unique.d.ts +2 -0
- package/lib/migrations/20230912193824-package-name-unique.js +14 -31
- package/lib/migrations/20230912294620-update-pkg.d.ts +6 -0
- package/lib/migrations/20230912294620-update-pkg.js +55 -0
- package/lib/migrations/20240106082756-update-plugins.d.ts +6 -0
- package/lib/migrations/20240106082756-update-plugins.js +41 -0
- package/lib/plugin-manager/options/collection.js +2 -2
- package/lib/plugin-manager/plugin-manager-repository.d.ts +1 -2
- package/lib/plugin-manager/plugin-manager-repository.js +14 -26
- package/lib/plugin-manager/plugin-manager.d.ts +36 -3
- package/lib/plugin-manager/plugin-manager.js +271 -42
- package/lib/plugin.d.ts +12 -0
- package/lib/plugin.js +108 -14
- package/package.json +13 -13
package/lib/app-command.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
export declare class AppCommand extends Command {
|
|
3
3
|
private _handleByIPCServer;
|
|
4
|
+
_preload: boolean;
|
|
4
5
|
ipc(): this;
|
|
6
|
+
auth(): this;
|
|
7
|
+
preload(): this;
|
|
8
|
+
hasCommand(name: string): boolean;
|
|
5
9
|
isHandleByIPCServer(): boolean;
|
|
6
10
|
createCommand(name?: string): AppCommand;
|
|
7
11
|
parseHandleByIPCServer(argv: any, parseOptions?: any): Boolean;
|
package/lib/app-command.js
CHANGED
|
@@ -24,10 +24,24 @@ module.exports = __toCommonJS(app_command_exports);
|
|
|
24
24
|
var import_commander = require("commander");
|
|
25
25
|
const _AppCommand = class _AppCommand extends import_commander.Command {
|
|
26
26
|
_handleByIPCServer = false;
|
|
27
|
+
_preload = false;
|
|
27
28
|
ipc() {
|
|
28
29
|
this._handleByIPCServer = true;
|
|
29
30
|
return this;
|
|
30
31
|
}
|
|
32
|
+
auth() {
|
|
33
|
+
this["_authenticate"] = true;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
preload() {
|
|
37
|
+
this["_authenticate"] = true;
|
|
38
|
+
this._preload = true;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
hasCommand(name) {
|
|
42
|
+
const names = this.commands.map((c) => c.name());
|
|
43
|
+
return names.includes(name);
|
|
44
|
+
}
|
|
31
45
|
isHandleByIPCServer() {
|
|
32
46
|
return this._handleByIPCServer;
|
|
33
47
|
}
|
package/lib/app-supervisor.js
CHANGED
|
@@ -213,9 +213,17 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
213
213
|
});
|
|
214
214
|
app.on("__started", async (_app, options) => {
|
|
215
215
|
const { maintainingStatus, options: startOptions } = options;
|
|
216
|
-
if (maintainingStatus && [
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
if (maintainingStatus && [
|
|
217
|
+
"install",
|
|
218
|
+
"upgrade",
|
|
219
|
+
"refresh",
|
|
220
|
+
"restore",
|
|
221
|
+
"pm.add",
|
|
222
|
+
"pm.update",
|
|
223
|
+
"pm.enable",
|
|
224
|
+
"pm.disable",
|
|
225
|
+
"pm.remove"
|
|
226
|
+
].includes(maintainingStatus.command.name) && !startOptions.recover) {
|
|
219
227
|
this.setAppStatus(app.name, "running", {
|
|
220
228
|
refresh: true
|
|
221
229
|
});
|
package/lib/application.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ import { ACL } from '@nocobase/acl';
|
|
|
5
5
|
import { AuthManager, AuthManagerOptions } from '@nocobase/auth';
|
|
6
6
|
import { Cache, CacheManager, CacheManagerOptions } from '@nocobase/cache';
|
|
7
7
|
import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
|
|
8
|
-
import {
|
|
8
|
+
import { LoggerOptions, RequestLoggerOptions, SystemLogger, SystemLoggerOptions } from '@nocobase/logger';
|
|
9
9
|
import { ResourceOptions, Resourcer } from '@nocobase/resourcer';
|
|
10
|
+
import { Telemetry, TelemetryOptions } from '@nocobase/telemetry';
|
|
10
11
|
import { AsyncEmitter, ToposortOptions } from '@nocobase/utils';
|
|
11
12
|
import { Command, CommandOptions, ParseOptions } from 'commander';
|
|
12
13
|
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
@@ -20,7 +21,6 @@ import { ApplicationVersion } from './helpers/application-version';
|
|
|
20
21
|
import { Locale } from './locale';
|
|
21
22
|
import { Plugin } from './plugin';
|
|
22
23
|
import { InstallOptions, PluginManager } from './plugin-manager';
|
|
23
|
-
import { TelemetryOptions, Telemetry } from '@nocobase/telemetry';
|
|
24
24
|
export type PluginType = string | typeof Plugin;
|
|
25
25
|
export type PluginConfiguration = PluginType | [PluginType, any];
|
|
26
26
|
export interface ResourcerOptions {
|
|
@@ -70,6 +70,8 @@ interface StartOptions {
|
|
|
70
70
|
cliArgs?: any[];
|
|
71
71
|
dbSync?: boolean;
|
|
72
72
|
checkInstall?: boolean;
|
|
73
|
+
quickstart?: boolean;
|
|
74
|
+
reload?: boolean;
|
|
73
75
|
recover?: boolean;
|
|
74
76
|
}
|
|
75
77
|
type MaintainingStatus = 'command_begin' | 'command_end' | 'command_running' | 'command_error';
|
|
@@ -143,6 +145,9 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
143
145
|
setMaintaining(_maintainingCommandStatus: MaintainingCommandStatus): void;
|
|
144
146
|
setMaintainingMessage(message: string): void;
|
|
145
147
|
getVersion(): string;
|
|
148
|
+
/**
|
|
149
|
+
* @deprecated
|
|
150
|
+
*/
|
|
146
151
|
plugin<O = any>(pluginClass: any, options?: O): void;
|
|
147
152
|
use<NewStateT = {}, NewContextT = {}>(middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>, options?: ToposortOptions): this;
|
|
148
153
|
callback(): (req: IncomingMessage, res: ServerResponse) => any;
|
|
@@ -151,13 +156,35 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
151
156
|
actions(handlers: any, options?: ActionsOptions): void;
|
|
152
157
|
command(name: string, desc?: string, opts?: CommandOptions): AppCommand;
|
|
153
158
|
findCommand(name: string): Command;
|
|
159
|
+
preload(): Promise<void>;
|
|
160
|
+
reInit(): Promise<void>;
|
|
154
161
|
load(options?: any): Promise<void>;
|
|
155
162
|
reload(options?: any): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* @deprecated
|
|
165
|
+
*/
|
|
156
166
|
getPlugin<P extends Plugin>(name: string | typeof Plugin): P;
|
|
157
167
|
parse(argv?: string[]): Promise<AppCommand>;
|
|
158
168
|
authenticate(): Promise<void>;
|
|
159
169
|
runCommand(command: string, ...args: any[]): Promise<AppCommand>;
|
|
160
170
|
createCli(): AppCommand;
|
|
171
|
+
loadMigrations(options: any): Promise<{
|
|
172
|
+
beforeLoad: any[];
|
|
173
|
+
afterSync: any[];
|
|
174
|
+
afterLoad: any[];
|
|
175
|
+
}>;
|
|
176
|
+
loadCoreMigrations(): Promise<{
|
|
177
|
+
beforeLoad: {
|
|
178
|
+
up: () => Promise<void>;
|
|
179
|
+
};
|
|
180
|
+
afterSync: {
|
|
181
|
+
up: () => Promise<void>;
|
|
182
|
+
};
|
|
183
|
+
afterLoad: {
|
|
184
|
+
up: () => Promise<void>;
|
|
185
|
+
};
|
|
186
|
+
}>;
|
|
187
|
+
loadPluginCommands(): Promise<void>;
|
|
161
188
|
runAsCLI(argv?: string[], options?: ParseOptions & {
|
|
162
189
|
throwError?: boolean;
|
|
163
190
|
reqId?: string;
|
package/lib/application.js
CHANGED
|
@@ -36,12 +36,15 @@ var import_actions = require("@nocobase/actions");
|
|
|
36
36
|
var import_auth = require("@nocobase/auth");
|
|
37
37
|
var import_database = __toESM(require("@nocobase/database"));
|
|
38
38
|
var import_logger = require("@nocobase/logger");
|
|
39
|
+
var import_telemetry = require("@nocobase/telemetry");
|
|
39
40
|
var import_utils = require("@nocobase/utils");
|
|
40
|
-
var import_chalk = __toESM(require("chalk"));
|
|
41
41
|
var import_crypto = require("crypto");
|
|
42
|
+
var import_glob = __toESM(require("glob"));
|
|
42
43
|
var import_koa = __toESM(require("koa"));
|
|
43
44
|
var import_koa_compose = __toESM(require("koa-compose"));
|
|
44
45
|
var import_lodash = __toESM(require("lodash"));
|
|
46
|
+
var import_path = require("path");
|
|
47
|
+
var import_semver = __toESM(require("semver"));
|
|
45
48
|
var import_acl2 = require("./acl");
|
|
46
49
|
var import_app_command = require("./app-command");
|
|
47
50
|
var import_app_supervisor = require("./app-supervisor");
|
|
@@ -53,7 +56,6 @@ var import_helper = require("./helper");
|
|
|
53
56
|
var import_application_version = require("./helpers/application-version");
|
|
54
57
|
var import_locale = require("./locale");
|
|
55
58
|
var import_plugin_manager = require("./plugin-manager");
|
|
56
|
-
var import_telemetry = require("@nocobase/telemetry");
|
|
57
59
|
var import_package = __toESM(require("../package.json"));
|
|
58
60
|
const _Application = class _Application extends import_koa.default {
|
|
59
61
|
constructor(options) {
|
|
@@ -180,6 +182,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
180
182
|
getVersion() {
|
|
181
183
|
return import_package.default.version;
|
|
182
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* @deprecated
|
|
187
|
+
*/
|
|
183
188
|
plugin(pluginClass, options) {
|
|
184
189
|
this.log.debug(`add plugin`, { method: "plugin", name: pluginClass.name });
|
|
185
190
|
this.pm.addPreset(pluginClass, options);
|
|
@@ -213,6 +218,26 @@ const _Application = class _Application extends import_koa.default {
|
|
|
213
218
|
findCommand(name) {
|
|
214
219
|
return this.cli._findCommand(name);
|
|
215
220
|
}
|
|
221
|
+
async preload() {
|
|
222
|
+
}
|
|
223
|
+
async reInit() {
|
|
224
|
+
if (!this._loaded) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
this.log.info("app reinitializing");
|
|
228
|
+
if (this.cacheManager) {
|
|
229
|
+
await this.cacheManager.close();
|
|
230
|
+
}
|
|
231
|
+
if (this.telemetry.started) {
|
|
232
|
+
await this.telemetry.shutdown();
|
|
233
|
+
}
|
|
234
|
+
const oldDb = this._db;
|
|
235
|
+
this.init();
|
|
236
|
+
if (!oldDb.closed()) {
|
|
237
|
+
await oldDb.close();
|
|
238
|
+
}
|
|
239
|
+
this._loaded = false;
|
|
240
|
+
}
|
|
216
241
|
async load(options) {
|
|
217
242
|
var _a;
|
|
218
243
|
if (this._loaded) {
|
|
@@ -238,14 +263,18 @@ const _Application = class _Application extends import_koa.default {
|
|
|
238
263
|
await this.pm.initPlugins();
|
|
239
264
|
this.setMaintainingMessage("start load");
|
|
240
265
|
this.setMaintainingMessage("emit beforeLoad");
|
|
241
|
-
|
|
266
|
+
if ((options == null ? void 0 : options.hooks) !== false) {
|
|
267
|
+
await this.emitAsync("beforeLoad", this, options);
|
|
268
|
+
}
|
|
242
269
|
this.telemetry.init();
|
|
243
270
|
if ((_a = this.options.telemetry) == null ? void 0 : _a.enabled) {
|
|
244
271
|
this.telemetry.start();
|
|
245
272
|
}
|
|
246
273
|
await this.pm.load(options);
|
|
247
274
|
this.setMaintainingMessage("emit afterLoad");
|
|
248
|
-
|
|
275
|
+
if ((options == null ? void 0 : options.hooks) !== false) {
|
|
276
|
+
await this.emitAsync("afterLoad", this, options);
|
|
277
|
+
}
|
|
249
278
|
this._loaded = true;
|
|
250
279
|
}
|
|
251
280
|
async reload(options) {
|
|
@@ -261,6 +290,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
261
290
|
await this.emitAsync("afterReload", this, options);
|
|
262
291
|
this.log.debug(`finish reload`, { method: "reload" });
|
|
263
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* @deprecated
|
|
295
|
+
*/
|
|
264
296
|
getPlugin(name) {
|
|
265
297
|
return this.pm.get(name);
|
|
266
298
|
}
|
|
@@ -293,8 +325,12 @@ const _Application = class _Application extends import_koa.default {
|
|
|
293
325
|
status: "command_running",
|
|
294
326
|
command: this.activatedCommand
|
|
295
327
|
});
|
|
296
|
-
|
|
297
|
-
|
|
328
|
+
if (actionCommand["_authenticate"]) {
|
|
329
|
+
await this.authenticate();
|
|
330
|
+
}
|
|
331
|
+
if (actionCommand["_preload"]) {
|
|
332
|
+
await this.load();
|
|
333
|
+
}
|
|
298
334
|
}).hook("postAction", async (_, actionCommand) => {
|
|
299
335
|
var _a;
|
|
300
336
|
if (((_a = this._maintainingStatusBeforeCommand) == null ? void 0 : _a.error) && this._started) {
|
|
@@ -306,6 +342,64 @@ const _Application = class _Application extends import_koa.default {
|
|
|
306
342
|
});
|
|
307
343
|
return command;
|
|
308
344
|
}
|
|
345
|
+
async loadMigrations(options) {
|
|
346
|
+
const { directory, context, namespace } = options;
|
|
347
|
+
const migrations = {
|
|
348
|
+
beforeLoad: [],
|
|
349
|
+
afterSync: [],
|
|
350
|
+
afterLoad: []
|
|
351
|
+
};
|
|
352
|
+
const extensions = ["js", "ts"];
|
|
353
|
+
const patten = `${directory}/*.{${extensions.join(",")}}`;
|
|
354
|
+
const files = import_glob.default.sync(patten, {
|
|
355
|
+
ignore: ["**/*.d.ts"]
|
|
356
|
+
});
|
|
357
|
+
const appVersion = await this.version.get();
|
|
358
|
+
for (const file of files) {
|
|
359
|
+
let filename = (0, import_path.basename)(file);
|
|
360
|
+
filename = filename.substring(0, filename.lastIndexOf(".")) || filename;
|
|
361
|
+
const Migration = await (0, import_utils.importModule)(file);
|
|
362
|
+
const m = new Migration({ app: this, db: this.db, ...context });
|
|
363
|
+
if (!m.appVersion || import_semver.default.satisfies(appVersion, m.appVersion, { includePrerelease: true })) {
|
|
364
|
+
m.name = `${filename}/${namespace}`;
|
|
365
|
+
migrations[m.on || "afterLoad"].push(m);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return migrations;
|
|
369
|
+
}
|
|
370
|
+
async loadCoreMigrations() {
|
|
371
|
+
const migrations = await this.loadMigrations({
|
|
372
|
+
directory: (0, import_path.resolve)(__dirname, "migrations"),
|
|
373
|
+
namespace: "@nocobase/server"
|
|
374
|
+
});
|
|
375
|
+
return {
|
|
376
|
+
beforeLoad: {
|
|
377
|
+
up: async () => {
|
|
378
|
+
this.log.debug("run core migrations(beforeLoad)");
|
|
379
|
+
const migrator = this.db.createMigrator({ migrations: migrations.beforeLoad });
|
|
380
|
+
await migrator.up();
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
afterSync: {
|
|
384
|
+
up: async () => {
|
|
385
|
+
this.log.debug("run core migrations(afterSync)");
|
|
386
|
+
const migrator = this.db.createMigrator({ migrations: migrations.afterSync });
|
|
387
|
+
await migrator.up();
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
afterLoad: {
|
|
391
|
+
up: async () => {
|
|
392
|
+
this.log.debug("run core migrations(afterLoad)");
|
|
393
|
+
const migrator = this.db.createMigrator({ migrations: migrations.afterLoad });
|
|
394
|
+
await migrator.up();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
async loadPluginCommands() {
|
|
400
|
+
this.log.debug("load plugin commands");
|
|
401
|
+
await this.pm.loadCommands();
|
|
402
|
+
}
|
|
309
403
|
async runAsCLI(argv = process.argv, options) {
|
|
310
404
|
if (this.activatedCommand) {
|
|
311
405
|
return;
|
|
@@ -316,6 +410,10 @@ const _Application = class _Application extends import_koa.default {
|
|
|
316
410
|
}
|
|
317
411
|
this._maintainingStatusBeforeCommand = this._maintainingCommandStatus;
|
|
318
412
|
try {
|
|
413
|
+
const commandName = (options == null ? void 0 : options.from) === "user" ? argv[0] : argv[2];
|
|
414
|
+
if (!this.cli.hasCommand(commandName)) {
|
|
415
|
+
await this.pm.loadCommands();
|
|
416
|
+
}
|
|
319
417
|
const command = await this.cli.parseAsync(argv, options);
|
|
320
418
|
this.setMaintaining({
|
|
321
419
|
status: "command_end",
|
|
@@ -323,7 +421,6 @@ const _Application = class _Application extends import_koa.default {
|
|
|
323
421
|
});
|
|
324
422
|
return command;
|
|
325
423
|
} catch (error) {
|
|
326
|
-
console.log({ error });
|
|
327
424
|
if (!this.activatedCommand) {
|
|
328
425
|
this.activatedCommand = {
|
|
329
426
|
name: "unknown"
|
|
@@ -393,6 +490,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
393
490
|
if (!this._started) {
|
|
394
491
|
return;
|
|
395
492
|
}
|
|
493
|
+
this.log.info("restarting...");
|
|
396
494
|
this._started = false;
|
|
397
495
|
await this.emitAsync("beforeStop");
|
|
398
496
|
await this.reload(options);
|
|
@@ -400,20 +498,30 @@ const _Application = class _Application extends import_koa.default {
|
|
|
400
498
|
this.emit("__restarted", this, options);
|
|
401
499
|
}
|
|
402
500
|
async stop(options = {}) {
|
|
403
|
-
|
|
501
|
+
const log = options.logging === false ? {
|
|
502
|
+
debug() {
|
|
503
|
+
},
|
|
504
|
+
warn() {
|
|
505
|
+
},
|
|
506
|
+
info() {
|
|
507
|
+
},
|
|
508
|
+
error() {
|
|
509
|
+
}
|
|
510
|
+
} : this.log;
|
|
511
|
+
log.debug("stop app...", { method: "stop" });
|
|
404
512
|
this.setMaintainingMessage("stopping app...");
|
|
405
513
|
if (this.stopped) {
|
|
406
|
-
|
|
514
|
+
log.warn(`app is stopped`, { method: "stop" });
|
|
407
515
|
return;
|
|
408
516
|
}
|
|
409
517
|
await this.emitAsync("beforeStop", this, options);
|
|
410
518
|
try {
|
|
411
519
|
if (!this.db.closed()) {
|
|
412
|
-
|
|
520
|
+
log.info(`close db`, { method: "stop" });
|
|
413
521
|
await this.db.close();
|
|
414
522
|
}
|
|
415
523
|
} catch (e) {
|
|
416
|
-
|
|
524
|
+
log.error(e.message, { method: "stop", err: e.stack });
|
|
417
525
|
}
|
|
418
526
|
if (this.cacheManager) {
|
|
419
527
|
await this.cacheManager.close();
|
|
@@ -423,7 +531,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
423
531
|
}
|
|
424
532
|
await this.emitAsync("afterStop", this, options);
|
|
425
533
|
this.stopped = true;
|
|
426
|
-
|
|
534
|
+
log.info(`app has stopped`, { method: "stop" });
|
|
427
535
|
this._started = false;
|
|
428
536
|
}
|
|
429
537
|
async destroy(options = {}) {
|
|
@@ -439,29 +547,27 @@ const _Application = class _Application extends import_koa.default {
|
|
|
439
547
|
return await this.db.collectionExistsInDb("applicationVersion") || await this.db.collectionExistsInDb("collections");
|
|
440
548
|
}
|
|
441
549
|
async install(options = {}) {
|
|
442
|
-
var _a
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if ((options == null ? void 0 : options.clean) || ((_a = options == null ? void 0 : options.sync) == null ? void 0 : _a.force)) {
|
|
446
|
-
this.log.debug("truncate database", { method: "install" });
|
|
550
|
+
var _a;
|
|
551
|
+
const reinstall = options.clean || options.force;
|
|
552
|
+
if (reinstall) {
|
|
447
553
|
await this.db.clean({ drop: true });
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
this.log.warn("app is installed", { method: "install" });
|
|
554
|
+
}
|
|
555
|
+
if (await this.isInstalled()) {
|
|
556
|
+
this.log.warn("app is installed");
|
|
452
557
|
return;
|
|
453
558
|
}
|
|
559
|
+
await this.reInit();
|
|
560
|
+
await this.db.sync();
|
|
561
|
+
await this.load({ hooks: false });
|
|
454
562
|
this.log.debug("emit beforeInstall", { method: "install" });
|
|
455
563
|
this.setMaintainingMessage("call beforeInstall hook...");
|
|
456
564
|
await this.emitAsync("beforeInstall", this, options);
|
|
457
|
-
this.
|
|
458
|
-
await this.pm.install(options);
|
|
459
|
-
this.log.debug("update version", { method: "install" });
|
|
565
|
+
await this.pm.install();
|
|
460
566
|
await this.version.update();
|
|
461
567
|
this.log.debug("emit afterInstall", { method: "install" });
|
|
462
568
|
this.setMaintainingMessage("call afterInstall hook...");
|
|
463
569
|
await this.emitAsync("afterInstall", this, options);
|
|
464
|
-
if ((
|
|
570
|
+
if ((_a = this._maintainingStatusBeforeCommand) == null ? void 0 : _a.error) {
|
|
465
571
|
return;
|
|
466
572
|
}
|
|
467
573
|
if (this._started) {
|
|
@@ -469,27 +575,33 @@ const _Application = class _Application extends import_koa.default {
|
|
|
469
575
|
}
|
|
470
576
|
}
|
|
471
577
|
async upgrade(options = {}) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
await
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
await
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
578
|
+
this.log.info("upgrading...");
|
|
579
|
+
await this.reInit();
|
|
580
|
+
const migrator1 = await this.loadCoreMigrations();
|
|
581
|
+
await migrator1.beforeLoad.up();
|
|
582
|
+
await this.db.sync();
|
|
583
|
+
await migrator1.afterSync.up();
|
|
584
|
+
await this.pm.initPresetPlugins();
|
|
585
|
+
const migrator2 = await this.pm.loadPresetMigrations();
|
|
586
|
+
await migrator2.beforeLoad.up();
|
|
587
|
+
await this.pm.load();
|
|
588
|
+
await this.db.sync();
|
|
589
|
+
await migrator2.afterSync.up();
|
|
590
|
+
await this.pm.upgrade();
|
|
591
|
+
await this.pm.initOtherPlugins();
|
|
592
|
+
const migrator3 = await this.pm.loadOtherMigrations();
|
|
593
|
+
await migrator3.beforeLoad.up();
|
|
594
|
+
await this.load();
|
|
595
|
+
await this.db.sync();
|
|
596
|
+
await migrator3.afterSync.up();
|
|
597
|
+
await this.pm.upgrade();
|
|
598
|
+
await migrator1.afterLoad.up();
|
|
599
|
+
await migrator2.afterLoad.up();
|
|
600
|
+
await migrator3.afterLoad.up();
|
|
601
|
+
await this.pm.repository.updateVersions();
|
|
485
602
|
await this.version.update();
|
|
486
603
|
await this.emitAsync("afterUpgrade", this, options);
|
|
487
|
-
|
|
488
|
-
if (this._started) {
|
|
489
|
-
await (0, import_utils.measureExecutionTime)(async () => {
|
|
490
|
-
await this.restart();
|
|
491
|
-
}, "Restart");
|
|
492
|
-
}
|
|
604
|
+
await this.restart();
|
|
493
605
|
}
|
|
494
606
|
toJSON() {
|
|
495
607
|
return {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var create_migration_exports = {};
|
|
30
|
+
__export(create_migration_exports, {
|
|
31
|
+
default: () => create_migration_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(create_migration_exports);
|
|
34
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
35
|
+
var import_fs = __toESM(require("fs"));
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var create_migration_default = /* @__PURE__ */ __name((app) => {
|
|
38
|
+
app.command("create-migration").argument("<name>").option("--pkg <pkg>").option("--on [on]").action(async (name, options) => {
|
|
39
|
+
const pkg = options.pkg;
|
|
40
|
+
const dir = await import_fs.default.promises.realpath((0, import_path.resolve)(process.env.NODE_MODULES_PATH, pkg));
|
|
41
|
+
const filename = (0, import_path.resolve)(
|
|
42
|
+
dir,
|
|
43
|
+
pkg === "@nocobase/server" ? "src" : "src/server",
|
|
44
|
+
"migrations",
|
|
45
|
+
`${(0, import_dayjs.default)().format("YYYYMMDDHHmmss")}-${name}.ts`
|
|
46
|
+
);
|
|
47
|
+
const version = app.getVersion();
|
|
48
|
+
const keys = version.split(".");
|
|
49
|
+
keys.push(1 * keys.pop() + 1);
|
|
50
|
+
const nextVersion = keys.join(".");
|
|
51
|
+
const from = pkg === "@nocobase/server" ? `../migration` : "@nocobase/server";
|
|
52
|
+
const data = `import { Migration } from '${from}';
|
|
53
|
+
|
|
54
|
+
export default class extends Migration {
|
|
55
|
+
on = '${options.on || "afterLoad"}'; // 'beforeLoad' or 'afterLoad'
|
|
56
|
+
appVersion = '<${nextVersion}';
|
|
57
|
+
|
|
58
|
+
async up() {
|
|
59
|
+
// coding
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
await import_fs.default.promises.mkdir((0, import_path.dirname)(filename), { recursive: true });
|
|
64
|
+
await import_fs.default.promises.writeFile(filename, data, "utf8");
|
|
65
|
+
app.log.info(`migration file in ${filename}`);
|
|
66
|
+
});
|
|
67
|
+
}, "default");
|
package/lib/commands/db-clean.js
CHANGED
|
@@ -22,7 +22,7 @@ __export(db_clean_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(db_clean_exports);
|
|
24
24
|
var db_clean_default = /* @__PURE__ */ __name((app) => {
|
|
25
|
-
app.command("db:clean").option("-y, --yes").action(async (opts) => {
|
|
25
|
+
app.command("db:clean").auth().option("-y, --yes").action(async (opts) => {
|
|
26
26
|
console.log("Clearing database");
|
|
27
27
|
await app.db.clean({
|
|
28
28
|
drop: opts.yes
|
package/lib/commands/db-sync.js
CHANGED
|
@@ -22,7 +22,7 @@ __export(db_sync_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(db_sync_exports);
|
|
24
24
|
var db_sync_default = /* @__PURE__ */ __name((app) => {
|
|
25
|
-
app.command("db:sync").action(async (...cliArgs) => {
|
|
25
|
+
app.command("db:sync").auth().action(async (...cliArgs) => {
|
|
26
26
|
const [opts] = cliArgs;
|
|
27
27
|
console.log("db sync...");
|
|
28
28
|
const force = false;
|
package/lib/commands/destroy.js
CHANGED
|
@@ -22,7 +22,7 @@ __export(destroy_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(destroy_exports);
|
|
24
24
|
var destroy_default = /* @__PURE__ */ __name((app) => {
|
|
25
|
-
app.command("destroy").action(async (...cliArgs) => {
|
|
25
|
+
app.command("destroy").preload().action(async (...cliArgs) => {
|
|
26
26
|
await app.destroy({
|
|
27
27
|
cliArgs
|
|
28
28
|
});
|
package/lib/commands/index.js
CHANGED
|
@@ -31,31 +31,31 @@ __export(commands_exports, {
|
|
|
31
31
|
registerCli: () => registerCli
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(commands_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_create_migration = __toESM(require("./create-migration"));
|
|
35
35
|
var import_db_auth = __toESM(require("./db-auth"));
|
|
36
36
|
var import_db_clean = __toESM(require("./db-clean"));
|
|
37
37
|
var import_db_sync = __toESM(require("./db-sync"));
|
|
38
38
|
var import_destroy = __toESM(require("./destroy"));
|
|
39
39
|
var import_install = __toESM(require("./install"));
|
|
40
|
-
var import_migrator = __toESM(require("./migrator"));
|
|
41
40
|
var import_pm = __toESM(require("./pm"));
|
|
41
|
+
var import_refresh = __toESM(require("./refresh"));
|
|
42
42
|
var import_restart = __toESM(require("./restart"));
|
|
43
43
|
var import_start = __toESM(require("./start"));
|
|
44
44
|
var import_stop = __toESM(require("./stop"));
|
|
45
45
|
var import_upgrade = __toESM(require("./upgrade"));
|
|
46
46
|
function registerCli(app) {
|
|
47
|
-
(0, import_console.default)(app);
|
|
48
47
|
(0, import_db_auth.default)(app);
|
|
48
|
+
(0, import_create_migration.default)(app);
|
|
49
49
|
(0, import_db_clean.default)(app);
|
|
50
50
|
(0, import_db_sync.default)(app);
|
|
51
51
|
(0, import_install.default)(app);
|
|
52
|
-
(0, import_migrator.default)(app);
|
|
53
|
-
(0, import_start.default)(app);
|
|
54
52
|
(0, import_upgrade.default)(app);
|
|
55
53
|
(0, import_pm.default)(app);
|
|
56
54
|
(0, import_restart.default)(app);
|
|
57
55
|
(0, import_stop.default)(app);
|
|
58
56
|
(0, import_destroy.default)(app);
|
|
57
|
+
(0, import_start.default)(app);
|
|
58
|
+
(0, import_refresh.default)(app);
|
|
59
59
|
app.command("build").argument("[packages...]");
|
|
60
60
|
app.command("clean");
|
|
61
61
|
app.command("dev").usage("[options]").option("-p, --port [port]").option("--client").option("--server");
|
package/lib/commands/install.js
CHANGED
|
@@ -22,14 +22,12 @@ __export(install_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(install_exports);
|
|
24
24
|
var install_default = /* @__PURE__ */ __name((app) => {
|
|
25
|
-
app.command("install").ipc().option("-f, --force").option("-c, --clean").action(async (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
});
|
|
25
|
+
app.command("install").ipc().auth().option("-f, --force").option("-c, --clean").option("--lang <lang>").action(async (options) => {
|
|
26
|
+
if (options.lang) {
|
|
27
|
+
process.env.INIT_APP_LANG = options.lang;
|
|
28
|
+
}
|
|
29
|
+
await app.install(options);
|
|
30
|
+
const reinstall = options.clean || options.force;
|
|
31
|
+
app.log.info(`app ${reinstall ? "reinstalled" : "installed"} successfully [v${app.getVersion()}]`);
|
|
34
32
|
});
|
|
35
33
|
}, "default");
|
package/lib/commands/migrator.js
CHANGED
|
@@ -22,7 +22,7 @@ __export(migrator_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(migrator_exports);
|
|
24
24
|
var migrator_default = /* @__PURE__ */ __name((app) => {
|
|
25
|
-
app.command("migrator").action(async (opts) => {
|
|
25
|
+
app.command("migrator").preload().action(async (opts) => {
|
|
26
26
|
console.log("migrating...");
|
|
27
27
|
await app.emitAsync("cli.beforeMigrator", opts);
|
|
28
28
|
await app.db.migrator.runAsCLI(process.argv.slice(3));
|