@nocobase/cli 2.1.0-alpha.1 → 2.1.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/LICENSE +201 -661
- package/README.md +79 -10
- package/nocobase.conf.tpl +77 -1
- package/package.json +6 -6
- package/src/commands/build.js +34 -2
- package/src/commands/client.js +166 -0
- package/src/commands/create-nginx-conf.js +19 -3
- package/src/commands/dev.js +128 -70
- package/src/commands/index.js +1 -0
- package/src/commands/pkg.js +6 -1
- package/src/commands/pm2.js +1 -1
- package/src/commands/update-deps.js +1 -0
- package/src/license.js +1 -1
- package/src/util.js +43 -1
- package/templates/bundle-status.html +338 -0
- package/templates/create-app-package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
# NocoBase
|
|
2
2
|
|
|
3
3
|
<video width="100%" controls>
|
|
4
|
-
|
|
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-first, open-source no-code 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
|
|
11
|
-
|
|
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
|
-
|
|
23
|
-
https://
|
|
29
|
+
Forum:
|
|
30
|
+
https://forum.nocobase.com/
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
https://www.nocobase.com/en/
|
|
32
|
+
Use Cases:
|
|
33
|
+
https://www.nocobase.com/en/blog/tags/customer-stories
|
|
27
34
|
|
|
35
|
+
## Release Notes
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+

|
|
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
|
+

|
|
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
|
+

|
|
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
|
+

|
|
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/nocobase.conf.tpl
CHANGED
|
@@ -12,6 +12,11 @@ log_format apm '"$time_local" client=$remote_addr '
|
|
|
12
12
|
'upstream_connect_time=$upstream_connect_time '
|
|
13
13
|
'upstream_header_time=$upstream_header_time';
|
|
14
14
|
|
|
15
|
+
map $http_x_forwarded_proto $upstream_x_forwarded_proto {
|
|
16
|
+
default $http_x_forwarded_proto;
|
|
17
|
+
"" $scheme;
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
server {
|
|
16
21
|
listen 80;
|
|
17
22
|
server_name _;
|
|
@@ -50,6 +55,77 @@ server {
|
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
location = {{v2PublicPathNoTrailingSlash}} {
|
|
59
|
+
return 302 {{v2PublicPath}}$is_args$args;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
location {{v2PublicPath}}assets/ {
|
|
63
|
+
alias {{cwd}}/node_modules/@nocobase/app/dist/client/v2/assets/;
|
|
64
|
+
expires 365d;
|
|
65
|
+
add_header Cache-Control "public";
|
|
66
|
+
access_log off;
|
|
67
|
+
autoindex off;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
location {{v2PublicPath}} {
|
|
71
|
+
proxy_pass http://127.0.0.1:{{apiPort}};
|
|
72
|
+
proxy_http_version 1.1;
|
|
73
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
74
|
+
proxy_set_header Connection 'upgrade';
|
|
75
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
76
|
+
proxy_set_header X-Forwarded-Proto $upstream_x_forwarded_proto;
|
|
77
|
+
proxy_set_header Host $host;
|
|
78
|
+
proxy_set_header Referer $http_referer;
|
|
79
|
+
proxy_set_header User-Agent $http_user_agent;
|
|
80
|
+
add_header Cache-Control 'no-cache, no-store';
|
|
81
|
+
proxy_cache_bypass $http_upgrade;
|
|
82
|
+
proxy_connect_timeout 600;
|
|
83
|
+
proxy_send_timeout 600;
|
|
84
|
+
proxy_read_timeout 600;
|
|
85
|
+
send_timeout 600;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# RFC 8414 root-mounted discovery compatibility for path-based issuers/resources.
|
|
89
|
+
location ~ ^/\.well-known/oauth-authorization-server/(.+)$ {
|
|
90
|
+
rewrite ^/\.well-known/oauth-authorization-server/(.+)$ /$1/.well-known/oauth-authorization-server break;
|
|
91
|
+
proxy_pass http://127.0.0.1:{{apiPort}};
|
|
92
|
+
proxy_http_version 1.1;
|
|
93
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
94
|
+
proxy_set_header Connection 'upgrade';
|
|
95
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
96
|
+
proxy_set_header X-Forwarded-Proto $upstream_x_forwarded_proto;
|
|
97
|
+
proxy_set_header Host $host;
|
|
98
|
+
proxy_set_header Referer $http_referer;
|
|
99
|
+
proxy_set_header User-Agent $http_user_agent;
|
|
100
|
+
add_header Cache-Control 'no-cache, no-store';
|
|
101
|
+
proxy_cache_bypass $http_upgrade;
|
|
102
|
+
proxy_connect_timeout 600;
|
|
103
|
+
proxy_send_timeout 600;
|
|
104
|
+
proxy_read_timeout 600;
|
|
105
|
+
send_timeout 600;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
location ~ ^/\.well-known/openid-configuration/(.+)$ {
|
|
109
|
+
rewrite ^/\.well-known/openid-configuration/(.+)$ /$1/.well-known/openid-configuration break;
|
|
110
|
+
proxy_pass http://127.0.0.1:{{apiPort}};
|
|
111
|
+
proxy_http_version 1.1;
|
|
112
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
113
|
+
proxy_set_header Connection 'upgrade';
|
|
114
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
115
|
+
proxy_set_header X-Forwarded-Proto $upstream_x_forwarded_proto;
|
|
116
|
+
proxy_set_header Host $host;
|
|
117
|
+
proxy_set_header Referer $http_referer;
|
|
118
|
+
proxy_set_header User-Agent $http_user_agent;
|
|
119
|
+
add_header Cache-Control 'no-cache, no-store';
|
|
120
|
+
proxy_cache_bypass $http_upgrade;
|
|
121
|
+
proxy_connect_timeout 600;
|
|
122
|
+
proxy_send_timeout 600;
|
|
123
|
+
proxy_read_timeout 600;
|
|
124
|
+
send_timeout 600;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
53
129
|
location {{publicPath}} {
|
|
54
130
|
alias {{cwd}}/node_modules/@nocobase/app/dist/client/;
|
|
55
131
|
try_files $uri $uri/ /index.html;
|
|
@@ -73,7 +149,7 @@ server {
|
|
|
73
149
|
proxy_set_header Upgrade $http_upgrade;
|
|
74
150
|
proxy_set_header Connection 'upgrade';
|
|
75
151
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
76
|
-
proxy_set_header X-Forwarded-Proto $
|
|
152
|
+
proxy_set_header X-Forwarded-Proto $upstream_x_forwarded_proto;
|
|
77
153
|
proxy_set_header Host $host;
|
|
78
154
|
proxy_set_header Referer $http_referer;
|
|
79
155
|
proxy_set_header User-Agent $http_user_agent;
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.10",
|
|
4
4
|
"description": "",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"nocobase": "./bin/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nocobase/app": "2.1.0-alpha.
|
|
12
|
-
"@nocobase/license-kit": "^0.3.
|
|
11
|
+
"@nocobase/app": "2.1.0-alpha.10",
|
|
12
|
+
"@nocobase/license-kit": "^0.3.8",
|
|
13
13
|
"@types/fs-extra": "^11.0.1",
|
|
14
14
|
"@umijs/utils": "3.5.20",
|
|
15
15
|
"chalk": "^4.1.1",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"tsx": "^4.19.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@nocobase/devtools": "2.1.0-alpha.
|
|
30
|
+
"@nocobase/devtools": "2.1.0-alpha.10"
|
|
31
31
|
},
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
34
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
35
35
|
"directory": "packages/core/cli"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "ce790d46c0a5768ca9618c7d0d77ab8300de75c8"
|
|
38
38
|
}
|
package/src/commands/build.js
CHANGED
|
@@ -7,10 +7,34 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
const { existsSync } = require('fs');
|
|
10
11
|
const { resolve } = require('path');
|
|
11
12
|
const { Command } = require('commander');
|
|
12
13
|
const { run, nodeCheck, isPackageValid, buildIndexHtml } = require('../util');
|
|
13
14
|
|
|
15
|
+
async function buildClientV2() {
|
|
16
|
+
const configPath = resolve(process.env.APP_PACKAGE_ROOT, 'client-v2/rsbuild.config.ts');
|
|
17
|
+
if (!existsSync(configPath)) {
|
|
18
|
+
console.log(`client-v2 config not found: ${configPath}`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
await run('rsbuild', ['build', '--config', configPath], {
|
|
22
|
+
env: {
|
|
23
|
+
...process.env,
|
|
24
|
+
APP_ENV: 'production',
|
|
25
|
+
NODE_ENV: 'production',
|
|
26
|
+
API_BASE_URL: process.env.API_BASE_URL || process.env.API_BASE_PATH,
|
|
27
|
+
API_CLIENT_STORAGE_PREFIX: process.env.API_CLIENT_STORAGE_PREFIX,
|
|
28
|
+
API_CLIENT_STORAGE_TYPE: process.env.API_CLIENT_STORAGE_TYPE,
|
|
29
|
+
API_CLIENT_SHARE_TOKEN: process.env.API_CLIENT_SHARE_TOKEN || 'false',
|
|
30
|
+
WEBSOCKET_URL: process.env.WEBSOCKET_URL || '',
|
|
31
|
+
WS_PATH: process.env.WS_PATH,
|
|
32
|
+
ESM_CDN_BASE_URL: process.env.ESM_CDN_BASE_URL || 'https://esm.sh',
|
|
33
|
+
ESM_CDN_SUFFIX: process.env.ESM_CDN_SUFFIX || '',
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
14
38
|
/**
|
|
15
39
|
*
|
|
16
40
|
* @param {Command} cli
|
|
@@ -26,16 +50,23 @@ module.exports = (cli) => {
|
|
|
26
50
|
.option('-w, --watch', 'watch compile the @nocobase/build package')
|
|
27
51
|
.option('-s, --sourcemap', 'generate sourcemap')
|
|
28
52
|
.option('--no-dts', 'not generate dts')
|
|
53
|
+
.option('--client-v2-only', 'build client-v2 shell only')
|
|
29
54
|
.action(async (pkgs, options) => {
|
|
30
55
|
nodeCheck();
|
|
56
|
+
process.env['VITE_CJS_IGNORE_WARNING'] = 'true';
|
|
57
|
+
process.env.APP_ENV = 'production';
|
|
58
|
+
|
|
59
|
+
if (options.clientV2Only) {
|
|
60
|
+
await buildClientV2();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
31
64
|
if (options.compile || options.watch || isPackageValid('@nocobase/build/src/index.ts')) {
|
|
32
65
|
await run('yarn', ['build', options.watch ? '--watch' : ''], {
|
|
33
66
|
cwd: resolve(process.cwd(), 'packages/core/build'),
|
|
34
67
|
});
|
|
35
68
|
if (options.watch) return;
|
|
36
69
|
}
|
|
37
|
-
process.env['VITE_CJS_IGNORE_WARNING'] = 'true';
|
|
38
|
-
process.env.APP_ENV = 'production';
|
|
39
70
|
|
|
40
71
|
await run('nocobase-build', [
|
|
41
72
|
...pkgs,
|
|
@@ -45,5 +76,6 @@ module.exports = (cli) => {
|
|
|
45
76
|
options.retry ? '--retry' : '',
|
|
46
77
|
]);
|
|
47
78
|
buildIndexHtml(true);
|
|
79
|
+
await buildClientV2();
|
|
48
80
|
});
|
|
49
81
|
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const { Command } = require('commander');
|
|
12
|
+
const fs = require('fs-extra');
|
|
13
|
+
const { resolve } = require('path');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 复制主应用客户端文件
|
|
17
|
+
* @param {string} source - 源目录路径
|
|
18
|
+
* @param {string} target - 目标目录路径
|
|
19
|
+
*/
|
|
20
|
+
async function copyMainClient(source, target) {
|
|
21
|
+
if (!(await fs.exists(source))) {
|
|
22
|
+
console.log(chalk.yellow(`Source directory does not exist: ${source}`));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// 确保目标目录存在且为空
|
|
26
|
+
await fs.ensureDir(target);
|
|
27
|
+
await fs.emptyDir(target);
|
|
28
|
+
await fs.copy(source, target, { recursive: true });
|
|
29
|
+
console.log(chalk.green(`Copied main client files from ${source} to ${target}`));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 复制插件客户端文件
|
|
34
|
+
* @param {string} pluginsBaseDir - 插件基础目录路径
|
|
35
|
+
* @param {string} namespace - 命名空间(如 '@nocobase' 或 '@nocobase-example')
|
|
36
|
+
* @param {string} target - 目标目录
|
|
37
|
+
*/
|
|
38
|
+
async function copyPluginClients(pluginsBaseDir, namespace, target) {
|
|
39
|
+
const pluginsDir = resolve(process.cwd(), pluginsBaseDir, namespace);
|
|
40
|
+
if (await fs.exists(pluginsDir)) {
|
|
41
|
+
const pluginNames = await fs.readdir(pluginsDir);
|
|
42
|
+
for (const pluginName of pluginNames) {
|
|
43
|
+
const pluginPath = resolve(pluginsDir, pluginName);
|
|
44
|
+
const pluginDistClient = resolve(pluginPath, 'dist/client');
|
|
45
|
+
if (await fs.exists(pluginDistClient)) {
|
|
46
|
+
const pluginTarget = resolve(target, 'static/plugins', namespace, pluginName, 'dist/client');
|
|
47
|
+
await fs.mkdir(resolve(pluginTarget, '..'), { recursive: true });
|
|
48
|
+
await fs.copy(pluginDistClient, pluginTarget, { recursive: true });
|
|
49
|
+
console.log(chalk.green(`Copied ${namespace}/${pluginName} client files`));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 递归上传目录到 OSS
|
|
57
|
+
* @param {Client} client - OSS 客户端实例
|
|
58
|
+
* @param {string} localDir - 本地目录路径
|
|
59
|
+
* @param {string} ossPrefix - OSS 对象前缀(目录路径)
|
|
60
|
+
*/
|
|
61
|
+
async function uploadDirectoryToOSS(client, localDir, ossPrefix = '') {
|
|
62
|
+
if (!(await fs.exists(localDir))) {
|
|
63
|
+
console.log(chalk.yellow(`Directory does not exist: ${localDir}`));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const stats = await fs.stat(localDir);
|
|
68
|
+
if (!stats.isDirectory()) {
|
|
69
|
+
throw new Error(`${localDir} is not a directory`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const files = await fs.readdir(localDir);
|
|
73
|
+
let uploadedCount = 0;
|
|
74
|
+
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
const filePath = resolve(localDir, file);
|
|
77
|
+
const fileStats = await fs.stat(filePath);
|
|
78
|
+
|
|
79
|
+
if (fileStats.isDirectory()) {
|
|
80
|
+
// 递归处理子目录
|
|
81
|
+
const subOssPrefix = ossPrefix ? `${ossPrefix}/${file}` : file;
|
|
82
|
+
const subCount = await uploadDirectoryToOSS(client, filePath, subOssPrefix);
|
|
83
|
+
uploadedCount += subCount;
|
|
84
|
+
} else {
|
|
85
|
+
// 上传文件
|
|
86
|
+
const ossKey = ossPrefix ? `${ossPrefix}/${file}` : file;
|
|
87
|
+
try {
|
|
88
|
+
await client.put(ossKey, filePath);
|
|
89
|
+
// console.log(chalk.green(`Uploaded: ${ossKey}`));
|
|
90
|
+
uploadedCount++;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error(chalk.red(`Failed to upload ${ossKey}:`), error.message);
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return uploadedCount;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* @param {Command} cli
|
|
104
|
+
*/
|
|
105
|
+
module.exports = (cli) => {
|
|
106
|
+
cli
|
|
107
|
+
.command('client:extract')
|
|
108
|
+
.allowUnknownOption()
|
|
109
|
+
.action(async () => {
|
|
110
|
+
const version = require('../../package.json').version;
|
|
111
|
+
const target = resolve(process.cwd(), 'storage/dist-client', version);
|
|
112
|
+
const mainClientSource = resolve(process.cwd(), 'node_modules/@nocobase/app/dist/client');
|
|
113
|
+
await copyMainClient(mainClientSource, target);
|
|
114
|
+
await copyPluginClients('packages/plugins', '@nocobase', target);
|
|
115
|
+
await copyPluginClients('packages/plugins', '@nocobase-example', target);
|
|
116
|
+
await copyPluginClients('packages/pro-plugins', '@nocobase', target);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
cli
|
|
120
|
+
.command('client:upload')
|
|
121
|
+
.allowUnknownOption()
|
|
122
|
+
.action(async () => {
|
|
123
|
+
const version = require('../../package.json').version;
|
|
124
|
+
const target = resolve(process.cwd(), 'storage/dist-client', version);
|
|
125
|
+
|
|
126
|
+
// 检查必要的环境变量
|
|
127
|
+
if (
|
|
128
|
+
!process.env.CDN_ALI_OSS_ACCESS_KEY_ID ||
|
|
129
|
+
!process.env.CDN_ALI_OSS_ACCESS_KEY_SECRET ||
|
|
130
|
+
!process.env.CDN_ALI_OSS_BUCKET ||
|
|
131
|
+
!process.env.CDN_ALI_OSS_REGION
|
|
132
|
+
) {
|
|
133
|
+
console.error(
|
|
134
|
+
chalk.red(
|
|
135
|
+
'Missing required environment variables: CDN_ALI_OSS_ACCESS_KEY_ID, CDN_ALI_OSS_ACCESS_KEY_SECRET, CDN_ALI_OSS_BUCKET, CDN_ALI_OSS_REGION',
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const Client = require('ali-oss');
|
|
142
|
+
|
|
143
|
+
const client = new Client({
|
|
144
|
+
accessKeyId: process.env.CDN_ALI_OSS_ACCESS_KEY_ID,
|
|
145
|
+
accessKeySecret: process.env.CDN_ALI_OSS_ACCESS_KEY_SECRET,
|
|
146
|
+
bucket: process.env.CDN_ALI_OSS_BUCKET,
|
|
147
|
+
region: process.env.CDN_ALI_OSS_REGION,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (!(await fs.exists(target))) {
|
|
151
|
+
console.error(chalk.red(`Target directory does not exist: ${target}`));
|
|
152
|
+
console.log(chalk.yellow('Please run "client:extract" first to generate the client files.'));
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
console.log(chalk.blue(`Uploading directory ${target} to OSS...`));
|
|
157
|
+
const ossPrefix = `${version}`;
|
|
158
|
+
try {
|
|
159
|
+
const uploadedCount = await uploadDirectoryToOSS(client, target, ossPrefix);
|
|
160
|
+
console.log(chalk.green(`Successfully uploaded ${uploadedCount} files to OSS`));
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error(chalk.red('Upload failed:'), error);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
};
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
const { resolve, posix } = require('path');
|
|
11
11
|
const { Command } = require('commander');
|
|
12
12
|
const { readFileSync, writeFileSync } = require('fs');
|
|
13
|
+
const { resolvePublicPath, resolveV2PublicPath } = require('../util');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
*
|
|
@@ -17,18 +18,33 @@ const { readFileSync, writeFileSync } = require('fs');
|
|
|
17
18
|
*/
|
|
18
19
|
module.exports = (cli) => {
|
|
19
20
|
cli.command('create-nginx-conf').action(async (name, options) => {
|
|
21
|
+
const rawAppPublicPath = process.env.APP_PUBLIC_PATH || '/';
|
|
22
|
+
const appPublicPath = resolvePublicPath(rawAppPublicPath);
|
|
23
|
+
const v2PublicPath = resolveV2PublicPath(rawAppPublicPath);
|
|
24
|
+
const appPublicPathWithoutTrailingSlash = appPublicPath.replace(/\/$/, '');
|
|
25
|
+
const v2PublicPathWithoutTrailingSlash = v2PublicPath.replace(/\/$/, '');
|
|
20
26
|
const file = resolve(__dirname, '../../nocobase.conf.tpl');
|
|
21
27
|
const data = readFileSync(file, 'utf-8');
|
|
22
28
|
let otherLocation = '';
|
|
23
|
-
if (
|
|
24
|
-
otherLocation = `location / {
|
|
29
|
+
if (appPublicPath !== '/') {
|
|
30
|
+
otherLocation = `location = /v2 {
|
|
31
|
+
return 302 ${v2PublicPath}$is_args$args;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
location /v2/ {
|
|
35
|
+
return 302 ${appPublicPathWithoutTrailingSlash}$uri$is_args$args;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
location / {
|
|
25
39
|
alias ${posix.resolve(process.cwd())}/node_modules/@nocobase/app/dist/client/;
|
|
26
40
|
try_files $uri $uri/ /index.html;
|
|
27
41
|
}`;
|
|
28
42
|
}
|
|
29
43
|
const replaced = data
|
|
30
44
|
.replace(/\{\{cwd\}\}/g, posix.resolve(process.cwd()))
|
|
31
|
-
.replace(/\{\{publicPath\}\}/g,
|
|
45
|
+
.replace(/\{\{publicPath\}\}/g, appPublicPath)
|
|
46
|
+
.replace(/\{\{v2PublicPath\}\}/g, v2PublicPath)
|
|
47
|
+
.replace(/\{\{v2PublicPathNoTrailingSlash\}\}/g, v2PublicPathWithoutTrailingSlash)
|
|
32
48
|
.replace(/\{\{apiPort\}\}/g, process.env.APP_PORT)
|
|
33
49
|
.replace(/\{\{otherLocation\}\}/g, otherLocation);
|
|
34
50
|
const targetFile = resolve(process.cwd(), 'storage', 'nocobase.conf');
|