@nocobase/cli 2.1.0-beta.14 → 2.1.0-beta.16
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.txt +107 -0
- package/README.md +307 -63
- package/README.zh-CN.md +332 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +114 -0
- package/dist/commands/api/resource/create.js +15 -0
- package/dist/commands/api/resource/destroy.js +15 -0
- package/dist/commands/api/resource/get.js +15 -0
- package/dist/commands/api/resource/index.js +20 -0
- package/dist/commands/api/resource/list.js +16 -0
- package/dist/commands/api/resource/query.js +15 -0
- package/dist/commands/api/resource/update.js +15 -0
- package/dist/commands/build.js +57 -0
- package/dist/commands/db/logs.js +85 -0
- package/dist/commands/db/ps.js +60 -0
- package/dist/commands/db/shared.js +81 -0
- package/dist/commands/db/start.js +70 -0
- package/dist/commands/db/stop.js +70 -0
- package/dist/commands/dev.js +149 -0
- package/dist/commands/down.js +193 -0
- package/dist/commands/download.js +743 -0
- package/dist/commands/env/add.js +327 -0
- package/dist/commands/env/auth.js +62 -0
- package/dist/commands/env/list.js +41 -0
- package/dist/commands/env/remove.js +65 -0
- package/dist/commands/env/update.js +73 -0
- package/dist/commands/env/use.js +36 -0
- package/dist/commands/init.js +806 -0
- package/dist/commands/install.js +1840 -0
- package/dist/commands/logs.js +90 -0
- package/dist/commands/pm/disable.js +63 -0
- package/dist/commands/pm/enable.js +63 -0
- package/dist/commands/pm/list.js +54 -0
- package/dist/commands/prompts-stages.js +150 -0
- package/dist/commands/prompts-test.js +181 -0
- package/dist/commands/ps.js +116 -0
- package/dist/commands/scaffold/migration.js +38 -0
- package/dist/commands/scaffold/plugin.js +37 -0
- package/dist/commands/start.js +211 -0
- package/dist/commands/stop.js +90 -0
- package/dist/commands/upgrade.js +583 -0
- package/dist/generated/command-registry.js +133 -0
- package/dist/help/runtime-help.js +20 -0
- package/dist/lib/api-client.js +243 -0
- package/dist/lib/app-runtime.js +142 -0
- package/dist/lib/auth-store.js +241 -0
- package/dist/lib/bootstrap.js +387 -0
- package/dist/lib/build-config.js +10 -0
- package/dist/lib/cli-home.js +30 -0
- package/dist/lib/cli-locale.js +115 -0
- package/dist/lib/command-discovery.js +39 -0
- package/dist/lib/env-auth.js +872 -0
- package/dist/lib/generated-command.js +142 -0
- package/dist/lib/naming.js +70 -0
- package/dist/lib/openapi.js +62 -0
- package/dist/lib/post-processors.js +23 -0
- package/dist/lib/prompt-catalog.js +574 -0
- package/dist/lib/prompt-validators.js +185 -0
- package/dist/lib/prompt-web-ui.js +2061 -0
- package/dist/lib/resource-command.js +335 -0
- package/dist/lib/resource-request.js +104 -0
- package/dist/lib/run-npm.js +123 -0
- package/dist/lib/runtime-generator.js +419 -0
- package/dist/lib/runtime-store.js +56 -0
- package/dist/lib/ui.js +175 -0
- package/dist/locale/en-US.json +282 -0
- package/dist/locale/zh-CN.json +282 -0
- package/dist/post-processors/data-modeling.js +66 -0
- package/dist/post-processors/data-source-manager.js +114 -0
- package/dist/post-processors/index.js +19 -0
- package/nocobase-ctl.config.json +287 -0
- package/package.json +52 -25
- package/LICENSE +0 -201
- package/bin/index.js +0 -39
- package/nocobase.conf.tpl +0 -95
- package/src/cli.js +0 -19
- package/src/commands/benchmark.js +0 -73
- package/src/commands/build.js +0 -49
- package/src/commands/clean.js +0 -30
- package/src/commands/client.js +0 -166
- package/src/commands/create-nginx-conf.js +0 -37
- package/src/commands/create-plugin.js +0 -33
- package/src/commands/dev.js +0 -200
- package/src/commands/doc.js +0 -76
- package/src/commands/e2e.js +0 -265
- package/src/commands/global.js +0 -43
- package/src/commands/index.js +0 -45
- package/src/commands/instance-id.js +0 -47
- package/src/commands/locale/cronstrue.js +0 -122
- package/src/commands/locale/react-js-cron/en-US.json +0 -75
- package/src/commands/locale/react-js-cron/index.js +0 -17
- package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
- package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
- package/src/commands/locale.js +0 -81
- package/src/commands/p-test.js +0 -88
- package/src/commands/perf.js +0 -63
- package/src/commands/pkg.js +0 -321
- package/src/commands/pm2.js +0 -37
- package/src/commands/postinstall.js +0 -88
- package/src/commands/start.js +0 -148
- package/src/commands/tar.js +0 -36
- package/src/commands/test-coverage.js +0 -55
- package/src/commands/test.js +0 -107
- package/src/commands/umi.js +0 -33
- package/src/commands/update-deps.js +0 -72
- package/src/commands/upgrade.js +0 -47
- package/src/commands/view-license-key.js +0 -44
- package/src/index.js +0 -14
- package/src/license.js +0 -76
- package/src/logger.js +0 -75
- package/src/plugin-generator.js +0 -80
- package/src/util.js +0 -517
- package/templates/bundle-status.html +0 -338
- package/templates/create-app-package.json +0 -39
- package/templates/plugin/.npmignore.tpl +0 -2
- package/templates/plugin/README.md.tpl +0 -1
- package/templates/plugin/client.d.ts +0 -2
- package/templates/plugin/client.js +0 -1
- package/templates/plugin/package.json.tpl +0 -11
- package/templates/plugin/server.d.ts +0 -2
- package/templates/plugin/server.js +0 -1
- package/templates/plugin/src/client/client.d.ts +0 -249
- package/templates/plugin/src/client/index.tsx.tpl +0 -1
- package/templates/plugin/src/client/locale.ts +0 -21
- package/templates/plugin/src/client/models/index.ts +0 -12
- package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
- package/templates/plugin/src/index.ts +0 -2
- package/templates/plugin/src/locale/en-US.json +0 -1
- package/templates/plugin/src/locale/zh-CN.json +0 -1
- package/templates/plugin/src/server/collections/.gitkeep +0 -0
- package/templates/plugin/src/server/index.ts.tpl +0 -1
- 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
|
-
};
|