@nocobase/utils 0.13.0-alpha.9 → 0.14.0-alpha.2
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/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/server.d.ts +1 -0
- package/lib/server.js +3 -1
- package/package.json +2 -2
- package/plugin-symlink.d.ts +5 -0
- package/plugin-symlink.js +87 -0
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -52,6 +52,7 @@ __reExport(src_exports, require("./registry"), module.exports);
|
|
|
52
52
|
__reExport(src_exports, require("./requireModule"), module.exports);
|
|
53
53
|
__reExport(src_exports, require("./toposort"), module.exports);
|
|
54
54
|
__reExport(src_exports, require("./uid"), module.exports);
|
|
55
|
+
__reExport(src_exports, require("./url"), module.exports);
|
|
55
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
57
|
0 && (module.exports = {
|
|
57
58
|
dayjs,
|
|
@@ -73,5 +74,6 @@ __reExport(src_exports, require("./uid"), module.exports);
|
|
|
73
74
|
...require("./registry"),
|
|
74
75
|
...require("./requireModule"),
|
|
75
76
|
...require("./toposort"),
|
|
76
|
-
...require("./uid")
|
|
77
|
+
...require("./uid"),
|
|
78
|
+
...require("./url")
|
|
77
79
|
});
|
package/lib/server.d.ts
CHANGED
package/lib/server.js
CHANGED
|
@@ -23,6 +23,7 @@ __reExport(server_exports, require("./registry"), module.exports);
|
|
|
23
23
|
__reExport(server_exports, require("./requireModule"), module.exports);
|
|
24
24
|
__reExport(server_exports, require("./toposort"), module.exports);
|
|
25
25
|
__reExport(server_exports, require("./uid"), module.exports);
|
|
26
|
+
__reExport(server_exports, require("./url"), module.exports);
|
|
26
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
28
|
0 && (module.exports = {
|
|
28
29
|
...require("./date"),
|
|
@@ -33,5 +34,6 @@ __reExport(server_exports, require("./uid"), module.exports);
|
|
|
33
34
|
...require("./registry"),
|
|
34
35
|
...require("./requireModule"),
|
|
35
36
|
...require("./toposort"),
|
|
36
|
-
...require("./uid")
|
|
37
|
+
...require("./uid"),
|
|
38
|
+
...require("./url")
|
|
37
39
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0-alpha.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
"multer": "^1.4.5-lts.1",
|
|
16
16
|
"object-path": "^0.11.8"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "ea841d4a1e8c37aa77b4fbae6a6a4937e2aa3c0a"
|
|
19
19
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getStoragePluginNames(target: any): Promise<any[]>;
|
|
2
|
+
export declare function fsExists(path: any): Promise<boolean>;
|
|
3
|
+
export declare function createStoragePluginSymLink(pluginName: any): Promise<void>;
|
|
4
|
+
export declare function createStoragePluginsSymlink(): Promise<void>;
|
|
5
|
+
export declare function createDevPluginSymLink(pluginName: any): Promise<void>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const { dirname, resolve } = require('path');
|
|
2
|
+
const { readFile, writeFile, readdir, symlink, unlink, mkdir, stat } = require('fs').promises;
|
|
3
|
+
|
|
4
|
+
async function getStoragePluginNames(target) {
|
|
5
|
+
const plugins = [];
|
|
6
|
+
const items = await readdir(target);
|
|
7
|
+
for (const item of items) {
|
|
8
|
+
if (item.startsWith('@')) {
|
|
9
|
+
const children = await getStoragePluginNames(resolve(target, item));
|
|
10
|
+
plugins.push(
|
|
11
|
+
...children.map((child) => {
|
|
12
|
+
return `${item}/${child}`;
|
|
13
|
+
}),
|
|
14
|
+
);
|
|
15
|
+
} else if (await fsExists(resolve(target, item, 'package.json'))) {
|
|
16
|
+
plugins.push(item);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return plugins;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function fsExists(path) {
|
|
23
|
+
try {
|
|
24
|
+
await stat(path);
|
|
25
|
+
return true;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.fsExists = fsExists;
|
|
32
|
+
|
|
33
|
+
async function createStoragePluginSymLink(pluginName) {
|
|
34
|
+
const storagePluginsPath = resolve(process.cwd(), 'storage/plugins');
|
|
35
|
+
const nodeModulesPath = process.env.NODE_MODULES_PATH; // resolve(dirname(require.resolve('@nocobase/server/package.json')), 'node_modules');
|
|
36
|
+
// const nodeModulesPath = resolve(process.cwd(), 'node_modules');
|
|
37
|
+
try {
|
|
38
|
+
if (pluginName.startsWith('@')) {
|
|
39
|
+
const [orgName] = pluginName.split('/');
|
|
40
|
+
if (!(await fsExists(resolve(nodeModulesPath, orgName)))) {
|
|
41
|
+
await mkdir(resolve(nodeModulesPath, orgName), { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const link = resolve(nodeModulesPath, pluginName);
|
|
45
|
+
if (await fsExists(link)) {
|
|
46
|
+
await unlink(link);
|
|
47
|
+
}
|
|
48
|
+
await symlink(resolve(storagePluginsPath, pluginName), link);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.createStoragePluginSymLink = createStoragePluginSymLink;
|
|
55
|
+
|
|
56
|
+
async function createStoragePluginsSymlink() {
|
|
57
|
+
const storagePluginsPath = resolve(process.cwd(), 'storage/plugins');
|
|
58
|
+
if (!(await fsExists(storagePluginsPath))) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const pluginNames = await getStoragePluginNames(storagePluginsPath);
|
|
62
|
+
await Promise.all(pluginNames.map((pluginName) => createStoragePluginSymLink(pluginName)));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.createStoragePluginsSymlink = createStoragePluginsSymlink;
|
|
66
|
+
|
|
67
|
+
async function createDevPluginSymLink(pluginName) {
|
|
68
|
+
const packagePluginsPath = resolve(process.cwd(), 'packages/plugins');
|
|
69
|
+
const nodeModulesPath = process.env.NODE_MODULES_PATH; // resolve(dirname(require.resolve('@nocobase/server/package.json')), 'node_modules');
|
|
70
|
+
try {
|
|
71
|
+
if (pluginName.startsWith('@')) {
|
|
72
|
+
const [orgName] = pluginName.split('/');
|
|
73
|
+
if (!(await fsExists(resolve(nodeModulesPath, orgName)))) {
|
|
74
|
+
await mkdir(resolve(nodeModulesPath, orgName), { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const link = resolve(nodeModulesPath, pluginName);
|
|
78
|
+
if (await fsExists(link)) {
|
|
79
|
+
await unlink(link);
|
|
80
|
+
}
|
|
81
|
+
await symlink(resolve(packagePluginsPath, pluginName), link);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.createDevPluginSymLink = createDevPluginSymLink;
|