@nocobase/cli 0.20.0-alpha.8 → 0.21.0-alpha.1
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/nocobase.conf.tpl +89 -0
- package/package.json +5 -5
- package/src/commands/build.js +5 -1
- package/src/commands/create-nginx-conf.js +21 -0
- package/src/commands/e2e.js +6 -0
- package/src/commands/index.js +2 -0
- package/src/commands/p-test.js +2 -1
- package/src/commands/pm2.js +28 -0
- package/src/commands/test.js +1 -0
- package/src/util.js +42 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
log_format apm '"$time_local" client=$remote_addr '
|
|
2
|
+
'method=$request_method request="$request" '
|
|
3
|
+
'request_length=$request_length '
|
|
4
|
+
'status=$status bytes_sent=$bytes_sent '
|
|
5
|
+
'body_bytes_sent=$body_bytes_sent '
|
|
6
|
+
'referer=$http_referer '
|
|
7
|
+
'user_agent="$http_user_agent" '
|
|
8
|
+
'upstream_addr=$upstream_addr '
|
|
9
|
+
'upstream_status=$upstream_status '
|
|
10
|
+
'request_time=$request_time '
|
|
11
|
+
'upstream_response_time=$upstream_response_time '
|
|
12
|
+
'upstream_connect_time=$upstream_connect_time '
|
|
13
|
+
'upstream_header_time=$upstream_header_time';
|
|
14
|
+
|
|
15
|
+
server {
|
|
16
|
+
listen 80;
|
|
17
|
+
server_name _;
|
|
18
|
+
root {{cwd}}/node_modules/@nocobase/app/dist/client;
|
|
19
|
+
index index.html;
|
|
20
|
+
client_max_body_size 1000M;
|
|
21
|
+
access_log /var/log/nginx/nocobase.log apm;
|
|
22
|
+
|
|
23
|
+
gzip on;
|
|
24
|
+
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
|
25
|
+
|
|
26
|
+
# 不缓存 HTML 文件
|
|
27
|
+
# location ~ \.html$ {
|
|
28
|
+
# if_modified_since off;
|
|
29
|
+
# expires off;
|
|
30
|
+
# etag off;
|
|
31
|
+
# }
|
|
32
|
+
|
|
33
|
+
# # 缓存 JavaScript 和 CSS 文件
|
|
34
|
+
# location ~* \.(js|css)$ {
|
|
35
|
+
# expires 365d;
|
|
36
|
+
# add_header Cache-Control "public";
|
|
37
|
+
# }
|
|
38
|
+
|
|
39
|
+
location {{publicPath}}storage/uploads/ {
|
|
40
|
+
alias {{cwd}}/storage/uploads/;
|
|
41
|
+
add_header Cache-Control "public";
|
|
42
|
+
access_log off;
|
|
43
|
+
autoindex off;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
location {{publicPath}} {
|
|
47
|
+
alias {{cwd}}/node_modules/@nocobase/app/dist/client/;
|
|
48
|
+
try_files $uri $uri/ /index.html;
|
|
49
|
+
add_header Last-Modified $date_gmt;
|
|
50
|
+
add_header Cache-Control 'no-store, no-cache';
|
|
51
|
+
if_modified_since off;
|
|
52
|
+
expires off;
|
|
53
|
+
etag off;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
location ^~ {{publicPath}}api/ {
|
|
57
|
+
proxy_pass http://127.0.0.1:{{apiPort}}{{publicPath}}api/;
|
|
58
|
+
proxy_http_version 1.1;
|
|
59
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
60
|
+
proxy_set_header Connection 'upgrade';
|
|
61
|
+
proxy_set_header Host $host;
|
|
62
|
+
proxy_cache_bypass $http_upgrade;
|
|
63
|
+
proxy_connect_timeout 600;
|
|
64
|
+
proxy_send_timeout 600;
|
|
65
|
+
proxy_read_timeout 600;
|
|
66
|
+
send_timeout 600;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
location ^~ {{publicPath}}static/plugins/ {
|
|
70
|
+
proxy_pass http://127.0.0.1:{{apiPort}}{{publicPath}}static/plugins/;
|
|
71
|
+
proxy_http_version 1.1;
|
|
72
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
73
|
+
proxy_set_header Connection 'upgrade';
|
|
74
|
+
proxy_set_header Host $host;
|
|
75
|
+
proxy_cache_bypass $http_upgrade;
|
|
76
|
+
proxy_connect_timeout 600;
|
|
77
|
+
proxy_send_timeout 600;
|
|
78
|
+
proxy_read_timeout 600;
|
|
79
|
+
send_timeout 600;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
location {{publicPath}}ws {
|
|
83
|
+
proxy_pass http://127.0.0.1:{{apiPort}}{{publicPath}}ws;
|
|
84
|
+
proxy_http_version 1.1;
|
|
85
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
86
|
+
proxy_set_header Connection "Upgrade";
|
|
87
|
+
proxy_set_header Host $host;
|
|
88
|
+
}
|
|
89
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"nocobase": "./bin/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nocobase/app": "0.
|
|
11
|
+
"@nocobase/app": "0.21.0-alpha.1",
|
|
12
12
|
"@types/fs-extra": "^11.0.1",
|
|
13
13
|
"@umijs/utils": "3.5.20",
|
|
14
14
|
"chalk": "^4.1.1",
|
|
15
15
|
"commander": "^9.2.0",
|
|
16
|
-
"dotenv": "^
|
|
16
|
+
"dotenv": "^16.0.0",
|
|
17
17
|
"execa": "^5.1.1",
|
|
18
18
|
"fast-glob": "^3.3.1",
|
|
19
19
|
"fs-extra": "^11.1.1",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"tsx": "^4.6.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@nocobase/devtools": "0.
|
|
28
|
+
"@nocobase/devtools": "0.21.0-alpha.1"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
32
32
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
33
33
|
"directory": "packages/core/cli"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "afd2f3d1341b85ea9daa7b2667dd4ace1fafb7ff"
|
|
36
36
|
}
|
package/src/commands/build.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { resolve } = require('path');
|
|
2
2
|
const { Command } = require('commander');
|
|
3
|
-
const { run, nodeCheck, isPackageValid } = require('../util');
|
|
3
|
+
const { run, nodeCheck, isPackageValid, buildIndexHtml } = require('../util');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
@@ -13,6 +13,7 @@ module.exports = (cli) => {
|
|
|
13
13
|
.argument('[packages...]')
|
|
14
14
|
.option('-v, --version', 'print version')
|
|
15
15
|
.option('-c, --compile', 'compile the @nocobase/build package')
|
|
16
|
+
.option('-r, --retry', 'retry the last failed package')
|
|
16
17
|
.option('-w, --watch', 'watch compile the @nocobase/build package')
|
|
17
18
|
.option('-s, --sourcemap', 'generate sourcemap')
|
|
18
19
|
.option('--no-dts', 'not generate dts')
|
|
@@ -24,12 +25,15 @@ module.exports = (cli) => {
|
|
|
24
25
|
});
|
|
25
26
|
if (options.watch) return;
|
|
26
27
|
}
|
|
28
|
+
process.env['VITE_CJS_IGNORE_WARNING'] = 'true';
|
|
27
29
|
|
|
28
30
|
await run('nocobase-build', [
|
|
29
31
|
...pkgs,
|
|
30
32
|
options.version ? '--version' : '',
|
|
31
33
|
!options.dts ? '--no-dts' : '',
|
|
32
34
|
options.sourcemap ? '--sourcemap' : '',
|
|
35
|
+
options.retry ? '--retry' : '',
|
|
33
36
|
]);
|
|
37
|
+
buildIndexHtml(true);
|
|
34
38
|
});
|
|
35
39
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { resolve } = require('path');
|
|
2
|
+
const { Command } = require('commander');
|
|
3
|
+
const { readFileSync, writeFileSync } = require('fs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {Command} cli
|
|
8
|
+
*/
|
|
9
|
+
module.exports = (cli) => {
|
|
10
|
+
cli.command('create-nginx-conf').action(async (name, options) => {
|
|
11
|
+
const file = resolve(__dirname, '../../nocobase.conf.tpl');
|
|
12
|
+
const data = readFileSync(file, 'utf-8');
|
|
13
|
+
const replaced = data
|
|
14
|
+
.replace(/\{\{cwd\}\}/g, '/app/nocobase')
|
|
15
|
+
.replace(/\{\{publicPath\}\}/g, process.env.APP_PUBLIC_PATH)
|
|
16
|
+
.replace(/\{\{apiPort\}\}/g, process.env.APP_PORT);
|
|
17
|
+
|
|
18
|
+
const targetFile = resolve(process.cwd(), 'storage', 'nocobase.conf');
|
|
19
|
+
writeFileSync(targetFile, replaced);
|
|
20
|
+
});
|
|
21
|
+
};
|
package/src/commands/e2e.js
CHANGED
|
@@ -243,6 +243,12 @@ module.exports = (cli) => {
|
|
|
243
243
|
.option('--stop-on-error')
|
|
244
244
|
.option('--build')
|
|
245
245
|
.option('--concurrency [concurrency]', '', os.cpus().length)
|
|
246
|
+
.option(
|
|
247
|
+
'--match [match]',
|
|
248
|
+
'Only the files matching one of these patterns are executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.',
|
|
249
|
+
'packages/**/__e2e__/**/*.test.ts',
|
|
250
|
+
)
|
|
251
|
+
.option('--ignore [ignore]', 'Skip tests that match the pattern. Strings are treated as glob patterns.', undefined)
|
|
246
252
|
.action(async (options) => {
|
|
247
253
|
process.env.__E2E__ = true;
|
|
248
254
|
if (options.build) {
|
package/src/commands/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const { isPackageValid, generateAppDir } = require('../util');
|
|
|
8
8
|
module.exports = (cli) => {
|
|
9
9
|
generateAppDir();
|
|
10
10
|
require('./global')(cli);
|
|
11
|
+
require('./create-nginx-conf')(cli);
|
|
11
12
|
require('./build')(cli);
|
|
12
13
|
require('./tar')(cli);
|
|
13
14
|
require('./dev')(cli);
|
|
@@ -15,6 +16,7 @@ module.exports = (cli) => {
|
|
|
15
16
|
require('./e2e')(cli);
|
|
16
17
|
require('./clean')(cli);
|
|
17
18
|
require('./doc')(cli);
|
|
19
|
+
require('./pm2')(cli);
|
|
18
20
|
require('./test')(cli);
|
|
19
21
|
require('./umi')(cli);
|
|
20
22
|
require('./upgrade')(cli);
|
package/src/commands/p-test.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
const { Command } = require('commander');
|
|
3
|
+
const { run, isDev } = require('../util');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {Command} cli
|
|
8
|
+
*/
|
|
9
|
+
module.exports = (cli) => {
|
|
10
|
+
cli
|
|
11
|
+
.command('pm2')
|
|
12
|
+
.allowUnknownOption()
|
|
13
|
+
.action(() => {
|
|
14
|
+
run('pm2', process.argv.slice(3));
|
|
15
|
+
});
|
|
16
|
+
cli
|
|
17
|
+
.command('pm2-restart')
|
|
18
|
+
.allowUnknownOption()
|
|
19
|
+
.action(() => {
|
|
20
|
+
run('pm2', ['restart', 'all']);
|
|
21
|
+
});
|
|
22
|
+
cli
|
|
23
|
+
.command('pm2-stop')
|
|
24
|
+
.allowUnknownOption()
|
|
25
|
+
.action(() => {
|
|
26
|
+
run('pm2', ['stop', 'all']);
|
|
27
|
+
});
|
|
28
|
+
};
|
package/src/commands/test.js
CHANGED
|
@@ -19,6 +19,7 @@ function addTestCommand(name, cli) {
|
|
|
19
19
|
.arguments('[paths...]')
|
|
20
20
|
.allowUnknownOption()
|
|
21
21
|
.action(async (paths, opts) => {
|
|
22
|
+
process.argv.push('--disable-console-intercept');
|
|
22
23
|
if (name === 'test:server') {
|
|
23
24
|
process.env.TEST_ENV = 'server-side';
|
|
24
25
|
} else if (name === 'test:client') {
|
package/src/util.js
CHANGED
|
@@ -180,6 +180,7 @@ exports.generateAppDir = function generateAppDir() {
|
|
|
180
180
|
} else {
|
|
181
181
|
process.env.APP_PACKAGE_ROOT = appPkgPath;
|
|
182
182
|
}
|
|
183
|
+
buildIndexHtml();
|
|
183
184
|
};
|
|
184
185
|
|
|
185
186
|
exports.genTsConfigPaths = function genTsConfigPaths() {
|
|
@@ -257,6 +258,30 @@ function parseEnv(name) {
|
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
260
|
|
|
261
|
+
function buildIndexHtml(force = false) {
|
|
262
|
+
const file = `${process.env.APP_PACKAGE_ROOT}/dist/client/index.html`;
|
|
263
|
+
if (!fs.existsSync(file)) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const tpl = `${process.env.APP_PACKAGE_ROOT}/dist/client/index.html.tpl`;
|
|
267
|
+
if (force && fs.existsSync(tpl)) {
|
|
268
|
+
fs.rmSync(tpl);
|
|
269
|
+
}
|
|
270
|
+
if (!fs.existsSync(tpl)) {
|
|
271
|
+
fs.copyFileSync(file, tpl);
|
|
272
|
+
}
|
|
273
|
+
const data = fs.readFileSync(tpl, 'utf-8');
|
|
274
|
+
const replacedData = data
|
|
275
|
+
.replace(/\{\{env.APP_PUBLIC_PATH\}\}/g, process.env.APP_PUBLIC_PATH)
|
|
276
|
+
.replace(/\{\{env.API_BASE_URL\}\}/g, process.env.API_BASE_URL || process.env.API_BASE_PATH)
|
|
277
|
+
.replace(/\{\{env.WS_URL\}\}/g, process.env.WEBSOCKET_URL || '')
|
|
278
|
+
.replace(/\{\{env.WS_PATH\}\}/g, process.env.WS_PATH)
|
|
279
|
+
.replace('src="/umi.', `src="${process.env.APP_PUBLIC_PATH}umi.`);
|
|
280
|
+
fs.writeFileSync(file, replacedData, 'utf-8');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
exports.buildIndexHtml = buildIndexHtml;
|
|
284
|
+
|
|
260
285
|
exports.initEnv = function initEnv() {
|
|
261
286
|
const env = {
|
|
262
287
|
APP_ENV: 'development',
|
|
@@ -280,7 +305,10 @@ exports.initEnv = function initEnv() {
|
|
|
280
305
|
PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), 'storage/playwright/.auth/admin.json'),
|
|
281
306
|
CACHE_DEFAULT_STORE: 'memory',
|
|
282
307
|
CACHE_MEMORY_MAX: 2000,
|
|
308
|
+
PLUGIN_STATICS_PATH: '/static/plugins/',
|
|
283
309
|
LOGGER_BASE_PATH: 'storage/logs',
|
|
310
|
+
APP_SERVER_BASE_URL: '',
|
|
311
|
+
APP_PUBLIC_PATH: '/',
|
|
284
312
|
};
|
|
285
313
|
|
|
286
314
|
if (
|
|
@@ -319,4 +347,18 @@ exports.initEnv = function initEnv() {
|
|
|
319
347
|
process.env[key] = env[key];
|
|
320
348
|
}
|
|
321
349
|
}
|
|
350
|
+
|
|
351
|
+
if (!process.env.__env_modified__ && process.env.APP_PUBLIC_PATH) {
|
|
352
|
+
const publicPath = process.env.APP_PUBLIC_PATH.replace(/\/$/g, '');
|
|
353
|
+
const keys = ['API_BASE_PATH', 'WS_PATH', 'PLUGIN_STATICS_PATH'];
|
|
354
|
+
for (const key of keys) {
|
|
355
|
+
process.env[key] = publicPath + process.env[key];
|
|
356
|
+
}
|
|
357
|
+
process.env.__env_modified__ = true;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (!process.env.__env_modified__ && process.env.APP_SERVER_BASE_URL && !process.env.API_BASE_URL) {
|
|
361
|
+
process.env.API_BASE_URL = process.env.APP_SERVER_BASE_URL + process.env.API_BASE_PATH;
|
|
362
|
+
process.env.__env_modified__ = true;
|
|
363
|
+
}
|
|
322
364
|
};
|