@nocobase/devtools 0.12.0-alpha.5 → 0.13.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/index.js +0 -0
- package/package.json +4 -4
- package/umiConfig.js +64 -32
package/lib/index.js
ADDED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0-alpha.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@nocobase/build": "0.
|
|
9
|
-
"@nocobase/client": "0.
|
|
8
|
+
"@nocobase/build": "0.13.0-alpha.10",
|
|
9
|
+
"@nocobase/client": "0.13.0-alpha.10",
|
|
10
10
|
"@testing-library/react": "^14.0.0",
|
|
11
11
|
"@types/jest": "^29.0.0",
|
|
12
12
|
"@types/koa": "^2.13.4",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
54
54
|
"directory": "packages/core/devtools"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "5360ed81650f6895f3ed39aede2706467d55862c"
|
|
57
57
|
}
|
package/umiConfig.js
CHANGED
|
@@ -35,6 +35,7 @@ function getUmiConfig() {
|
|
|
35
35
|
'process.env.API_BASE_URL': API_BASE_URL || API_BASE_PATH,
|
|
36
36
|
'process.env.APP_ENV': process.env.APP_ENV,
|
|
37
37
|
'process.env.VERSION': packageJson.version,
|
|
38
|
+
'process.env.WEBSOCKET_URL': process.env.WEBSOCKET_URL,
|
|
38
39
|
},
|
|
39
40
|
// only proxy when using `umi dev`
|
|
40
41
|
// if the assets are built, will not proxy
|
|
@@ -105,70 +106,101 @@ class IndexGenerator {
|
|
|
105
106
|
this.pluginsPath = pluginsPath;
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
get indexPath() {
|
|
110
|
+
return path.join(this.outputPath, 'index.ts');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get packageMapPath() {
|
|
114
|
+
return path.join(this.outputPath, 'packageMap.json');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
get packagesPath() {
|
|
118
|
+
return path.join(this.outputPath, 'packages');
|
|
119
|
+
}
|
|
120
|
+
|
|
108
121
|
generate() {
|
|
109
|
-
this.
|
|
122
|
+
this.generatePluginContent();
|
|
110
123
|
if (process.env.NODE_ENV === 'production') return;
|
|
111
124
|
this.pluginsPath.forEach((pluginPath) => {
|
|
112
125
|
if (!fs.existsSync(pluginPath)) {
|
|
113
126
|
return;
|
|
114
127
|
}
|
|
115
128
|
fs.watch(pluginPath, { recursive: false }, () => {
|
|
116
|
-
this.
|
|
129
|
+
this.generatePluginContent();
|
|
117
130
|
});
|
|
118
131
|
});
|
|
119
132
|
}
|
|
120
133
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
134
|
+
get indexContent() {
|
|
135
|
+
return `// @ts-nocheck
|
|
136
|
+
import packageMap from './packageMap.json';
|
|
137
|
+
|
|
138
|
+
function devDynamicImport(packageName: string): Promise<any> {
|
|
139
|
+
const fileName = packageMap[packageName];
|
|
140
|
+
if (!fileName) {
|
|
141
|
+
return Promise.resolve(null);
|
|
142
|
+
}
|
|
143
|
+
return import(\`./packages/\${fileName}\`)
|
|
144
|
+
}
|
|
145
|
+
export default devDynamicImport;`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get emptyIndexContent() {
|
|
149
|
+
return `
|
|
150
|
+
export default function devDynamicImport(packageName: string): Promise<any> {
|
|
151
|
+
return Promise.resolve(null);
|
|
152
|
+
}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
generatePluginContent() {
|
|
156
|
+
if (fs.existsSync(this.outputPath)) {
|
|
157
|
+
fs.rmdirSync(this.outputPath, { recursive: true, force: true });
|
|
125
158
|
}
|
|
159
|
+
fs.mkdirSync(this.outputPath);
|
|
126
160
|
const validPluginPaths = this.pluginsPath.filter((pluginPath) => fs.existsSync(pluginPath));
|
|
127
|
-
if (!validPluginPaths.length) {
|
|
161
|
+
if (!validPluginPaths.length || process.env.NODE_ENV === 'production') {
|
|
162
|
+
fs.writeFileSync(this.indexPath, this.emptyIndexContent);
|
|
128
163
|
return;
|
|
129
164
|
}
|
|
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
165
|
|
|
138
|
-
const
|
|
166
|
+
const pluginInfos = validPluginPaths.map((pluginPath) => this.getContent(pluginPath)).flat();
|
|
139
167
|
|
|
140
|
-
|
|
168
|
+
// index.ts
|
|
169
|
+
fs.writeFileSync(this.indexPath, this.indexContent);
|
|
170
|
+
// packageMap.json
|
|
171
|
+
const packageMapContent = pluginInfos.reduce((memo, item) => {
|
|
172
|
+
memo[item.packageJsonName] = item.pluginFileName + '.ts';
|
|
173
|
+
return memo;
|
|
174
|
+
}, {});
|
|
175
|
+
fs.writeFileSync(this.packageMapPath, JSON.stringify(packageMapContent, null, 2));
|
|
176
|
+
// packages
|
|
177
|
+
fs.mkdirSync(this.packagesPath, { recursive: true });
|
|
178
|
+
pluginInfos.forEach((item) => {
|
|
179
|
+
const pluginPackagePath = path.join(this.packagesPath, item.pluginFileName + '.ts');
|
|
180
|
+
fs.writeFileSync(pluginPackagePath, item.exportStatement);
|
|
181
|
+
});
|
|
141
182
|
}
|
|
142
183
|
|
|
143
184
|
getContent(pluginPath) {
|
|
144
185
|
const pluginFolders = fs.readdirSync(pluginPath);
|
|
145
|
-
const
|
|
186
|
+
const pluginInfos = pluginFolders
|
|
146
187
|
.filter((folder) => {
|
|
147
188
|
const pluginPackageJsonPath = path.join(pluginPath, folder, 'package.json');
|
|
148
189
|
const pluginSrcClientPath = path.join(pluginPath, folder, 'src', 'client');
|
|
149
190
|
return fs.existsSync(pluginPackageJsonPath) && fs.existsSync(pluginSrcClientPath);
|
|
150
191
|
})
|
|
151
|
-
.map((folder
|
|
192
|
+
.map((folder) => {
|
|
152
193
|
const pluginPackageJsonPath = path.join(pluginPath, folder, 'package.json');
|
|
153
194
|
const pluginPackageJson = require(pluginPackageJsonPath);
|
|
154
195
|
const pluginSrcClientPath = path
|
|
155
|
-
.relative(
|
|
196
|
+
.relative(this.packagesPath, path.join(pluginPath, folder, 'src', 'client'))
|
|
156
197
|
.replaceAll('\\', '/');
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
return {
|
|
198
|
+
const pluginFileName = `${path.basename(pluginPath)}_${folder.replaceAll('-', '_')}`;
|
|
199
|
+
const exportStatement = `export { default } from '${pluginSrcClientPath}';`;
|
|
200
|
+
return { exportStatement, pluginFileName, packageJsonName: pluginPackageJson.name };
|
|
160
201
|
});
|
|
161
202
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const exportContent = pluginImports
|
|
165
|
-
.map(({ pluginName, packageJsonName }) => ` "${packageJsonName}": ${pluginName},`)
|
|
166
|
-
.join('\n');
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
indexContent,
|
|
170
|
-
exportContent,
|
|
171
|
-
};
|
|
203
|
+
return pluginInfos;
|
|
172
204
|
}
|
|
173
205
|
}
|
|
174
206
|
|