@nocobase/devtools 2.1.0-beta.15 → 2.1.0-beta.16
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/common.d.ts +10 -0
- package/common.js +212 -0
- package/package.json +11 -5
- package/rsbuildConfig.d.ts +3 -0
- package/rsbuildConfig.js +12 -0
- package/umiConfig.d.ts +1 -6
- package/umiConfig.js +38 -198
package/common.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function getPackagePaths(): [string, string][];
|
|
2
|
+
|
|
3
|
+
export declare class IndexGenerator {
|
|
4
|
+
constructor(outputPath: string, pluginsPath: string[]);
|
|
5
|
+
generate(): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare function generatePlugins(): void;
|
|
9
|
+
export declare function generateV2Plugins(): void;
|
|
10
|
+
export declare function generateAllPlugins(): void;
|
package/common.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
const { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } = require('node:fs');
|
|
2
|
+
const { dirname, join, relative, resolve, sep } = require('node:path');
|
|
3
|
+
const glob = require('fast-glob');
|
|
4
|
+
const { resolvePluginStoragePath } = require('@nocobase/utils/plugin-symlink');
|
|
5
|
+
|
|
6
|
+
function getTsconfigPaths() {
|
|
7
|
+
const content = readFileSync(resolve(process.cwd(), 'tsconfig.paths.json'), 'utf-8');
|
|
8
|
+
const json = JSON.parse(content);
|
|
9
|
+
return json.compilerOptions.paths;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getPackagePaths() {
|
|
13
|
+
const paths = getTsconfigPaths();
|
|
14
|
+
const pkgs = [];
|
|
15
|
+
for (const key in paths) {
|
|
16
|
+
if (Object.hasOwnProperty.call(paths, key)) {
|
|
17
|
+
for (const dir of paths[key]) {
|
|
18
|
+
if (dir.includes('*')) {
|
|
19
|
+
const files = glob.sync(dir, { cwd: process.cwd(), onlyDirectories: true });
|
|
20
|
+
for (const file of files) {
|
|
21
|
+
const dirname = resolve(process.cwd(), file);
|
|
22
|
+
if (existsSync(dirname)) {
|
|
23
|
+
const re = new RegExp(dir.replace('*', '(.+)'));
|
|
24
|
+
const normalized = dirname
|
|
25
|
+
.substring(process.cwd().length + 1)
|
|
26
|
+
.split(sep)
|
|
27
|
+
.join('/');
|
|
28
|
+
const match = re.exec(normalized);
|
|
29
|
+
pkgs.push([key.replace('*', match?.[1]), dirname]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
const dirname = resolve(process.cwd(), dir);
|
|
34
|
+
pkgs.push([key, dirname]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return pkgs;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getNodeModulesPath(packageDir) {
|
|
43
|
+
return join(process.cwd(), 'node_modules', packageDir);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class IndexGenerator {
|
|
47
|
+
nocobaseDir = getNodeModulesPath('@nocobase');
|
|
48
|
+
|
|
49
|
+
constructor(outputPath, pluginsPath, options = {}) {
|
|
50
|
+
this.outputPath = outputPath;
|
|
51
|
+
this.pluginsPath = pluginsPath;
|
|
52
|
+
this.options = {
|
|
53
|
+
clientModuleName: 'client',
|
|
54
|
+
clientRootFile: 'client.js',
|
|
55
|
+
clientSourceDir: 'client',
|
|
56
|
+
...options,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get indexPath() {
|
|
61
|
+
return join(this.outputPath, 'index.ts');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get packageMapPath() {
|
|
65
|
+
return join(this.outputPath, 'packageMap.json');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get packagesPath() {
|
|
69
|
+
return join(this.outputPath, 'packages');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
generate() {
|
|
73
|
+
this.generatePluginContent();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get indexContent() {
|
|
77
|
+
return `// @ts-nocheck
|
|
78
|
+
import packageMap from './packageMap.json';
|
|
79
|
+
|
|
80
|
+
function devDynamicImport(packageName: string): Promise<any> {
|
|
81
|
+
const fileName = packageMap[packageName];
|
|
82
|
+
if (!fileName) {
|
|
83
|
+
return Promise.resolve(null);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return import(\`./packages/\${fileName}\`)
|
|
87
|
+
} catch (error) {
|
|
88
|
+
return Promise.resolve(null);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export default devDynamicImport;`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get emptyIndexContent() {
|
|
95
|
+
return `
|
|
96
|
+
export default function devDynamicImport(packageName: string): Promise<any> {
|
|
97
|
+
return Promise.resolve(null);
|
|
98
|
+
}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
generatePluginContent() {
|
|
102
|
+
if (existsSync(this.outputPath)) {
|
|
103
|
+
rmSync(this.outputPath, { recursive: true, force: true });
|
|
104
|
+
}
|
|
105
|
+
mkdirSync(this.outputPath, { recursive: true });
|
|
106
|
+
const validPluginPaths = this.pluginsPath.filter((pluginsPath) => existsSync(pluginsPath));
|
|
107
|
+
if (!validPluginPaths.length || process.env.NODE_ENV === 'production') {
|
|
108
|
+
writeFileSync(this.indexPath, this.emptyIndexContent);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const pluginInfos = validPluginPaths.map((pluginsPath) => this.getContent(pluginsPath)).flat();
|
|
113
|
+
|
|
114
|
+
writeFileSync(this.indexPath, this.indexContent);
|
|
115
|
+
const packageMapContent = pluginInfos.reduce((memo, item) => {
|
|
116
|
+
memo[item.packageJsonName] = `${item.pluginFileName}.ts`;
|
|
117
|
+
return memo;
|
|
118
|
+
}, {});
|
|
119
|
+
writeFileSync(this.packageMapPath, JSON.stringify(packageMapContent, null, 2));
|
|
120
|
+
mkdirSync(this.packagesPath, { recursive: true });
|
|
121
|
+
pluginInfos.forEach((item) => {
|
|
122
|
+
const pluginPackagePath = join(this.packagesPath, `${item.pluginFileName}.ts`);
|
|
123
|
+
writeFileSync(pluginPackagePath, item.exportStatement);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getContent(pluginsPath) {
|
|
128
|
+
const pluginFolders = glob.sync(['*/package.json', '*/*/package.json'], {
|
|
129
|
+
cwd: pluginsPath,
|
|
130
|
+
onlyFiles: true,
|
|
131
|
+
absolute: true,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const storagePluginFolders = glob.sync(['*/package.json', '*/*/package.json'], {
|
|
135
|
+
cwd: resolvePluginStoragePath(),
|
|
136
|
+
onlyFiles: true,
|
|
137
|
+
absolute: true,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const nocobasePluginFolders = glob
|
|
141
|
+
.sync(['plugin-*/package.json'], { cwd: this.nocobaseDir, onlyFiles: true, absolute: true })
|
|
142
|
+
.map((item) => realpathSync(item));
|
|
143
|
+
|
|
144
|
+
return Array.from(new Set([...pluginFolders, ...storagePluginFolders, ...nocobasePluginFolders]))
|
|
145
|
+
.filter((item) => {
|
|
146
|
+
const pluginDir = dirname(item);
|
|
147
|
+
const clientJs = join(pluginDir, this.options.clientRootFile);
|
|
148
|
+
return existsSync(clientJs);
|
|
149
|
+
})
|
|
150
|
+
.map((pluginPackageJsonPath) => {
|
|
151
|
+
const pluginPackageJson = require(pluginPackageJsonPath);
|
|
152
|
+
const pluginPathArr = pluginPackageJsonPath.replaceAll(sep, '/').split('/');
|
|
153
|
+
const hasNamespace = pluginPathArr[pluginPathArr.length - 3].startsWith('@');
|
|
154
|
+
const pluginFileName = (hasNamespace
|
|
155
|
+
? `${pluginPathArr[pluginPathArr.length - 3].replace('@', '')}_${pluginPathArr[pluginPathArr.length - 2]}`
|
|
156
|
+
: pluginPathArr[pluginPathArr.length - 2]
|
|
157
|
+
).replaceAll('-', '_');
|
|
158
|
+
|
|
159
|
+
let exportStatement = '';
|
|
160
|
+
if (pluginPackageJsonPath.includes('packages')) {
|
|
161
|
+
const pluginSrcClientPath = relative(
|
|
162
|
+
this.packagesPath,
|
|
163
|
+
join(dirname(pluginPackageJsonPath), 'src', this.options.clientSourceDir),
|
|
164
|
+
).replaceAll(sep, '/');
|
|
165
|
+
exportStatement = `export { default } from '${pluginSrcClientPath}';`;
|
|
166
|
+
} else {
|
|
167
|
+
exportStatement = `export { default } from '${pluginPackageJson.name}/${this.options.clientModuleName}';`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return { exportStatement, pluginFileName, packageJsonName: pluginPackageJson.name };
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function getPluginDirs() {
|
|
176
|
+
return (process.env.PLUGIN_PATH || 'packages/plugins/,packages/samples/,packages/pro-plugins/')
|
|
177
|
+
.split(',')
|
|
178
|
+
.map((item) => join(process.cwd(), item));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function generatePluginsByOutputPath(outputPluginPath, options = {}) {
|
|
182
|
+
const pluginDirs = getPluginDirs();
|
|
183
|
+
const indexGenerator = new IndexGenerator(outputPluginPath, pluginDirs, options);
|
|
184
|
+
indexGenerator.generate();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function generatePlugins() {
|
|
188
|
+
generatePluginsByOutputPath(join(process.env.APP_PACKAGE_ROOT, 'client', 'src', '.plugins'));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function generateV2Plugins() {
|
|
192
|
+
generatePluginsByOutputPath(join(process.env.APP_PACKAGE_ROOT, 'client-v2', 'src', '.plugins'), {
|
|
193
|
+
clientModuleName: 'client-v2',
|
|
194
|
+
clientRootFile: 'client-v2.js',
|
|
195
|
+
clientSourceDir: 'client-v2',
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function generateAllPlugins() {
|
|
200
|
+
[
|
|
201
|
+
join(process.env.APP_PACKAGE_ROOT, 'client', 'src', '.plugins'),
|
|
202
|
+
join(process.env.APP_PACKAGE_ROOT, 'client-v2', 'src', '.plugins'),
|
|
203
|
+
].forEach((outputPluginPath) => {
|
|
204
|
+
generatePluginsByOutputPath(outputPluginPath);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
exports.getPackagePaths = getPackagePaths;
|
|
209
|
+
exports.IndexGenerator = IndexGenerator;
|
|
210
|
+
exports.generatePlugins = generatePlugins;
|
|
211
|
+
exports.generateV2Plugins = generateV2Plugins;
|
|
212
|
+
exports.generateAllPlugins = generateAllPlugins;
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/devtools",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@nocobase/build": "2.1.0-beta.
|
|
9
|
-
"@nocobase/client": "2.1.0-beta.
|
|
10
|
-
"@nocobase/test": "2.1.0-beta.
|
|
8
|
+
"@nocobase/build": "2.1.0-beta.16",
|
|
9
|
+
"@nocobase/client": "2.1.0-beta.16",
|
|
10
|
+
"@nocobase/test": "2.1.0-beta.16",
|
|
11
|
+
"@nocobase/utils": "2.1.0-beta.16",
|
|
12
|
+
"@rsbuild/core": "1.7.3",
|
|
13
|
+
"@rsbuild/plugin-less": "^1.6.2",
|
|
14
|
+
"@rsbuild/plugin-node-polyfill": "1.4.4",
|
|
15
|
+
"@rsbuild/plugin-react": "1.4.6",
|
|
16
|
+
"@rsbuild/plugin-svgr": "^1.3.1",
|
|
11
17
|
"@types/koa": "^2.15.0",
|
|
12
18
|
"@types/koa-bodyparser": "^4.3.4",
|
|
13
19
|
"@types/lodash": "^4.14.177",
|
|
@@ -50,5 +56,5 @@
|
|
|
50
56
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
51
57
|
"directory": "packages/core/devtools"
|
|
52
58
|
},
|
|
53
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "b9a191705a440a336c85d82fd877fdf152bec70f"
|
|
54
60
|
}
|
package/rsbuildConfig.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import common from './common.js';
|
|
2
|
+
|
|
3
|
+
const { getPackagePaths, generateV2Plugins, generatePlugins } = common;
|
|
4
|
+
|
|
5
|
+
export function getRsbuildAlias() {
|
|
6
|
+
return getPackagePaths().reduce((memo, item) => {
|
|
7
|
+
memo[item[0]] = item[1];
|
|
8
|
+
return memo;
|
|
9
|
+
}, {});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { generateV2Plugins, generatePlugins };
|
package/umiConfig.d.ts
CHANGED
|
@@ -20,9 +20,4 @@ export declare function getUmiConfig(): {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export declare function resolveNocobasePackagesAlias(config: any): {};
|
|
23
|
-
export
|
|
24
|
-
constructor(outputPath: string, pluginsPath: string[]): void;
|
|
25
|
-
generate(): void;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export declare function generatePlugins(): {}
|
|
23
|
+
export { IndexGenerator, generateAllPlugins, generatePlugins } from './common.js';
|
package/umiConfig.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
const { existsSync } = require('fs');
|
|
2
|
-
const { resolve, sep } = require('path');
|
|
3
1
|
const packageJson = require('./package.json');
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const path = require('path');
|
|
2
|
+
const { resolvePublicPath, resolveV2PublicPath } = require('../cli-v1/src/util');
|
|
3
|
+
const { getPackagePaths, IndexGenerator, generatePlugins, generateAllPlugins } = require('./common.js');
|
|
7
4
|
|
|
8
5
|
console.log('VERSION: ', packageJson.version);
|
|
9
6
|
|
|
10
7
|
function getUmiConfig() {
|
|
11
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
APP_PORT,
|
|
10
|
+
APP_V2_PORT,
|
|
11
|
+
API_BASE_URL,
|
|
12
|
+
API_CLIENT_STORAGE_TYPE,
|
|
13
|
+
API_CLIENT_STORAGE_PREFIX,
|
|
14
|
+
APP_PUBLIC_PATH,
|
|
15
|
+
} = process.env;
|
|
12
16
|
const API_BASE_PATH = process.env.API_BASE_PATH || '/api/';
|
|
17
|
+
const normalizedAppPublicPath = resolvePublicPath(APP_PUBLIC_PATH || '/');
|
|
18
|
+
const V2_PUBLIC_PATH = resolveV2PublicPath(APP_PUBLIC_PATH || '/');
|
|
13
19
|
const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${APP_PORT}`;
|
|
14
20
|
const LOCAL_STORAGE_BASE_URL = 'storage/uploads/';
|
|
15
21
|
const STATIC_PATH = 'static/';
|
|
@@ -20,17 +26,37 @@ function getUmiConfig() {
|
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
return {
|
|
23
|
-
[
|
|
29
|
+
[normalizedAppPublicPath + LOCAL_STORAGE_BASE_URL]: {
|
|
24
30
|
target: PROXY_TARGET_URL,
|
|
25
31
|
changeOrigin: true,
|
|
26
32
|
},
|
|
27
|
-
[
|
|
33
|
+
[normalizedAppPublicPath + STATIC_PATH]: {
|
|
28
34
|
target: PROXY_TARGET_URL,
|
|
29
35
|
changeOrigin: true,
|
|
30
36
|
},
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
|
|
40
|
+
function getClientV2Proxy() {
|
|
41
|
+
if (!APP_V2_PORT) {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
[V2_PUBLIC_PATH]: {
|
|
47
|
+
target: `http://127.0.0.1:${APP_V2_PORT}`,
|
|
48
|
+
changeOrigin: true,
|
|
49
|
+
ws: true,
|
|
50
|
+
pathRewrite: { [`^${V2_PUBLIC_PATH}`]: V2_PUBLIC_PATH },
|
|
51
|
+
onProxyReq: (proxyReq, req, res) => {
|
|
52
|
+
if (req?.ip) {
|
|
53
|
+
proxyReq.setHeader('X-Forwarded-For', req.ip);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
34
60
|
return {
|
|
35
61
|
alias: getPackagePaths().reduce((memo, item) => {
|
|
36
62
|
memo[item[0]] = item[1];
|
|
@@ -72,52 +98,12 @@ function getUmiConfig() {
|
|
|
72
98
|
},
|
|
73
99
|
// for local storage
|
|
74
100
|
...getLocalStorageProxy(),
|
|
101
|
+
// v2 shell dev server proxy
|
|
102
|
+
...getClientV2Proxy(),
|
|
75
103
|
},
|
|
76
104
|
};
|
|
77
105
|
}
|
|
78
106
|
|
|
79
|
-
function getNamespace() {
|
|
80
|
-
const content = fs.readFileSync(resolve(process.cwd(), 'package.json'), 'utf-8');
|
|
81
|
-
const json = JSON.parse(content);
|
|
82
|
-
return json.name;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function getTsconfigPaths() {
|
|
86
|
-
const content = fs.readFileSync(resolve(process.cwd(), 'tsconfig.paths.json'), 'utf-8');
|
|
87
|
-
const json = JSON.parse(content);
|
|
88
|
-
return json.compilerOptions.paths;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function getPackagePaths() {
|
|
92
|
-
const paths = getTsconfigPaths();
|
|
93
|
-
const pkgs = [];
|
|
94
|
-
for (const key in paths) {
|
|
95
|
-
if (Object.hasOwnProperty.call(paths, key)) {
|
|
96
|
-
for (let dir of paths[key]) {
|
|
97
|
-
if (dir.includes('*')) {
|
|
98
|
-
const files = glob.sync(dir, { cwd: process.cwd(), onlyDirectories: true });
|
|
99
|
-
for (const file of files) {
|
|
100
|
-
const dirname = resolve(process.cwd(), file);
|
|
101
|
-
if (existsSync(dirname)) {
|
|
102
|
-
const re = new RegExp(dir.replace('*', '(.+)'));
|
|
103
|
-
const p = dirname
|
|
104
|
-
.substring(process.cwd().length + 1)
|
|
105
|
-
.split(sep)
|
|
106
|
-
.join('/');
|
|
107
|
-
const match = re.exec(p);
|
|
108
|
-
pkgs.push([key.replace('*', match?.[1]), dirname]);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
const dirname = resolve(process.cwd(), dir);
|
|
113
|
-
pkgs.push([key, dirname]);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return pkgs;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
107
|
function resolveNocobasePackagesAlias(config) {
|
|
122
108
|
const pkgs = getPackagePaths();
|
|
123
109
|
for (const [pkg, dir] of pkgs) {
|
|
@@ -126,154 +112,8 @@ function resolveNocobasePackagesAlias(config) {
|
|
|
126
112
|
}
|
|
127
113
|
}
|
|
128
114
|
|
|
129
|
-
function getNodeModulesPath(packageDir) {
|
|
130
|
-
const node_modules_dir = path.join(process.cwd(), 'node_modules');
|
|
131
|
-
return path.join(node_modules_dir, packageDir);
|
|
132
|
-
}
|
|
133
|
-
class IndexGenerator {
|
|
134
|
-
nocobaseDir = getNodeModulesPath('@nocobase');
|
|
135
|
-
|
|
136
|
-
constructor(outputPath, pluginsPath) {
|
|
137
|
-
this.outputPath = outputPath;
|
|
138
|
-
this.pluginsPath = pluginsPath;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
get indexPath() {
|
|
142
|
-
return path.join(this.outputPath, 'index.ts');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
get packageMapPath() {
|
|
146
|
-
return path.join(this.outputPath, 'packageMap.json');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
get packagesPath() {
|
|
150
|
-
return path.join(this.outputPath, 'packages');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
generate() {
|
|
154
|
-
this.generatePluginContent();
|
|
155
|
-
if (process.env.NODE_ENV === 'production') return;
|
|
156
|
-
// this.pluginsPath.forEach((pluginPath) => {
|
|
157
|
-
// if (!fs.existsSync(pluginPath)) {
|
|
158
|
-
// return;
|
|
159
|
-
// }
|
|
160
|
-
// fs.watch(pluginPath, { recursive: false }, () => {
|
|
161
|
-
// this.generatePluginContent();
|
|
162
|
-
// });
|
|
163
|
-
// });
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
get indexContent() {
|
|
167
|
-
return `// @ts-nocheck
|
|
168
|
-
import packageMap from './packageMap.json';
|
|
169
|
-
|
|
170
|
-
function devDynamicImport(packageName: string): Promise<any> {
|
|
171
|
-
const fileName = packageMap[packageName];
|
|
172
|
-
if (!fileName) {
|
|
173
|
-
return Promise.resolve(null);
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
return import(\`./packages/\${fileName}\`)
|
|
177
|
-
} catch (error) {
|
|
178
|
-
return Promise.resolve(null);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
export default devDynamicImport;`;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
get emptyIndexContent() {
|
|
185
|
-
return `
|
|
186
|
-
export default function devDynamicImport(packageName: string): Promise<any> {
|
|
187
|
-
return Promise.resolve(null);
|
|
188
|
-
}`;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
generatePluginContent() {
|
|
192
|
-
if (fs.existsSync(this.outputPath)) {
|
|
193
|
-
fs.rmSync(this.outputPath, { recursive: true, force: true });
|
|
194
|
-
}
|
|
195
|
-
fs.mkdirSync(this.outputPath, { recursive: true, force: true });
|
|
196
|
-
const validPluginPaths = this.pluginsPath.filter((pluginsPath) => fs.existsSync(pluginsPath));
|
|
197
|
-
if (!validPluginPaths.length || process.env.NODE_ENV === 'production') {
|
|
198
|
-
fs.writeFileSync(this.indexPath, this.emptyIndexContent);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const pluginInfos = validPluginPaths.map((pluginsPath) => this.getContent(pluginsPath)).flat();
|
|
203
|
-
|
|
204
|
-
// index.ts
|
|
205
|
-
fs.writeFileSync(this.indexPath, this.indexContent);
|
|
206
|
-
// packageMap.json
|
|
207
|
-
const packageMapContent = pluginInfos.reduce((memo, item) => {
|
|
208
|
-
memo[item.packageJsonName] = item.pluginFileName + '.ts';
|
|
209
|
-
return memo;
|
|
210
|
-
}, {});
|
|
211
|
-
fs.writeFileSync(this.packageMapPath, JSON.stringify(packageMapContent, null, 2));
|
|
212
|
-
// packages
|
|
213
|
-
fs.mkdirSync(this.packagesPath, { recursive: true });
|
|
214
|
-
pluginInfos.forEach((item) => {
|
|
215
|
-
const pluginPackagePath = path.join(this.packagesPath, item.pluginFileName + '.ts');
|
|
216
|
-
fs.writeFileSync(pluginPackagePath, item.exportStatement);
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
getContent(pluginsPath) {
|
|
221
|
-
const pluginFolders = glob.sync(['*/package.json', '*/*/package.json'], {
|
|
222
|
-
cwd: pluginsPath,
|
|
223
|
-
onlyFiles: true,
|
|
224
|
-
absolute: true,
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
const storagePluginFolders = glob.sync(['*/package.json', '*/*/package.json'], {
|
|
228
|
-
cwd: process.env.PLUGIN_STORAGE_PATH,
|
|
229
|
-
onlyFiles: true,
|
|
230
|
-
absolute: true,
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const nocobasePluginFolders = glob
|
|
234
|
-
.sync(['plugin-*/package.json'], { cwd: this.nocobaseDir, onlyFiles: true, absolute: true })
|
|
235
|
-
.map((item) => fs.realpathSync(item));
|
|
236
|
-
const pluginInfos = Array.from(new Set([...pluginFolders, ...storagePluginFolders, ...nocobasePluginFolders]))
|
|
237
|
-
.filter((item) => {
|
|
238
|
-
const dirname = path.dirname(item);
|
|
239
|
-
const clientJs = path.join(dirname, 'client.js');
|
|
240
|
-
return fs.existsSync(clientJs);
|
|
241
|
-
})
|
|
242
|
-
.map((pluginPackageJsonPath) => {
|
|
243
|
-
const pluginPackageJson = require(pluginPackageJsonPath);
|
|
244
|
-
const pluginPathArr = pluginPackageJsonPath.replaceAll(path.sep, '/').split('/');
|
|
245
|
-
const hasNamespace = pluginPathArr[pluginPathArr.length - 3].startsWith('@');
|
|
246
|
-
const pluginFileName = (hasNamespace
|
|
247
|
-
? `${pluginPathArr[pluginPathArr.length - 3].replace('@', '')}_${pluginPathArr[pluginPathArr.length - 2]}`
|
|
248
|
-
: pluginPathArr[pluginPathArr.length - 2]
|
|
249
|
-
).replaceAll('-', '_');
|
|
250
|
-
|
|
251
|
-
let exportStatement = '';
|
|
252
|
-
if (pluginPackageJsonPath.includes('packages')) {
|
|
253
|
-
const pluginSrcClientPath = path
|
|
254
|
-
.relative(this.packagesPath, path.join(path.dirname(pluginPackageJsonPath), 'src', 'client'))
|
|
255
|
-
.replaceAll(path.sep, '/');
|
|
256
|
-
exportStatement = `export { default } from '${pluginSrcClientPath}';`;
|
|
257
|
-
} else {
|
|
258
|
-
exportStatement = `export { default } from '${pluginPackageJson.name}/client';`;
|
|
259
|
-
}
|
|
260
|
-
return { exportStatement, pluginFileName, packageJsonName: pluginPackageJson.name };
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
return pluginInfos;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
115
|
exports.getUmiConfig = getUmiConfig;
|
|
268
116
|
exports.resolveNocobasePackagesAlias = resolveNocobasePackagesAlias;
|
|
269
117
|
exports.IndexGenerator = IndexGenerator;
|
|
270
|
-
|
|
271
|
-
exports.
|
|
272
|
-
const pluginDirs = (process.env.PLUGIN_PATH || 'packages/plugins/,packages/samples/,packages/pro-plugins/')
|
|
273
|
-
.split(',')
|
|
274
|
-
.map((item) => path.join(process.cwd(), item));
|
|
275
|
-
|
|
276
|
-
const outputPluginPath = path.join(process.env.APP_PACKAGE_ROOT, 'client', 'src', '.plugins');
|
|
277
|
-
const indexGenerator = new IndexGenerator(outputPluginPath, pluginDirs);
|
|
278
|
-
indexGenerator.generate();
|
|
279
|
-
};
|
|
118
|
+
exports.generatePlugins = generatePlugins;
|
|
119
|
+
exports.generateAllPlugins = generateAllPlugins;
|