@nocobase/cli 0.20.0-alpha.1 → 0.20.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.
@@ -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.20.0-alpha.1",
3
+ "version": "0.20.0-alpha.11",
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.20.0-alpha.1",
11
+ "@nocobase/app": "0.20.0-alpha.11",
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": "^10.0.0",
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.20.0-alpha.1"
28
+ "@nocobase/devtools": "0.20.0-alpha.11"
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": "516c0b1470d77ff499f533ae6b57e4c084450ff5"
35
+ "gitHead": "ed56e8464869fefbd6e263a2358fc14930c22f96"
36
36
  }
@@ -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
  *
@@ -31,5 +31,6 @@ module.exports = (cli) => {
31
31
  !options.dts ? '--no-dts' : '',
32
32
  options.sourcemap ? '--sourcemap' : '',
33
33
  ]);
34
+ buildIndexHtml(true);
34
35
  });
35
36
  };
@@ -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
+ };
@@ -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);
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,16 @@ exports.initEnv = function initEnv() {
319
347
  process.env[key] = env[key];
320
348
  }
321
349
  }
350
+
351
+ if (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
+ }
358
+
359
+ if (process.env.APP_SERVER_BASE_URL && !process.env.API_BASE_URL) {
360
+ process.env.API_BASE_URL = process.env.APP_SERVER_BASE_URL + process.env.API_BASE_PATH;
361
+ }
322
362
  };