@nocobase/devtools 0.11.1-alpha.5 → 0.12.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/package.json +4 -3
- package/umiConfig.d.ts +4 -0
- package/umiConfig.js +81 -3
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@nocobase/build": "0.
|
|
8
|
+
"@nocobase/build": "0.12.0-alpha.2",
|
|
9
|
+
"@nocobase/client": "0.12.0-alpha.2",
|
|
9
10
|
"@testing-library/react": "^14.0.0",
|
|
10
11
|
"@types/jest": "^29.0.0",
|
|
11
12
|
"@types/koa": "^2.13.4",
|
|
@@ -52,5 +53,5 @@
|
|
|
52
53
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
53
54
|
"directory": "packages/core/devtools"
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "a95e9e2666f0318c955113a4735bc005a2c9a767"
|
|
56
57
|
}
|
package/umiConfig.d.ts
CHANGED
package/umiConfig.js
CHANGED
|
@@ -3,6 +3,7 @@ const { resolve, sep } = require('path');
|
|
|
3
3
|
const packageJson = require('./package.json');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const glob = require('glob');
|
|
6
|
+
const path = require('path');
|
|
6
7
|
|
|
7
8
|
console.log('VERSION: ', packageJson.version);
|
|
8
9
|
|
|
@@ -27,8 +28,8 @@ function getUmiConfig() {
|
|
|
27
28
|
|
|
28
29
|
return {
|
|
29
30
|
alias: getPackagePaths().reduce((memo, item) => {
|
|
30
|
-
memo[item[0]] = item[1]
|
|
31
|
-
return memo
|
|
31
|
+
memo[item[0]] = item[1];
|
|
32
|
+
return memo;
|
|
32
33
|
}, {}),
|
|
33
34
|
define: {
|
|
34
35
|
'process.env.API_BASE_URL': API_BASE_URL || API_BASE_PATH,
|
|
@@ -73,7 +74,10 @@ function getPackagePaths() {
|
|
|
73
74
|
const dirname = resolve(process.cwd(), file);
|
|
74
75
|
if (existsSync(dirname)) {
|
|
75
76
|
const re = new RegExp(dir.replace('*', '(.+)'));
|
|
76
|
-
const p = dirname
|
|
77
|
+
const p = dirname
|
|
78
|
+
.substring(process.cwd().length + 1)
|
|
79
|
+
.split(sep)
|
|
80
|
+
.join('/');
|
|
77
81
|
const match = re.exec(p);
|
|
78
82
|
pkgs.push([key.replace('*', match?.[1]), dirname]);
|
|
79
83
|
}
|
|
@@ -95,5 +99,79 @@ function resolveNocobasePackagesAlias(config) {
|
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
class IndexGenerator {
|
|
103
|
+
constructor(outputPath, pluginsPath) {
|
|
104
|
+
this.outputPath = outputPath;
|
|
105
|
+
this.pluginsPath = pluginsPath;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
generate() {
|
|
109
|
+
this.generatePluginIndex();
|
|
110
|
+
if (process.env.NODE_ENV === 'production') return;
|
|
111
|
+
this.pluginsPath.forEach((pluginPath) => {
|
|
112
|
+
if (!fs.existsSync(pluginPath)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
fs.watch(pluginPath, { recursive: false }, () => {
|
|
116
|
+
this.generatePluginIndex();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
generatePluginIndex() {
|
|
122
|
+
if (!fs.existsSync(this.outputPath)) {
|
|
123
|
+
fs.mkdirSync(path.dirname(this.outputPath), { recursive: true });
|
|
124
|
+
fs.writeFileSync(this.outputPath, 'export default {}');
|
|
125
|
+
}
|
|
126
|
+
const validPluginPaths = this.pluginsPath.filter((pluginPath) => fs.existsSync(pluginPath));
|
|
127
|
+
if (!validPluginPaths.length) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (process.env.NODE_ENV === 'production') {
|
|
131
|
+
fs.writeFileSync(this.outputPath, 'export default {}');
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const pluginInfo = validPluginPaths.map((pluginPath) => this.getContent(pluginPath));
|
|
135
|
+
const importContent = pluginInfo.map(({ indexContent }) => indexContent).join('\n');
|
|
136
|
+
const exportContent = pluginInfo.map(({ exportContent }) => exportContent).join('\n');
|
|
137
|
+
|
|
138
|
+
const fileContent = `${importContent}\n\nexport default {\n${exportContent}\n}`;
|
|
139
|
+
|
|
140
|
+
fs.writeFileSync(this.outputPath, fileContent);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getContent(pluginPath) {
|
|
144
|
+
const pluginFolders = fs.readdirSync(pluginPath);
|
|
145
|
+
const pluginImports = pluginFolders
|
|
146
|
+
.filter((folder) => {
|
|
147
|
+
const pluginPackageJsonPath = path.join(pluginPath, folder, 'package.json');
|
|
148
|
+
const pluginSrcClientPath = path.join(pluginPath, folder, 'src', 'client');
|
|
149
|
+
return fs.existsSync(pluginPackageJsonPath) && fs.existsSync(pluginSrcClientPath);
|
|
150
|
+
})
|
|
151
|
+
.map((folder, index) => {
|
|
152
|
+
const pluginPackageJsonPath = path.join(pluginPath, folder, 'package.json');
|
|
153
|
+
const pluginPackageJson = require(pluginPackageJsonPath);
|
|
154
|
+
const pluginSrcClientPath = path
|
|
155
|
+
.relative(path.dirname(this.outputPath), path.join(pluginPath, folder, 'src', 'client'))
|
|
156
|
+
.replaceAll('\\', '/');
|
|
157
|
+
const pluginName = `${folder.replaceAll('-', '_')}${index}`;
|
|
158
|
+
const importStatement = `const ${pluginName} = import('${pluginSrcClientPath}');`;
|
|
159
|
+
return { importStatement, pluginName, packageJsonName: pluginPackageJson.name };
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const indexContent = pluginImports.map(({ importStatement }) => importStatement).join('\n');
|
|
163
|
+
|
|
164
|
+
const exportContent = pluginImports
|
|
165
|
+
.map(({ pluginName, packageJsonName }) => ` "${packageJsonName}": ${pluginName},`)
|
|
166
|
+
.join('\n');
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
indexContent,
|
|
170
|
+
exportContent,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
98
175
|
exports.getUmiConfig = getUmiConfig;
|
|
99
176
|
exports.resolveNocobasePackagesAlias = resolveNocobasePackagesAlias;
|
|
177
|
+
exports.IndexGenerator = IndexGenerator;
|