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