@nocobase/server 1.0.0-alpha.13 → 1.0.0-alpha.14
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/commands/start.js +4 -1
- package/lib/plugin-manager/plugin-manager.js +6 -12
- package/lib/plugin-manager/utils.d.ts +1 -0
- package/lib/plugin-manager/utils.js +17 -0
- package/lib/plugin.d.ts +1 -12
- package/lib/plugin.js +12 -70
- package/package.json +14 -14
package/lib/commands/start.js
CHANGED
|
@@ -52,7 +52,10 @@ var start_default = /* @__PURE__ */ __name((app) => {
|
|
|
52
52
|
const upgrading = await (0, import_utils.fsExists)(file);
|
|
53
53
|
if (upgrading) {
|
|
54
54
|
await app.upgrade();
|
|
55
|
-
|
|
55
|
+
try {
|
|
56
|
+
await import_fs.default.promises.rm(file);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
}
|
|
56
59
|
} else if (options.quickstart) {
|
|
57
60
|
if (await app.isInstalled()) {
|
|
58
61
|
await app.upgrade();
|
|
@@ -379,7 +379,7 @@ const _PluginManager = class _PluginManager {
|
|
|
379
379
|
* @internal
|
|
380
380
|
*/
|
|
381
381
|
async loadCommands() {
|
|
382
|
-
this.app.log.
|
|
382
|
+
this.app.log.info("load commands");
|
|
383
383
|
const items = await this.repository.find({
|
|
384
384
|
filter: {
|
|
385
385
|
enabled: true
|
|
@@ -388,21 +388,15 @@ const _PluginManager = class _PluginManager {
|
|
|
388
388
|
const packageNames = items.map((item) => item.packageName);
|
|
389
389
|
const source = [];
|
|
390
390
|
for (const packageName of packageNames) {
|
|
391
|
-
const
|
|
392
|
-
const
|
|
393
|
-
const directory = (0, import_path.join)(
|
|
394
|
-
packageName,
|
|
395
|
-
sourceDir,
|
|
396
|
-
"server/commands/*." + ((0, import_path.basename)((0, import_path.dirname)(file)) === "src" ? "ts" : "js")
|
|
397
|
-
);
|
|
391
|
+
const dirname = await (0, import_utils2.getPluginBasePath)(packageName);
|
|
392
|
+
const directory = (0, import_path.join)(dirname, "server/commands/*." + ((0, import_path.basename)(dirname) === "src" ? "ts" : "js"));
|
|
398
393
|
source.push(directory.replaceAll(import_path.sep, "/"));
|
|
399
394
|
}
|
|
400
395
|
for (const plugin of this.options.plugins || []) {
|
|
401
396
|
if (typeof plugin === "string") {
|
|
402
|
-
const packageName = await _PluginManager.
|
|
403
|
-
const
|
|
404
|
-
const
|
|
405
|
-
const directory = (0, import_path.join)(packageName, sourceDir, "server/commands/*." + (sourceDir === "src" ? "ts" : "js"));
|
|
397
|
+
const { packageName } = await _PluginManager.parseName(plugin);
|
|
398
|
+
const dirname = await (0, import_utils2.getPluginBasePath)(packageName);
|
|
399
|
+
const directory = (0, import_path.join)(dirname, "server/commands/*." + ((0, import_path.basename)(dirname) === "src" ? "ts" : "js"));
|
|
406
400
|
source.push(directory.replaceAll(import_path.sep, "/"));
|
|
407
401
|
}
|
|
408
402
|
}
|
|
@@ -57,6 +57,7 @@ __export(utils_exports, {
|
|
|
57
57
|
getPackageJsonByLocalPath: () => getPackageJsonByLocalPath,
|
|
58
58
|
getPackageNameFromString: () => getPackageNameFromString,
|
|
59
59
|
getPackagesFromFiles: () => getPackagesFromFiles,
|
|
60
|
+
getPluginBasePath: () => getPluginBasePath,
|
|
60
61
|
getPluginInfoByNpm: () => getPluginInfoByNpm,
|
|
61
62
|
getPluginStoragePath: () => getPluginStoragePath,
|
|
62
63
|
getServerPackages: () => getServerPackages,
|
|
@@ -512,6 +513,21 @@ async function checkAndGetCompatible(packageName) {
|
|
|
512
513
|
};
|
|
513
514
|
}
|
|
514
515
|
__name(checkAndGetCompatible, "checkAndGetCompatible");
|
|
516
|
+
async function getPluginBasePath(packageName) {
|
|
517
|
+
if (!packageName) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
const file = await import_fs_extra.default.realpath(await (0, import_utils.requireResolve)(packageName));
|
|
521
|
+
try {
|
|
522
|
+
const basePath = await import_fs_extra.default.realpath(import_path.default.resolve(process.env.NODE_MODULES_PATH, packageName, "src"));
|
|
523
|
+
if (file.startsWith(basePath)) {
|
|
524
|
+
return basePath;
|
|
525
|
+
}
|
|
526
|
+
} catch (error) {
|
|
527
|
+
}
|
|
528
|
+
return import_path.default.dirname(import_path.default.dirname(file));
|
|
529
|
+
}
|
|
530
|
+
__name(getPluginBasePath, "getPluginBasePath");
|
|
515
531
|
// Annotate the CommonJS export names for ESM import in node:
|
|
516
532
|
0 && (module.exports = {
|
|
517
533
|
checkAndGetCompatible,
|
|
@@ -534,6 +550,7 @@ __name(checkAndGetCompatible, "checkAndGetCompatible");
|
|
|
534
550
|
getPackageJsonByLocalPath,
|
|
535
551
|
getPackageNameFromString,
|
|
536
552
|
getPackagesFromFiles,
|
|
553
|
+
getPluginBasePath,
|
|
537
554
|
getPluginInfoByNpm,
|
|
538
555
|
getPluginStoragePath,
|
|
539
556
|
getServerPackages,
|
package/lib/plugin.d.ts
CHANGED
|
@@ -73,10 +73,6 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
|
|
|
73
73
|
* @internal
|
|
74
74
|
*/
|
|
75
75
|
setOptions(options: any): void;
|
|
76
|
-
/**
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
loadCommands(): Promise<void>;
|
|
80
76
|
/**
|
|
81
77
|
* @internal
|
|
82
78
|
*/
|
|
@@ -85,6 +81,7 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
|
|
|
85
81
|
afterSync: any[];
|
|
86
82
|
afterLoad: any[];
|
|
87
83
|
}>;
|
|
84
|
+
private getPluginBasePath;
|
|
88
85
|
/**
|
|
89
86
|
* @internal
|
|
90
87
|
*/
|
|
@@ -98,13 +95,5 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
|
|
|
98
95
|
* @experimental
|
|
99
96
|
*/
|
|
100
97
|
toJSON(options?: any): Promise<any>;
|
|
101
|
-
/**
|
|
102
|
-
* @internal
|
|
103
|
-
*/
|
|
104
|
-
protected getSourceDir(): Promise<string>;
|
|
105
|
-
/**
|
|
106
|
-
* @internal
|
|
107
|
-
*/
|
|
108
|
-
protected isDev(): Promise<boolean>;
|
|
109
98
|
}
|
|
110
99
|
export default Plugin;
|
package/lib/plugin.js
CHANGED
|
@@ -43,7 +43,6 @@ __export(plugin_exports, {
|
|
|
43
43
|
module.exports = __toCommonJS(plugin_exports);
|
|
44
44
|
var import_utils = require("@nocobase/utils");
|
|
45
45
|
var import_fs = __toESM(require("fs"));
|
|
46
|
-
var import_glob = __toESM(require("glob"));
|
|
47
46
|
var import_path = require("path");
|
|
48
47
|
var import_plugin_manager = require("./plugin-manager");
|
|
49
48
|
var import_utils2 = require("./plugin-manager/utils");
|
|
@@ -136,45 +135,16 @@ const _Plugin = class _Plugin {
|
|
|
136
135
|
setOptions(options) {
|
|
137
136
|
this.options = options || {};
|
|
138
137
|
}
|
|
139
|
-
/**
|
|
140
|
-
* @internal
|
|
141
|
-
*/
|
|
142
|
-
async loadCommands() {
|
|
143
|
-
const extensions = ["js", "ts"];
|
|
144
|
-
const directory = (0, import_path.resolve)(
|
|
145
|
-
process.env.NODE_MODULES_PATH,
|
|
146
|
-
this.options.packageName,
|
|
147
|
-
await this.getSourceDir(),
|
|
148
|
-
"server/commands"
|
|
149
|
-
);
|
|
150
|
-
const patten = `${directory}/*.{${extensions.join(",")}}`;
|
|
151
|
-
const files = import_glob.default.sync(patten, {
|
|
152
|
-
ignore: ["**/*.d.ts"]
|
|
153
|
-
});
|
|
154
|
-
for (const file of files) {
|
|
155
|
-
let filename = (0, import_path.basename)(file);
|
|
156
|
-
filename = filename.substring(0, filename.lastIndexOf(".")) || filename;
|
|
157
|
-
const callback = await (0, import_utils.importModule)(file);
|
|
158
|
-
callback(this.app);
|
|
159
|
-
}
|
|
160
|
-
if (files.length) {
|
|
161
|
-
this.app.log.debug(`load commands [${this.name}]`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
138
|
/**
|
|
165
139
|
* @internal
|
|
166
140
|
*/
|
|
167
141
|
async loadMigrations() {
|
|
168
142
|
this.app.log.debug(`load plugin migrations [${this.name}]`);
|
|
169
|
-
|
|
143
|
+
const basePath = await this.getPluginBasePath();
|
|
144
|
+
if (!basePath) {
|
|
170
145
|
return { beforeLoad: [], afterSync: [], afterLoad: [] };
|
|
171
146
|
}
|
|
172
|
-
const directory = (0, import_path.resolve)(
|
|
173
|
-
process.env.NODE_MODULES_PATH,
|
|
174
|
-
this.options.packageName,
|
|
175
|
-
await this.getSourceDir(),
|
|
176
|
-
"server/migrations"
|
|
177
|
-
);
|
|
147
|
+
const directory = (0, import_path.resolve)(basePath, "server/migrations");
|
|
178
148
|
return await this.app.loadMigrations({
|
|
179
149
|
directory,
|
|
180
150
|
namespace: this.options.packageName,
|
|
@@ -183,19 +153,21 @@ const _Plugin = class _Plugin {
|
|
|
183
153
|
}
|
|
184
154
|
});
|
|
185
155
|
}
|
|
156
|
+
async getPluginBasePath() {
|
|
157
|
+
if (!this.options.packageName) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
return (0, import_utils2.getPluginBasePath)(this.options.packageName);
|
|
161
|
+
}
|
|
186
162
|
/**
|
|
187
163
|
* @internal
|
|
188
164
|
*/
|
|
189
165
|
async loadCollections() {
|
|
190
|
-
|
|
166
|
+
const basePath = await this.getPluginBasePath();
|
|
167
|
+
if (!basePath) {
|
|
191
168
|
return;
|
|
192
169
|
}
|
|
193
|
-
const directory = (0, import_path.resolve)(
|
|
194
|
-
process.env.NODE_MODULES_PATH,
|
|
195
|
-
this.options.packageName,
|
|
196
|
-
await this.getSourceDir(),
|
|
197
|
-
"server/collections"
|
|
198
|
-
);
|
|
170
|
+
const directory = (0, import_path.resolve)(basePath, "server/collections");
|
|
199
171
|
if (await (0, import_utils.fsExists)(directory)) {
|
|
200
172
|
await this.db.import({
|
|
201
173
|
directory,
|
|
@@ -246,36 +218,6 @@ const _Plugin = class _Plugin {
|
|
|
246
218
|
}
|
|
247
219
|
return results;
|
|
248
220
|
}
|
|
249
|
-
/**
|
|
250
|
-
* @internal
|
|
251
|
-
*/
|
|
252
|
-
async getSourceDir() {
|
|
253
|
-
if (this._sourceDir) {
|
|
254
|
-
return this._sourceDir;
|
|
255
|
-
}
|
|
256
|
-
if (await this.isDev()) {
|
|
257
|
-
return this._sourceDir = "src";
|
|
258
|
-
}
|
|
259
|
-
if ((0, import_path.basename)(__dirname) === "src") {
|
|
260
|
-
return this._sourceDir = "src";
|
|
261
|
-
}
|
|
262
|
-
return this._sourceDir = this.isPreset ? "lib" : "dist";
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* @internal
|
|
266
|
-
*/
|
|
267
|
-
async isDev() {
|
|
268
|
-
if (!this.options.packageName) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
const file = await import_fs.default.promises.realpath(
|
|
272
|
-
(0, import_path.resolve)(process.env.NODE_MODULES_PATH || (0, import_path.resolve)(process.cwd(), "node_modules"), this.options.packageName)
|
|
273
|
-
);
|
|
274
|
-
if (file.startsWith((0, import_path.resolve)(process.cwd(), "packages"))) {
|
|
275
|
-
return !!process.env.IS_DEV_CMD;
|
|
276
|
-
}
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
221
|
};
|
|
280
222
|
__name(_Plugin, "Plugin");
|
|
281
223
|
let Plugin = _Plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.14",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
"@koa/cors": "^3.1.0",
|
|
11
11
|
"@koa/multer": "^3.0.2",
|
|
12
12
|
"@koa/router": "^9.4.0",
|
|
13
|
-
"@nocobase/acl": "1.0.0-alpha.
|
|
14
|
-
"@nocobase/actions": "1.0.0-alpha.
|
|
15
|
-
"@nocobase/auth": "1.0.0-alpha.
|
|
16
|
-
"@nocobase/cache": "1.0.0-alpha.
|
|
17
|
-
"@nocobase/data-source-manager": "1.0.0-alpha.
|
|
18
|
-
"@nocobase/database": "1.0.0-alpha.
|
|
19
|
-
"@nocobase/evaluators": "1.0.0-alpha.
|
|
20
|
-
"@nocobase/logger": "1.0.0-alpha.
|
|
21
|
-
"@nocobase/resourcer": "1.0.0-alpha.
|
|
22
|
-
"@nocobase/sdk": "1.0.0-alpha.
|
|
23
|
-
"@nocobase/telemetry": "1.0.0-alpha.
|
|
24
|
-
"@nocobase/utils": "1.0.0-alpha.
|
|
13
|
+
"@nocobase/acl": "1.0.0-alpha.14",
|
|
14
|
+
"@nocobase/actions": "1.0.0-alpha.14",
|
|
15
|
+
"@nocobase/auth": "1.0.0-alpha.14",
|
|
16
|
+
"@nocobase/cache": "1.0.0-alpha.14",
|
|
17
|
+
"@nocobase/data-source-manager": "1.0.0-alpha.14",
|
|
18
|
+
"@nocobase/database": "1.0.0-alpha.14",
|
|
19
|
+
"@nocobase/evaluators": "1.0.0-alpha.14",
|
|
20
|
+
"@nocobase/logger": "1.0.0-alpha.14",
|
|
21
|
+
"@nocobase/resourcer": "1.0.0-alpha.14",
|
|
22
|
+
"@nocobase/sdk": "1.0.0-alpha.14",
|
|
23
|
+
"@nocobase/telemetry": "1.0.0-alpha.14",
|
|
24
|
+
"@nocobase/utils": "1.0.0-alpha.14",
|
|
25
25
|
"@types/decompress": "4.2.4",
|
|
26
26
|
"@types/ini": "^1.3.31",
|
|
27
27
|
"@types/koa-send": "^4.1.3",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"@types/serve-handler": "^6.1.1",
|
|
55
55
|
"@types/ws": "^8.5.5"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "829078819e5b9720a4c2501c340a301315c0d029"
|
|
58
58
|
}
|