@nocobase/cli 2.1.0-alpha.3 → 2.1.0-alpha.30

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.
Files changed (182) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +379 -19
  3. package/README.zh-CN.md +329 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +131 -0
  6. package/dist/commands/api/resource/create.js +15 -0
  7. package/dist/commands/api/resource/destroy.js +15 -0
  8. package/dist/commands/api/resource/get.js +15 -0
  9. package/dist/commands/api/resource/index.js +20 -0
  10. package/dist/commands/api/resource/list.js +16 -0
  11. package/dist/commands/api/resource/query.js +15 -0
  12. package/dist/commands/api/resource/update.js +15 -0
  13. package/dist/commands/app/down.js +266 -0
  14. package/dist/commands/app/logs.js +98 -0
  15. package/dist/commands/app/restart.js +75 -0
  16. package/dist/commands/app/start.js +253 -0
  17. package/dist/commands/app/stop.js +99 -0
  18. package/dist/commands/app/upgrade.js +582 -0
  19. package/{src/cli.js → dist/commands/build.js} +4 -11
  20. package/dist/commands/config/delete.js +30 -0
  21. package/dist/commands/config/get.js +29 -0
  22. package/dist/commands/config/index.js +20 -0
  23. package/dist/commands/config/list.js +29 -0
  24. package/dist/commands/config/set.js +35 -0
  25. package/dist/commands/db/check.js +238 -0
  26. package/dist/commands/db/logs.js +85 -0
  27. package/dist/commands/db/ps.js +60 -0
  28. package/dist/commands/db/shared.js +96 -0
  29. package/dist/commands/db/start.js +71 -0
  30. package/dist/commands/db/stop.js +71 -0
  31. package/{templates/plugin/src/client/models/index.ts → dist/commands/dev.js} +4 -4
  32. package/{src/index.js → dist/commands/down.js} +4 -6
  33. package/{src/commands/locale/react-js-cron/index.js → dist/commands/download.js} +4 -8
  34. package/dist/commands/env/add.js +312 -0
  35. package/dist/commands/env/auth.js +55 -0
  36. package/dist/commands/env/info.js +156 -0
  37. package/dist/commands/env/list.js +50 -0
  38. package/dist/commands/env/remove.js +59 -0
  39. package/dist/commands/env/shared.js +158 -0
  40. package/dist/commands/env/update.js +67 -0
  41. package/dist/commands/env/use.js +28 -0
  42. package/dist/commands/examples/prompts-stages.js +150 -0
  43. package/dist/commands/examples/prompts-test.js +181 -0
  44. package/dist/commands/init.js +1027 -0
  45. package/dist/commands/install.js +2206 -0
  46. package/dist/commands/license/activate.js +360 -0
  47. package/dist/commands/license/env.js +94 -0
  48. package/dist/commands/license/generate-id.js +108 -0
  49. package/dist/commands/license/id.js +56 -0
  50. package/dist/commands/license/index.js +20 -0
  51. package/dist/commands/license/plugins/clean.js +101 -0
  52. package/dist/commands/license/plugins/index.js +20 -0
  53. package/dist/commands/license/plugins/list.js +50 -0
  54. package/dist/commands/license/plugins/shared.js +325 -0
  55. package/dist/commands/license/plugins/sync.js +269 -0
  56. package/dist/commands/license/shared.js +414 -0
  57. package/dist/commands/license/status.js +50 -0
  58. package/dist/commands/logs.js +12 -0
  59. package/dist/commands/plugin/disable.js +66 -0
  60. package/dist/commands/plugin/enable.js +66 -0
  61. package/dist/commands/plugin/list.js +62 -0
  62. package/dist/commands/pm/disable.js +12 -0
  63. package/dist/commands/pm/enable.js +12 -0
  64. package/dist/commands/pm/list.js +12 -0
  65. package/dist/commands/restart.js +12 -0
  66. package/dist/commands/scaffold/migration.js +38 -0
  67. package/dist/commands/scaffold/plugin.js +37 -0
  68. package/dist/commands/self/check.js +71 -0
  69. package/dist/commands/self/index.js +20 -0
  70. package/dist/commands/self/update.js +86 -0
  71. package/dist/commands/skills/check.js +69 -0
  72. package/dist/commands/skills/index.js +20 -0
  73. package/dist/commands/skills/install.js +71 -0
  74. package/dist/commands/skills/remove.js +71 -0
  75. package/dist/commands/skills/update.js +78 -0
  76. package/dist/commands/source/build.js +58 -0
  77. package/dist/commands/source/dev.js +158 -0
  78. package/dist/commands/source/download.js +866 -0
  79. package/dist/commands/source/test.js +467 -0
  80. package/dist/commands/start.js +12 -0
  81. package/dist/commands/stop.js +12 -0
  82. package/dist/commands/test.js +12 -0
  83. package/dist/commands/upgrade.js +12 -0
  84. package/dist/generated/command-registry.js +133 -0
  85. package/dist/help/runtime-help.js +23 -0
  86. package/dist/lib/api-client.js +329 -0
  87. package/dist/lib/app-health.js +126 -0
  88. package/dist/lib/app-managed-resources.js +268 -0
  89. package/dist/lib/app-runtime.js +171 -0
  90. package/dist/lib/auth-store.js +328 -0
  91. package/dist/lib/bootstrap.js +384 -0
  92. package/dist/lib/build-config.js +18 -0
  93. package/dist/lib/builtin-db.js +86 -0
  94. package/dist/lib/cli-config.js +176 -0
  95. package/dist/lib/cli-home.js +47 -0
  96. package/dist/lib/cli-locale.js +129 -0
  97. package/dist/lib/command-discovery.js +39 -0
  98. package/dist/lib/db-connection-check.js +178 -0
  99. package/dist/lib/env-auth.js +872 -0
  100. package/dist/lib/env-config.js +87 -0
  101. package/dist/lib/generated-command.js +171 -0
  102. package/dist/lib/http-request.js +49 -0
  103. package/dist/lib/naming.js +70 -0
  104. package/dist/lib/openapi.js +62 -0
  105. package/dist/lib/plugin-storage.js +127 -0
  106. package/dist/lib/post-processors.js +23 -0
  107. package/dist/lib/prompt-catalog.js +581 -0
  108. package/dist/lib/prompt-validators.js +185 -0
  109. package/dist/lib/prompt-web-ui.js +2103 -0
  110. package/dist/lib/resource-command.js +343 -0
  111. package/dist/lib/resource-request.js +104 -0
  112. package/dist/lib/run-npm.js +250 -0
  113. package/dist/lib/runtime-env-vars.js +32 -0
  114. package/dist/lib/runtime-generator.js +498 -0
  115. package/dist/lib/runtime-store.js +56 -0
  116. package/dist/lib/self-manager.js +301 -0
  117. package/dist/lib/skills-manager.js +296 -0
  118. package/dist/lib/startup-update.js +281 -0
  119. package/dist/lib/ui.js +178 -0
  120. package/dist/locale/en-US.json +339 -0
  121. package/dist/locale/zh-CN.json +339 -0
  122. package/dist/post-processors/data-modeling.js +66 -0
  123. package/dist/post-processors/data-source-manager.js +114 -0
  124. package/dist/post-processors/index.js +19 -0
  125. package/nocobase-ctl.config.json +369 -0
  126. package/package.json +95 -26
  127. package/LICENSE +0 -661
  128. package/bin/index.js +0 -39
  129. package/nocobase.conf.tpl +0 -95
  130. package/src/commands/benchmark.js +0 -73
  131. package/src/commands/build.js +0 -49
  132. package/src/commands/clean.js +0 -30
  133. package/src/commands/client.js +0 -166
  134. package/src/commands/create-nginx-conf.js +0 -37
  135. package/src/commands/create-plugin.js +0 -33
  136. package/src/commands/dev.js +0 -200
  137. package/src/commands/doc.js +0 -76
  138. package/src/commands/e2e.js +0 -265
  139. package/src/commands/global.js +0 -43
  140. package/src/commands/index.js +0 -45
  141. package/src/commands/instance-id.js +0 -47
  142. package/src/commands/locale/cronstrue.js +0 -122
  143. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  144. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  145. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  146. package/src/commands/locale.js +0 -81
  147. package/src/commands/p-test.js +0 -88
  148. package/src/commands/perf.js +0 -63
  149. package/src/commands/pkg.js +0 -321
  150. package/src/commands/pm2.js +0 -37
  151. package/src/commands/postinstall.js +0 -88
  152. package/src/commands/start.js +0 -148
  153. package/src/commands/tar.js +0 -36
  154. package/src/commands/test-coverage.js +0 -55
  155. package/src/commands/test.js +0 -107
  156. package/src/commands/umi.js +0 -33
  157. package/src/commands/update-deps.js +0 -72
  158. package/src/commands/upgrade.js +0 -47
  159. package/src/commands/view-license-key.js +0 -44
  160. package/src/license.js +0 -76
  161. package/src/logger.js +0 -75
  162. package/src/plugin-generator.js +0 -80
  163. package/src/util.js +0 -517
  164. package/templates/bundle-status.html +0 -338
  165. package/templates/create-app-package.json +0 -39
  166. package/templates/plugin/.npmignore.tpl +0 -2
  167. package/templates/plugin/README.md.tpl +0 -1
  168. package/templates/plugin/client.d.ts +0 -2
  169. package/templates/plugin/client.js +0 -1
  170. package/templates/plugin/package.json.tpl +0 -11
  171. package/templates/plugin/server.d.ts +0 -2
  172. package/templates/plugin/server.js +0 -1
  173. package/templates/plugin/src/client/client.d.ts +0 -249
  174. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  175. package/templates/plugin/src/client/locale.ts +0 -21
  176. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  177. package/templates/plugin/src/index.ts +0 -2
  178. package/templates/plugin/src/locale/en-US.json +0 -1
  179. package/templates/plugin/src/locale/zh-CN.json +0 -1
  180. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  181. package/templates/plugin/src/server/index.ts.tpl +0 -1
  182. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
package/src/util.js DELETED
@@ -1,517 +0,0 @@
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 net = require('net');
11
- const chalk = require('chalk');
12
- const execa = require('execa');
13
- const fg = require('fast-glob');
14
- const { dirname, join, resolve, sep, isAbsolute } = require('path');
15
- const { readFile, writeFile } = require('fs').promises;
16
- const { existsSync, mkdirSync, cpSync, writeFileSync } = require('fs');
17
- const dotenv = require('dotenv');
18
- const fs = require('fs-extra');
19
- const os = require('os');
20
- const moment = require('moment-timezone');
21
-
22
- exports.isPackageValid = (pkg) => {
23
- try {
24
- require.resolve(pkg);
25
- return true;
26
- } catch (error) {
27
- return false;
28
- }
29
- };
30
-
31
- exports.hasCorePackages = () => {
32
- const coreDir = resolve(process.cwd(), 'packages/core/build');
33
- return existsSync(coreDir);
34
- };
35
-
36
- exports.hasTsNode = () => {
37
- return exports.isPackageValid('ts-node/dist/bin');
38
- };
39
-
40
- exports.isDev = function isDev() {
41
- if (process.env.APP_ENV === 'production') {
42
- return false;
43
- }
44
- return exports.hasTsNode();
45
- };
46
-
47
- const isProd = () => {
48
- const { APP_PACKAGE_ROOT } = process.env;
49
- const file = `${APP_PACKAGE_ROOT}/lib/index.js`;
50
- if (!existsSync(resolve(process.cwd(), file))) {
51
- console.log('For production environment, please build the code first.');
52
- console.log();
53
- console.log(chalk.yellow('$ yarn build'));
54
- console.log();
55
- process.exit(1);
56
- }
57
- return true;
58
- };
59
-
60
- exports.isProd = isProd;
61
-
62
- exports.nodeCheck = () => {
63
- if (!exports.hasTsNode()) {
64
- console.log('Please install all dependencies');
65
- console.log(chalk.yellow('$ yarn install'));
66
- process.exit(1);
67
- }
68
- };
69
-
70
- exports.run = (command, args, options = {}) => {
71
- if (command === 'tsx') {
72
- command = 'node';
73
- args = ['./node_modules/tsx/dist/cli.mjs'].concat(args || []);
74
- }
75
- return execa(command, args, {
76
- shell: true,
77
- stdio: 'inherit',
78
- ...options,
79
- env: {
80
- ...process.env,
81
- ...options.env,
82
- },
83
- });
84
- };
85
-
86
- exports.isPortReachable = async (port, { timeout = 1000, host } = {}) => {
87
- const promise = new Promise((resolve, reject) => {
88
- const socket = new net.Socket();
89
-
90
- const onError = () => {
91
- socket.destroy();
92
- reject();
93
- };
94
-
95
- socket.setTimeout(timeout);
96
- socket.once('error', onError);
97
- socket.once('timeout', onError);
98
-
99
- socket.connect(port, host, () => {
100
- socket.end();
101
- resolve();
102
- });
103
- });
104
-
105
- try {
106
- await promise;
107
- return true;
108
- } catch (_) {
109
- return false;
110
- }
111
- };
112
-
113
- exports.postCheck = async (opts) => {
114
- const port = opts.port || process.env.APP_PORT;
115
- const result = await exports.isPortReachable(port);
116
- if (result) {
117
- console.error(chalk.red(`Port ${port} already in use`));
118
- process.exit(1);
119
- }
120
- };
121
-
122
- exports.runInstall = async () => {
123
- const { APP_PACKAGE_ROOT, SERVER_TSCONFIG_PATH } = process.env;
124
-
125
- if (exports.isDev()) {
126
- const argv = [
127
- '--tsconfig',
128
- SERVER_TSCONFIG_PATH,
129
- '-r',
130
- 'tsconfig-paths/register',
131
- `${APP_PACKAGE_ROOT}/src/index.ts`,
132
- 'install',
133
- '-s',
134
- ];
135
- await exports.run('tsx', argv);
136
- } else if (isProd()) {
137
- const file = `${APP_PACKAGE_ROOT}/lib/index.js`;
138
- const argv = [file, 'install', '-s'];
139
- await exports.run('node', argv);
140
- }
141
- };
142
-
143
- exports.runAppCommand = async (command, args = []) => {
144
- const { APP_PACKAGE_ROOT, SERVER_TSCONFIG_PATH } = process.env;
145
-
146
- if (exports.isDev()) {
147
- const argv = [
148
- '--tsconfig',
149
- SERVER_TSCONFIG_PATH,
150
- '-r',
151
- 'tsconfig-paths/register',
152
- `${APP_PACKAGE_ROOT}/src/index.ts`,
153
- command,
154
- ...args,
155
- ];
156
- await exports.run('tsx', argv);
157
- } else if (isProd()) {
158
- const argv = [`${APP_PACKAGE_ROOT}/lib/index.js`, command, ...args];
159
- await exports.run('node', argv);
160
- }
161
- };
162
-
163
- exports.promptForTs = () => {
164
- console.log(chalk.green('WAIT: ') + 'TypeScript compiling...');
165
- };
166
-
167
- exports.downloadPro = async () => {
168
- // 此处不再判定,由pkgg命令处理
169
- // const { NOCOBASE_PKG_USERNAME, NOCOBASE_PKG_PASSWORD } = process.env;
170
- // if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) {
171
- // return;
172
- // }
173
- await exports.run('yarn', ['nocobase', 'pkg', 'download-pro']);
174
- };
175
-
176
- exports.updateJsonFile = async (target, fn) => {
177
- const content = await readFile(target, 'utf-8');
178
- const json = JSON.parse(content);
179
- await writeFile(target, JSON.stringify(fn(json), null, 2), 'utf-8');
180
- };
181
-
182
- exports.getVersion = async () => {
183
- const { stdout } = await execa('npm', ['v', '@nocobase/app-server', 'versions']);
184
- const versions = new Function(`return (${stdout})`)();
185
- return versions[versions.length - 1];
186
- };
187
-
188
- exports.generateAppDir = function generateAppDir() {
189
- const appPkgPath = dirname(dirname(require.resolve('@nocobase/app/src/index.ts')));
190
- const appDevDir = resolve(process.cwd(), './storage/.app-dev');
191
- if (exports.isDev() && !exports.hasCorePackages() && appPkgPath.includes('node_modules')) {
192
- if (!existsSync(appDevDir)) {
193
- mkdirSync(appDevDir, { force: true, recursive: true });
194
- cpSync(appPkgPath, appDevDir, {
195
- recursive: true,
196
- force: true,
197
- });
198
- }
199
- process.env.APP_PACKAGE_ROOT = appDevDir;
200
- } else {
201
- process.env.APP_PACKAGE_ROOT = appPkgPath;
202
- }
203
- buildIndexHtml();
204
- };
205
-
206
- exports.genTsConfigPaths = function genTsConfigPaths() {
207
- try {
208
- fs.unlinkSync(resolve(process.cwd(), 'node_modules/.bin/tsx'));
209
- fs.symlinkSync(
210
- resolve(process.cwd(), 'node_modules/tsx/dist/cli.mjs'),
211
- resolve(process.cwd(), 'node_modules/.bin/tsx'),
212
- 'file',
213
- );
214
- } catch (error) {
215
- //
216
- }
217
-
218
- const cwd = process.cwd();
219
- const cwdLength = cwd.length;
220
- const paths = {
221
- '@@/*': ['.dumi/tmp/*'],
222
- };
223
- const packages = fg.sync(['packages/*/*/package.json', 'packages/*/*/*/package.json'], {
224
- absolute: true,
225
- onlyFiles: true,
226
- });
227
- packages.forEach((packageFile) => {
228
- const packageJsonName = require(packageFile).name;
229
- const packageDir = dirname(packageFile);
230
- const relativePath = packageDir
231
- .slice(cwdLength + 1)
232
- .split(sep)
233
- .join('/');
234
- paths[`${packageJsonName}/client`] = [`${relativePath}/src/client`];
235
- paths[`${packageJsonName}/package.json`] = [`${relativePath}/package.json`];
236
- paths[packageJsonName] = [`${relativePath}/src`];
237
- if (packageJsonName === '@nocobase/test') {
238
- paths[`${packageJsonName}/server`] = [`${relativePath}/src/server`];
239
- paths[`${packageJsonName}/e2e`] = [`${relativePath}/src/e2e`];
240
- paths[`${packageJsonName}/web`] = [`${relativePath}/src/web`];
241
- }
242
- if (packageJsonName === '@nocobase/client') {
243
- paths[`${packageJsonName}/demo-utils`] = [`${relativePath}/src/demo-utils`];
244
- }
245
- if (packageJsonName === '@nocobase/plugin-workflow-test') {
246
- paths[`${packageJsonName}/e2e`] = [`${relativePath}/src/e2e`];
247
- }
248
- });
249
-
250
- const tsConfigJsonPath = join(cwd, './tsconfig.paths.json');
251
- const content = { compilerOptions: { paths } };
252
- writeFileSync(tsConfigJsonPath, JSON.stringify(content, null, 2), 'utf-8');
253
- return content;
254
- };
255
-
256
- function generatePlaywrightPath(clean = false) {
257
- try {
258
- const playwright = resolve(process.cwd(), 'storage/playwright/tests');
259
- if (clean && fs.existsSync(playwright)) {
260
- fs.rmSync(dirname(playwright), { force: true, recursive: true });
261
- }
262
- if (!fs.existsSync(playwright)) {
263
- const testPkg = require.resolve('@nocobase/test/package.json');
264
- fs.cpSync(resolve(dirname(testPkg), 'playwright/tests'), playwright, { recursive: true });
265
- }
266
- } catch (error) {
267
- // empty
268
- }
269
- }
270
-
271
- exports.generatePlaywrightPath = generatePlaywrightPath;
272
-
273
- function parseEnv(name) {
274
- if (name === 'DB_UNDERSCORED') {
275
- if (process.env.DB_UNDERSCORED === 'true') {
276
- return 'true';
277
- }
278
- if (process.env.DB_UNDERSCORED) {
279
- return 'true';
280
- }
281
- return 'false';
282
- }
283
- }
284
-
285
- function buildIndexHtml(force = false) {
286
- const file = `${process.env.APP_PACKAGE_ROOT}/dist/client/index.html`;
287
- if (!fs.existsSync(file)) {
288
- return;
289
- }
290
- const tpl = `${process.env.APP_PACKAGE_ROOT}/dist/client/index.html.tpl`;
291
- if (force && fs.existsSync(tpl)) {
292
- fs.rmSync(tpl);
293
- }
294
- if (!fs.existsSync(tpl)) {
295
- fs.copyFileSync(file, tpl);
296
- }
297
- const data = fs.readFileSync(tpl, 'utf-8');
298
- let replacedData = data
299
- .replace(/\{\{env.CDN_BASE_URL\}\}/g, process.env.CDN_BASE_URL)
300
- .replace(/\{\{env.APP_PUBLIC_PATH\}\}/g, process.env.APP_PUBLIC_PATH)
301
- .replace(/\{\{env.API_CLIENT_SHARE_TOKEN\}\}/g, process.env.API_CLIENT_SHARE_TOKEN || 'false')
302
- .replace(/\{\{env.API_CLIENT_STORAGE_TYPE\}\}/g, process.env.API_CLIENT_STORAGE_TYPE)
303
- .replace(/\{\{env.API_CLIENT_STORAGE_PREFIX\}\}/g, process.env.API_CLIENT_STORAGE_PREFIX)
304
- .replace(/\{\{env.API_BASE_URL\}\}/g, process.env.API_BASE_URL || process.env.API_BASE_PATH)
305
- .replace(/\{\{env.WS_URL\}\}/g, process.env.WEBSOCKET_URL || '')
306
- .replace(/\{\{env.WS_PATH\}\}/g, process.env.WS_PATH)
307
- .replace(/\{\{env.ESM_CDN_BASE_URL\}\}/g, process.env.ESM_CDN_BASE_URL || '')
308
- .replace(/\{\{env.ESM_CDN_SUFFIX\}\}/g, process.env.ESM_CDN_SUFFIX || '')
309
- .replace('src="/umi.', `src="${process.env.APP_PUBLIC_PATH}umi.`);
310
-
311
- if (process.env.CDN_BASE_URL) {
312
- const appBaseUrl = process.env.CDN_BASE_URL.replace(/\/+$/, '');
313
- const appPublicPath = process.env.APP_PUBLIC_PATH.replace(/\/+$/, '');
314
- const re1 = new RegExp(`src="${appPublicPath}/`, 'g');
315
- const re2 = new RegExp(`href="${appPublicPath}/`, 'g');
316
- replacedData = replacedData.replace(re1, `src="${appBaseUrl}/`).replace(re2, `href="${appBaseUrl}/`);
317
- }
318
- fs.writeFileSync(file, replacedData, 'utf-8');
319
- }
320
-
321
- exports.buildIndexHtml = buildIndexHtml;
322
-
323
- function getTimezonesByOffset(offset) {
324
- if (!/^[+-]\d{1,2}:\d{2}$/.test(offset)) {
325
- return offset;
326
- }
327
- const offsetMinutes = moment.duration(offset).asMinutes();
328
- return moment.tz.names().find((timezone) => {
329
- return moment.tz(timezone).utcOffset() === offsetMinutes;
330
- });
331
- }
332
-
333
- function areTimeZonesEqual(timeZone1, timeZone2) {
334
- if (timeZone1 === timeZone2) {
335
- return true;
336
- }
337
- timeZone1 = getTimezonesByOffset(timeZone1);
338
- timeZone2 = getTimezonesByOffset(timeZone2);
339
- return moment.tz(timeZone1).format('Z') === moment.tz(timeZone2).format('Z');
340
- }
341
-
342
- function generateGatewayPath() {
343
- if (process.env.SOCKET_PATH) {
344
- if (isAbsolute(process.env.SOCKET_PATH)) {
345
- return process.env.SOCKET_PATH;
346
- }
347
- return resolve(process.cwd(), process.env.SOCKET_PATH);
348
- }
349
- if (process.env.NOCOBASE_RUNNING_IN_DOCKER === 'true') {
350
- return resolve(os.homedir(), '.nocobase', 'gateway.sock');
351
- }
352
- return resolve(process.cwd(), 'storage/gateway.sock');
353
- }
354
-
355
- function generatePm2Home() {
356
- if (process.env.PM2_HOME) {
357
- if (isAbsolute(process.env.PM2_HOME)) {
358
- return process.env.PM2_HOME;
359
- }
360
- return resolve(process.cwd(), process.env.PM2_HOME);
361
- }
362
- if (process.env.NOCOBASE_RUNNING_IN_DOCKER === 'true') {
363
- return resolve(os.homedir(), '.nocobase', 'pm2');
364
- }
365
- return resolve(process.cwd(), './storage/.pm2');
366
- }
367
-
368
- exports.initEnv = function initEnv() {
369
- const env = {
370
- APP_ENV: 'development',
371
- APP_KEY: 'test-jwt-secret',
372
- APP_PORT: 13000,
373
- API_BASE_PATH: '/api/',
374
- API_CLIENT_STORAGE_PREFIX: 'NOCOBASE_',
375
- API_CLIENT_SHARE_TOKEN: 'false',
376
- API_CLIENT_STORAGE_TYPE: 'localStorage',
377
- // DB_DIALECT: 'sqlite',
378
- DB_STORAGE: 'storage/db/nocobase.sqlite',
379
- // DB_TIMEZONE: '+00:00',
380
- DB_UNDERSCORED: parseEnv('DB_UNDERSCORED'),
381
- DEFAULT_STORAGE_TYPE: 'local',
382
- LOCAL_STORAGE_DEST: 'storage/uploads',
383
- PLUGIN_STORAGE_PATH: resolve(process.cwd(), 'storage/plugins'),
384
- MFSU_AD: 'none',
385
- MAKO_AD: 'none',
386
- WS_PATH: '/ws',
387
- // PM2_HOME: generatePm2Home(),
388
- // SOCKET_PATH: generateGatewayPath(),
389
- NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),
390
- PLUGIN_PACKAGE_PREFIX: '@nocobase/plugin-,@nocobase/plugin-sample-,@nocobase/preset-',
391
- SERVER_TSCONFIG_PATH: './tsconfig.server.json',
392
- PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), 'storage/playwright/.auth/admin.json'),
393
- CACHE_DEFAULT_STORE: 'memory',
394
- CACHE_MEMORY_MAX: 2000,
395
- BROWSERSLIST_IGNORE_OLD_DATA: true,
396
- PLUGIN_STATICS_PATH: '/static/plugins/',
397
- LOGGER_BASE_PATH: 'storage/logs',
398
- APP_SERVER_BASE_URL: '',
399
- APP_BASE_URL: '',
400
- CDN_BASE_URL: '',
401
- APP_PUBLIC_PATH: '/',
402
- WATCH_FILE: resolve(process.cwd(), 'storage/app.watch.ts'),
403
- ESM_CDN_BASE_URL: 'https://esm.sh',
404
- ESM_CDN_SUFFIX: '',
405
- };
406
-
407
- if (
408
- !process.env.APP_ENV_PATH &&
409
- process.argv[2] &&
410
- ['test', 'test:client', 'test:server', 'benchmark', 'perf'].includes(process.argv[2])
411
- ) {
412
- if (fs.existsSync(resolve(process.cwd(), '.env.test'))) {
413
- process.env.APP_ENV_PATH = '.env.test';
414
- }
415
- }
416
-
417
- if (!process.env.APP_ENV_PATH && process.argv[2] === 'e2e') {
418
- // 用于存放 playwright 自动生成的相关的文件
419
- generatePlaywrightPath();
420
- if (!fs.existsSync('.env.e2e') && fs.existsSync('.env.e2e.example')) {
421
- const env = fs.readFileSync('.env.e2e.example');
422
- fs.writeFileSync('.env.e2e', env);
423
- }
424
- if (!fs.existsSync('.env.e2e')) {
425
- throw new Error('Please create .env.e2e file first!');
426
- }
427
- process.env.APP_ENV_PATH = '.env.e2e';
428
- }
429
-
430
- dotenv.config({
431
- path: resolve(process.cwd(), process.env.APP_ENV_PATH || '.env'),
432
- });
433
-
434
- if (process.argv[2] === 'e2e' && !process.env.APP_BASE_URL) {
435
- process.env.APP_BASE_URL = `http://127.0.0.1:${process.env.APP_PORT}`;
436
- }
437
-
438
- for (const key in env) {
439
- if (!process.env[key]) {
440
- process.env[key] = env[key];
441
- }
442
- }
443
-
444
- if (!process.env.__env_modified__ && process.env.APP_PUBLIC_PATH) {
445
- const publicPath = process.env.APP_PUBLIC_PATH.replace(/\/$/g, '');
446
- const keys = ['API_BASE_PATH', 'WS_PATH', 'PLUGIN_STATICS_PATH'];
447
- for (const key of keys) {
448
- process.env[key] = publicPath + process.env[key];
449
- }
450
- process.env.__env_modified__ = true;
451
- }
452
-
453
- if (!process.env.__env_modified__ && process.env.APP_SERVER_BASE_URL && !process.env.API_BASE_URL) {
454
- process.env.API_BASE_URL = process.env.APP_SERVER_BASE_URL + process.env.API_BASE_PATH;
455
- process.env.__env_modified__ = true;
456
- }
457
-
458
- if (!process.env.CDN_BASE_URL && process.env.APP_PUBLIC_PATH !== '/') {
459
- process.env.CDN_BASE_URL = process.env.APP_PUBLIC_PATH;
460
- }
461
-
462
- if (process.env.CDN_BASE_URL.includes('http') && process.env.CDN_VERSION === 'auto') {
463
- const version = require('../package.json').version;
464
- process.env.CDN_BASE_URL = process.env.CDN_BASE_URL.replace(/\/+$/, '') + '/' + version + '/';
465
- process.env.CDN_VERSION = '';
466
- }
467
-
468
- if (!process.env.TZ) {
469
- const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
470
- process.env.TZ = getTimezonesByOffset(process.env.DB_TIMEZONE || timeZone);
471
- }
472
-
473
- if (!process.env.DB_TIMEZONE) {
474
- process.env.DB_TIMEZONE = process.env.TZ;
475
- }
476
-
477
- if (!/^[+-]\d{1,2}:\d{2}$/.test(process.env.DB_TIMEZONE)) {
478
- process.env.DB_TIMEZONE = moment.tz(process.env.DB_TIMEZONE).format('Z');
479
- }
480
-
481
- if (!areTimeZonesEqual(process.env.DB_TIMEZONE, process.env.TZ)) {
482
- throw new Error(
483
- `process.env.DB_TIMEZONE="${process.env.DB_TIMEZONE}" and process.env.TZ="${process.env.TZ}" are different`,
484
- );
485
- }
486
-
487
- process.env.PM2_HOME = generatePm2Home();
488
- process.env.SOCKET_PATH = generateGatewayPath();
489
- fs.mkdirpSync(dirname(process.env.SOCKET_PATH), { force: true, recursive: true });
490
- fs.mkdirpSync(process.env.PM2_HOME, { force: true, recursive: true });
491
- const pkgs = [
492
- '@nocobase/plugin-multi-app-manager',
493
- '@nocobase/plugin-departments',
494
- '@nocobase/plugin-field-attachment-url',
495
- '@nocobase/plugin-workflow-response-message',
496
- ];
497
- for (const pkg of pkgs) {
498
- const pkgDir = resolve(process.cwd(), 'storage/plugins', pkg);
499
- fs.existsSync(pkgDir) && fs.rmdirSync(pkgDir, { recursive: true, force: true });
500
- }
501
- };
502
-
503
- exports.checkDBDialect = function () {
504
- if (!process.env.DB_DIALECT) {
505
- throw new Error('DB_DIALECT is required.');
506
- }
507
- };
508
-
509
- exports.generatePlugins = function () {
510
- try {
511
- require.resolve('@nocobase/devtools/umiConfig');
512
- const { generatePlugins } = require('@nocobase/devtools/umiConfig');
513
- generatePlugins();
514
- } catch (error) {
515
- return;
516
- }
517
- };