@nocobase/devtools 2.1.0-alpha.1 → 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/README.md CHANGED
@@ -1,17 +1,24 @@
1
1
  # NocoBase
2
2
 
3
3
  <video width="100%" controls>
4
- <source src="https://static-docs.nocobase.com/NocoBase0510.mp4" type="video/mp4">
4
+ <source src="https://github.com/user-attachments/assets/4d11a87b-00e2-48f3-9bf7-389d21072d13" type="video/mp4">
5
5
  </video>
6
6
 
7
+ <p align="center">
8
+ <a href="https://trendshift.io/repositories/4112" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4112" alt="nocobase%2Fnocobase | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
9
+ <a href="https://www.producthunt.com/posts/nocobase?embed=true&utm_source=badge-top-post-topic-badge&utm_medium=badge&utm_souce=badge-nocobase" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/top-post-topic-badge.svg?post_id=456520&theme=light&period=weekly&topic_id=267" alt="NocoBase - Scalability&#0045;first&#0044;&#0032;open&#0045;source&#0032;no&#0045;code&#0032;platform | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
10
+ </p>
7
11
 
8
12
  ## What is NocoBase
9
13
 
10
- NocoBase is a scalability-first, open-source no-code development platform.
11
- Instead of investing years of time and millions of dollars in research and development, deploy NocoBase in a few minutes and you'll have a private, controllable, and extremely scalable no-code development platform!
14
+ NocoBase is the most extensible AI-powered no-code platform.
15
+ Total control. Infinite extensibility. AI collaboration.
16
+ Enable your team to adapt quickly and cut costs dramatically.
17
+ No years of development. No millions wasted.
18
+ Deploy NocoBase in minutes — and take control of everything.
12
19
 
13
20
  Homepage:
14
- https://www.nocobase.com/
21
+ https://www.nocobase.com/
15
22
 
16
23
  Online Demo:
17
24
  https://demo.nocobase.com/new
@@ -19,12 +26,74 @@ https://demo.nocobase.com/new
19
26
  Documents:
20
27
  https://docs.nocobase.com/
21
28
 
22
- Commericial license & plugins:
23
- https://www.nocobase.com/en/commercial
29
+ Forum:
30
+ https://forum.nocobase.com/
24
31
 
25
- License agreement:
26
- https://www.nocobase.com/en/agreement
32
+ Use Cases:
33
+ https://www.nocobase.com/en/blog/tags/customer-stories
27
34
 
35
+ ## Release Notes
28
36
 
29
- ## Contact Us:
30
- hello@nocobase.com
37
+ Our [blog](https://www.nocobase.com/en/blog/timeline) is regularly updated with release notes and provides a weekly summary.
38
+
39
+ ## Distinctive features
40
+
41
+ ### 1. Data model-driven, not form/table–driven
42
+
43
+ Instead of being constrained by forms or tables, NocoBase adopts a data model–driven approach, separating data structure from user interface to unlock unlimited possibilities.
44
+
45
+ - UI and data structure are fully decoupled
46
+ - Multiple blocks and actions can be created for the same table or record in any quantity or form
47
+ - Supports the main database, external databases, and third-party APIs as data sources
48
+
49
+ ![model](https://static-docs.nocobase.com/model.png)
50
+
51
+ ### 2. AI employees, integrated into your business systems
52
+ Unlike standalone AI demos, NocoBase allows you to embed AI capabilities seamlessly into your interfaces, workflows, and data context, making AI truly useful in real business scenarios.
53
+
54
+ - Define AI employees for roles such as translator, analyst, researcher, or assistant
55
+ - Seamless AI–human collaboration in interfaces and workflows
56
+ - Ensure AI usage is secure, transparent, and customizable for your business needs
57
+
58
+ ![AI-employee](https://static-docs.nocobase.com/ai-employee-home.png)
59
+
60
+ ### 3. What you see is what you get, incredibly easy to use
61
+
62
+ While enabling the development of complex business systems, NocoBase keeps the experience simple and intuitive.
63
+
64
+ - One-click switch between usage mode and configuration mode
65
+ - Pages serve as a canvas to arrange blocks and actions, similar to Notion
66
+ - Configuration mode is designed for ordinary users, not just programmers
67
+
68
+ ![wysiwyg](https://static-docs.nocobase.com/wysiwyg.gif)
69
+
70
+ ### 4. Everything is a plugin, designed for extension
71
+ Adding more no-code features will never cover every business case. NocoBase is built for extension through its plugin-based microkernel architecture.
72
+
73
+ - All functionalities are plugins, similar to WordPress
74
+ - Plugins are ready to use upon installation
75
+ - Pages, blocks, actions, APIs, and data sources can all be extended through custom plugins
76
+
77
+ ![plugins](https://static-docs.nocobase.com/plugins.png)
78
+
79
+ ## Installation
80
+
81
+ NocoBase supports three installation methods:
82
+
83
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/docker-compose">Installing With Docker (👍Recommended)</a>
84
+
85
+ Suitable for no-code scenarios, no code to write. When upgrading, just download the latest image and reboot.
86
+
87
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/create-nocobase-app">Installing from create-nocobase-app CLI</a>
88
+
89
+ The business code of the project is completely independent and supports low-code development.
90
+
91
+ - <a target="_blank" href="https://docs.nocobase.com/welcome/getting-started/installation/git-clone">Installing from Git source code</a>
92
+
93
+ If you want to experience the latest unreleased version, or want to participate in the contribution, you need to make changes and debug on the source code, it is recommended to choose this installation method, which requires a high level of development skills, and if the code has been updated, you can git pull the latest code.
94
+
95
+ ## How NocoBase works
96
+
97
+ <video width="100%" controls>
98
+ <source src="https://github.com/user-attachments/assets/8d183b44-9bb5-4792-b08f-bc08fe8dfaaf" type="video/mp4">
99
+ </video>
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,13 +1,18 @@
1
1
  {
2
2
  "name": "@nocobase/devtools",
3
- "version": "2.1.0-alpha.1",
3
+ "version": "2.1.0-alpha.11",
4
4
  "description": "",
5
- "license": "AGPL-3.0",
5
+ "license": "Apache-2.0",
6
6
  "main": "./src/index.js",
7
7
  "dependencies": {
8
- "@nocobase/build": "2.1.0-alpha.1",
9
- "@nocobase/client": "2.1.0-alpha.1",
10
- "@nocobase/test": "2.1.0-alpha.1",
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
+ "@rsbuild/core": "1.7.3",
12
+ "@rsbuild/plugin-less": "^1.6.2",
13
+ "@rsbuild/plugin-node-polyfill": "1.4.4",
14
+ "@rsbuild/plugin-react": "1.4.6",
15
+ "@rsbuild/plugin-svgr": "^1.3.1",
11
16
  "@types/koa": "^2.15.0",
12
17
  "@types/koa-bodyparser": "^4.3.4",
13
18
  "@types/lodash": "^4.14.177",
@@ -50,5 +55,5 @@
50
55
  "url": "git+https://github.com/nocobase/nocobase.git",
51
56
  "directory": "packages/core/devtools"
52
57
  },
53
- "gitHead": "d27baf21569643d6fa83f882233f4e90eb5b89f1"
58
+ "gitHead": "bb96d633a6371afb586072ff516bd0613c757db0"
54
59
  }
@@ -0,0 +1,3 @@
1
+ export declare function getRsbuildAlias(): Record<string, string>;
2
+ export declare function generatePlugins(): void;
3
+ export declare function generateV2Plugins(): void;
@@ -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 declare class IndexGenerator {
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 fs = require('fs');
5
- const glob = require('fast-glob');
6
- const path = require('path');
2
+ const { resolvePublicPath, resolveV2PublicPath } = require('../cli/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 { APP_PORT, API_BASE_URL, API_CLIENT_STORAGE_TYPE, API_CLIENT_STORAGE_PREFIX, APP_PUBLIC_PATH } = process.env;
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
- [APP_PUBLIC_PATH + LOCAL_STORAGE_BASE_URL]: {
29
+ [normalizedAppPublicPath + LOCAL_STORAGE_BASE_URL]: {
24
30
  target: PROXY_TARGET_URL,
25
31
  changeOrigin: true,
26
32
  },
27
- [APP_PUBLIC_PATH + STATIC_PATH]: {
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];
@@ -42,6 +68,7 @@ function getUmiConfig() {
42
68
  'process.env.API_BASE_URL': API_BASE_URL || API_BASE_PATH,
43
69
  'process.env.API_CLIENT_STORAGE_PREFIX': API_CLIENT_STORAGE_PREFIX,
44
70
  'process.env.API_CLIENT_STORAGE_TYPE': API_CLIENT_STORAGE_TYPE,
71
+ 'process.env.API_CLIENT_SHARE_TOKEN': process.env.API_CLIENT_SHARE_TOKEN || 'false',
45
72
  'process.env.APP_ENV': process.env.APP_ENV,
46
73
  'process.env.VERSION': packageJson.version,
47
74
  'process.env.WEBSOCKET_URL': process.env.WEBSOCKET_URL,
@@ -71,52 +98,12 @@ function getUmiConfig() {
71
98
  },
72
99
  // for local storage
73
100
  ...getLocalStorageProxy(),
101
+ // v2 shell dev server proxy
102
+ ...getClientV2Proxy(),
74
103
  },
75
104
  };
76
105
  }
77
106
 
78
- function getNamespace() {
79
- const content = fs.readFileSync(resolve(process.cwd(), 'package.json'), 'utf-8');
80
- const json = JSON.parse(content);
81
- return json.name;
82
- }
83
-
84
- function getTsconfigPaths() {
85
- const content = fs.readFileSync(resolve(process.cwd(), 'tsconfig.paths.json'), 'utf-8');
86
- const json = JSON.parse(content);
87
- return json.compilerOptions.paths;
88
- }
89
-
90
- function getPackagePaths() {
91
- const paths = getTsconfigPaths();
92
- const pkgs = [];
93
- for (const key in paths) {
94
- if (Object.hasOwnProperty.call(paths, key)) {
95
- for (let dir of paths[key]) {
96
- if (dir.includes('*')) {
97
- const files = glob.sync(dir, { cwd: process.cwd(), onlyDirectories: true });
98
- for (const file of files) {
99
- const dirname = resolve(process.cwd(), file);
100
- if (existsSync(dirname)) {
101
- const re = new RegExp(dir.replace('*', '(.+)'));
102
- const p = dirname
103
- .substring(process.cwd().length + 1)
104
- .split(sep)
105
- .join('/');
106
- const match = re.exec(p);
107
- pkgs.push([key.replace('*', match?.[1]), dirname]);
108
- }
109
- }
110
- } else {
111
- const dirname = resolve(process.cwd(), dir);
112
- pkgs.push([key, dirname]);
113
- }
114
- }
115
- }
116
- }
117
- return pkgs;
118
- }
119
-
120
107
  function resolveNocobasePackagesAlias(config) {
121
108
  const pkgs = getPackagePaths();
122
109
  for (const [pkg, dir] of pkgs) {
@@ -125,154 +112,8 @@ function resolveNocobasePackagesAlias(config) {
125
112
  }
126
113
  }
127
114
 
128
- function getNodeModulesPath(packageDir) {
129
- const node_modules_dir = path.join(process.cwd(), 'node_modules');
130
- return path.join(node_modules_dir, packageDir);
131
- }
132
- class IndexGenerator {
133
- nocobaseDir = getNodeModulesPath('@nocobase');
134
-
135
- constructor(outputPath, pluginsPath) {
136
- this.outputPath = outputPath;
137
- this.pluginsPath = pluginsPath;
138
- }
139
-
140
- get indexPath() {
141
- return path.join(this.outputPath, 'index.ts');
142
- }
143
-
144
- get packageMapPath() {
145
- return path.join(this.outputPath, 'packageMap.json');
146
- }
147
-
148
- get packagesPath() {
149
- return path.join(this.outputPath, 'packages');
150
- }
151
-
152
- generate() {
153
- this.generatePluginContent();
154
- if (process.env.NODE_ENV === 'production') return;
155
- // this.pluginsPath.forEach((pluginPath) => {
156
- // if (!fs.existsSync(pluginPath)) {
157
- // return;
158
- // }
159
- // fs.watch(pluginPath, { recursive: false }, () => {
160
- // this.generatePluginContent();
161
- // });
162
- // });
163
- }
164
-
165
- get indexContent() {
166
- return `// @ts-nocheck
167
- import packageMap from './packageMap.json';
168
-
169
- function devDynamicImport(packageName: string): Promise<any> {
170
- const fileName = packageMap[packageName];
171
- if (!fileName) {
172
- return Promise.resolve(null);
173
- }
174
- try {
175
- return import(\`./packages/\${fileName}\`)
176
- } catch (error) {
177
- return Promise.resolve(null);
178
- }
179
- }
180
- export default devDynamicImport;`;
181
- }
182
-
183
- get emptyIndexContent() {
184
- return `
185
- export default function devDynamicImport(packageName: string): Promise<any> {
186
- return Promise.resolve(null);
187
- }`;
188
- }
189
-
190
- generatePluginContent() {
191
- if (fs.existsSync(this.outputPath)) {
192
- fs.rmSync(this.outputPath, { recursive: true, force: true });
193
- }
194
- fs.mkdirSync(this.outputPath, { recursive: true, force: true });
195
- const validPluginPaths = this.pluginsPath.filter((pluginsPath) => fs.existsSync(pluginsPath));
196
- if (!validPluginPaths.length || process.env.NODE_ENV === 'production') {
197
- fs.writeFileSync(this.indexPath, this.emptyIndexContent);
198
- return;
199
- }
200
-
201
- const pluginInfos = validPluginPaths.map((pluginsPath) => this.getContent(pluginsPath)).flat();
202
-
203
- // index.ts
204
- fs.writeFileSync(this.indexPath, this.indexContent);
205
- // packageMap.json
206
- const packageMapContent = pluginInfos.reduce((memo, item) => {
207
- memo[item.packageJsonName] = item.pluginFileName + '.ts';
208
- return memo;
209
- }, {});
210
- fs.writeFileSync(this.packageMapPath, JSON.stringify(packageMapContent, null, 2));
211
- // packages
212
- fs.mkdirSync(this.packagesPath, { recursive: true });
213
- pluginInfos.forEach((item) => {
214
- const pluginPackagePath = path.join(this.packagesPath, item.pluginFileName + '.ts');
215
- fs.writeFileSync(pluginPackagePath, item.exportStatement);
216
- });
217
- }
218
-
219
- getContent(pluginsPath) {
220
- const pluginFolders = glob.sync(['*/package.json', '*/*/package.json'], {
221
- cwd: pluginsPath,
222
- onlyFiles: true,
223
- absolute: true,
224
- });
225
-
226
- const storagePluginFolders = glob.sync(['*/package.json', '*/*/package.json'], {
227
- cwd: process.env.PLUGIN_STORAGE_PATH,
228
- onlyFiles: true,
229
- absolute: true,
230
- });
231
-
232
- const nocobasePluginFolders = glob
233
- .sync(['plugin-*/package.json'], { cwd: this.nocobaseDir, onlyFiles: true, absolute: true })
234
- .map((item) => fs.realpathSync(item));
235
- const pluginInfos = Array.from(new Set([...pluginFolders, ...storagePluginFolders, ...nocobasePluginFolders]))
236
- .filter((item) => {
237
- const dirname = path.dirname(item);
238
- const clientJs = path.join(dirname, 'client.js');
239
- return fs.existsSync(clientJs);
240
- })
241
- .map((pluginPackageJsonPath) => {
242
- const pluginPackageJson = require(pluginPackageJsonPath);
243
- const pluginPathArr = pluginPackageJsonPath.replaceAll(path.sep, '/').split('/');
244
- const hasNamespace = pluginPathArr[pluginPathArr.length - 3].startsWith('@');
245
- const pluginFileName = (hasNamespace
246
- ? `${pluginPathArr[pluginPathArr.length - 3].replace('@', '')}_${pluginPathArr[pluginPathArr.length - 2]}`
247
- : pluginPathArr[pluginPathArr.length - 2]
248
- ).replaceAll('-', '_');
249
-
250
- let exportStatement = '';
251
- if (pluginPackageJsonPath.includes('packages')) {
252
- const pluginSrcClientPath = path
253
- .relative(this.packagesPath, path.join(path.dirname(pluginPackageJsonPath), 'src', 'client'))
254
- .replaceAll(path.sep, '/');
255
- exportStatement = `export { default } from '${pluginSrcClientPath}';`;
256
- } else {
257
- exportStatement = `export { default } from '${pluginPackageJson.name}/client';`;
258
- }
259
- return { exportStatement, pluginFileName, packageJsonName: pluginPackageJson.name };
260
- });
261
-
262
- return pluginInfos;
263
- }
264
- }
265
-
266
115
  exports.getUmiConfig = getUmiConfig;
267
116
  exports.resolveNocobasePackagesAlias = resolveNocobasePackagesAlias;
268
117
  exports.IndexGenerator = IndexGenerator;
269
-
270
- exports.generatePlugins = function () {
271
- const pluginDirs = (process.env.PLUGIN_PATH || 'packages/plugins/,packages/samples/,packages/pro-plugins/')
272
- .split(',')
273
- .map((item) => path.join(process.cwd(), item));
274
-
275
- const outputPluginPath = path.join(process.env.APP_PACKAGE_ROOT, 'client', 'src', '.plugins');
276
- const indexGenerator = new IndexGenerator(outputPluginPath, pluginDirs);
277
- indexGenerator.generate();
278
- };
118
+ exports.generatePlugins = generatePlugins;
119
+ exports.generateAllPlugins = generateAllPlugins;