@nocobase/cli 2.1.0-beta.2 → 2.1.0-beta.20

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 (143) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +367 -19
  3. package/README.zh-CN.md +336 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +116 -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/build.js +57 -0
  14. package/dist/commands/db/logs.js +85 -0
  15. package/dist/commands/db/ps.js +60 -0
  16. package/dist/commands/db/shared.js +81 -0
  17. package/dist/commands/db/start.js +70 -0
  18. package/dist/commands/db/stop.js +70 -0
  19. package/dist/commands/dev.js +149 -0
  20. package/dist/commands/down.js +193 -0
  21. package/dist/commands/download.js +865 -0
  22. package/dist/commands/env/add.js +327 -0
  23. package/dist/commands/env/auth.js +62 -0
  24. package/dist/commands/env/list.js +41 -0
  25. package/dist/commands/env/remove.js +65 -0
  26. package/dist/commands/env/update.js +73 -0
  27. package/dist/commands/env/use.js +36 -0
  28. package/dist/commands/init.js +822 -0
  29. package/dist/commands/install.js +1888 -0
  30. package/dist/commands/logs.js +90 -0
  31. package/dist/commands/pm/disable.js +63 -0
  32. package/dist/commands/pm/enable.js +63 -0
  33. package/dist/commands/pm/list.js +54 -0
  34. package/dist/commands/prompts-stages.js +150 -0
  35. package/dist/commands/prompts-test.js +181 -0
  36. package/dist/commands/ps.js +116 -0
  37. package/dist/commands/restart.js +74 -0
  38. package/dist/commands/scaffold/migration.js +38 -0
  39. package/dist/commands/scaffold/plugin.js +37 -0
  40. package/dist/commands/self/check.js +71 -0
  41. package/dist/commands/self/index.js +20 -0
  42. package/dist/commands/self/update.js +76 -0
  43. package/dist/commands/skills/check.js +63 -0
  44. package/dist/commands/skills/index.js +20 -0
  45. package/dist/commands/skills/install.js +58 -0
  46. package/dist/commands/skills/update.js +58 -0
  47. package/dist/commands/start.js +211 -0
  48. package/dist/commands/stop.js +90 -0
  49. package/dist/commands/test.js +466 -0
  50. package/dist/commands/upgrade.js +583 -0
  51. package/dist/generated/command-registry.js +133 -0
  52. package/dist/help/runtime-help.js +20 -0
  53. package/dist/lib/api-client.js +243 -0
  54. package/dist/lib/app-runtime.js +142 -0
  55. package/dist/lib/auth-store.js +241 -0
  56. package/dist/lib/bootstrap.js +387 -0
  57. package/dist/lib/build-config.js +10 -0
  58. package/dist/lib/cli-home.js +30 -0
  59. package/dist/lib/cli-locale.js +115 -0
  60. package/dist/lib/command-discovery.js +39 -0
  61. package/dist/lib/env-auth.js +872 -0
  62. package/dist/lib/generated-command.js +142 -0
  63. package/dist/lib/naming.js +70 -0
  64. package/dist/lib/openapi.js +62 -0
  65. package/dist/lib/post-processors.js +23 -0
  66. package/dist/lib/prompt-catalog.js +581 -0
  67. package/dist/lib/prompt-validators.js +185 -0
  68. package/dist/lib/prompt-web-ui.js +2096 -0
  69. package/dist/lib/resource-command.js +335 -0
  70. package/dist/lib/resource-request.js +104 -0
  71. package/dist/lib/run-npm.js +197 -0
  72. package/dist/lib/runtime-generator.js +419 -0
  73. package/dist/lib/runtime-store.js +56 -0
  74. package/dist/lib/self-manager.js +246 -0
  75. package/dist/lib/skills-manager.js +202 -0
  76. package/dist/lib/ui.js +175 -0
  77. package/dist/locale/en-US.json +333 -0
  78. package/dist/locale/zh-CN.json +333 -0
  79. package/dist/post-processors/data-modeling.js +66 -0
  80. package/dist/post-processors/data-source-manager.js +114 -0
  81. package/dist/post-processors/index.js +19 -0
  82. package/nocobase-ctl.config.json +287 -0
  83. package/package.json +60 -26
  84. package/LICENSE +0 -661
  85. package/bin/index.js +0 -39
  86. package/nocobase.conf.tpl +0 -95
  87. package/src/cli.js +0 -19
  88. package/src/commands/benchmark.js +0 -73
  89. package/src/commands/build.js +0 -49
  90. package/src/commands/clean.js +0 -30
  91. package/src/commands/client.js +0 -166
  92. package/src/commands/create-nginx-conf.js +0 -37
  93. package/src/commands/create-plugin.js +0 -33
  94. package/src/commands/dev.js +0 -200
  95. package/src/commands/doc.js +0 -76
  96. package/src/commands/e2e.js +0 -265
  97. package/src/commands/global.js +0 -43
  98. package/src/commands/index.js +0 -45
  99. package/src/commands/instance-id.js +0 -47
  100. package/src/commands/locale/cronstrue.js +0 -122
  101. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  102. package/src/commands/locale/react-js-cron/index.js +0 -17
  103. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  104. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  105. package/src/commands/locale.js +0 -81
  106. package/src/commands/p-test.js +0 -88
  107. package/src/commands/perf.js +0 -63
  108. package/src/commands/pkg.js +0 -321
  109. package/src/commands/pm2.js +0 -37
  110. package/src/commands/postinstall.js +0 -88
  111. package/src/commands/start.js +0 -148
  112. package/src/commands/tar.js +0 -36
  113. package/src/commands/test-coverage.js +0 -55
  114. package/src/commands/test.js +0 -107
  115. package/src/commands/umi.js +0 -33
  116. package/src/commands/update-deps.js +0 -72
  117. package/src/commands/upgrade.js +0 -47
  118. package/src/commands/view-license-key.js +0 -44
  119. package/src/index.js +0 -14
  120. package/src/license.js +0 -76
  121. package/src/logger.js +0 -75
  122. package/src/plugin-generator.js +0 -80
  123. package/src/util.js +0 -517
  124. package/templates/bundle-status.html +0 -338
  125. package/templates/create-app-package.json +0 -39
  126. package/templates/plugin/.npmignore.tpl +0 -2
  127. package/templates/plugin/README.md.tpl +0 -1
  128. package/templates/plugin/client.d.ts +0 -2
  129. package/templates/plugin/client.js +0 -1
  130. package/templates/plugin/package.json.tpl +0 -11
  131. package/templates/plugin/server.d.ts +0 -2
  132. package/templates/plugin/server.js +0 -1
  133. package/templates/plugin/src/client/client.d.ts +0 -249
  134. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  135. package/templates/plugin/src/client/locale.ts +0 -21
  136. package/templates/plugin/src/client/models/index.ts +0 -12
  137. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  138. package/templates/plugin/src/index.ts +0 -2
  139. package/templates/plugin/src/locale/en-US.json +0 -1
  140. package/templates/plugin/src/locale/zh-CN.json +0 -1
  141. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  142. package/templates/plugin/src/server/index.ts.tpl +0 -1
  143. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
@@ -1,321 +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 { Command } = require('commander');
11
- const axios = require('axios');
12
- const fs = require('fs-extra');
13
- const zlib = require('zlib');
14
- const tar = require('tar');
15
- const path = require('path');
16
- const { createStoragePluginsSymlink } = require('@nocobase/utils/plugin-symlink');
17
- const { getAccessKeyPair, showLicenseInfo, LicenseKeyError } = require('../license');
18
- const { logger } = require('../logger');
19
-
20
- class Package {
21
- data;
22
- constructor(packageName, packageManager) {
23
- this.packageName = packageName;
24
- this.packageManager = packageManager;
25
- this.outputDir = path.resolve(process.cwd(), `storage/plugins/${this.packageName}`);
26
- }
27
-
28
- get token() {
29
- return this.packageManager.getToken();
30
- }
31
-
32
- url(path) {
33
- return this.packageManager.url(path);
34
- }
35
-
36
- async mkdir() {
37
- if (await fs.exists(this.outputDir)) {
38
- await fs.rm(this.outputDir, { recursive: true, force: true });
39
- }
40
- await fs.mkdirp(this.outputDir);
41
- }
42
-
43
- async getInfo() {
44
- try {
45
- const res = await axios.get(this.url(this.packageName), {
46
- headers: {
47
- Authorization: `Bearer ${this.token}`,
48
- },
49
- responseType: 'json',
50
- });
51
- this.data = res.data;
52
- } catch (error) {
53
- return;
54
- }
55
- }
56
-
57
- getTarball(version = 'latest') {
58
- if (this.data.versions[version]) {
59
- return [version, this.data.versions[version].dist.tarball];
60
- }
61
-
62
- const keys = version.split('.');
63
- const length = keys.length;
64
-
65
- if (version.includes('rc')) {
66
- version = version.split('-').shift();
67
- }
68
-
69
- if (length === 5) {
70
- keys.pop();
71
- version = keys.join('.');
72
- }
73
-
74
- if (version === 'latest') {
75
- version = this.data['dist-tags']['latest'];
76
- } else if (version === 'next') {
77
- version = this.data['dist-tags']['next'];
78
- }
79
-
80
- if (!this.data.versions[version]) {
81
- logger.error(`Download failed: ${this.packageName}@${version} package does not exist`);
82
- }
83
-
84
- return [version, this.data.versions[version].dist.tarball];
85
- }
86
-
87
- async isDevPackage() {
88
- let file = path.resolve(process.cwd(), 'packages/plugins', this.packageName, 'package.json');
89
- if (await fs.exists(file)) {
90
- return true;
91
- }
92
- file = path.resolve(process.cwd(), 'packages/pro-plugins', this.packageName, 'package.json');
93
- if (await fs.exists(file)) {
94
- return true;
95
- }
96
- return false;
97
- }
98
-
99
- async isDepPackage() {
100
- const pkg1 = path.resolve(process.cwd(), 'node_modules', this.packageName, 'package.json');
101
- const pkg2 = path.resolve(process.cwd(), process.env.PLUGIN_STORAGE_PATH, this.packageName, 'package.json');
102
- if ((await fs.exists(pkg1)) && (await fs.exists(pkg2))) {
103
- const readPath1 = fs.realpathSync(pkg1);
104
- const readPath2 = fs.realpathSync(pkg2);
105
- if (readPath1 !== readPath2) {
106
- return true;
107
- }
108
- }
109
- return false;
110
- }
111
-
112
- async isDownloaded(version) {
113
- const packageFile = path.resolve(process.env.PLUGIN_STORAGE_PATH, this.packageName, 'package.json');
114
- if (await fs.exists(packageFile)) {
115
- const json = await fs.readJson(packageFile);
116
- if (json.version === version) {
117
- return true;
118
- }
119
- }
120
- return false;
121
- }
122
-
123
- async download(options = {}) {
124
- if (await this.isDevPackage()) {
125
- logger.info(`Skipped: ${this.packageName} is dev package`);
126
- return;
127
- }
128
- if (await this.isDepPackage()) {
129
- logger.info(`Skipped: ${this.packageName} is dependency package`);
130
- return;
131
- }
132
- if (await this.isDownloaded(options.version)) {
133
- return;
134
- }
135
- await this.getInfo();
136
- if (!this.data) {
137
- logger.error(`Download failed: ${this.packageName} package does not exist`);
138
- return;
139
- }
140
- try {
141
- const [version, url] = this.getTarball(options.version);
142
- if (await this.isDownloaded(version)) {
143
- return;
144
- }
145
- const response = await axios({
146
- url,
147
- responseType: 'stream',
148
- method: 'GET',
149
- headers: {
150
- Authorization: `Bearer ${this.token}`,
151
- },
152
- });
153
- await this.mkdir();
154
- await new Promise((resolve, reject) => {
155
- response.data
156
- .pipe(zlib.createGunzip()) // 解压 gzip
157
- .pipe(tar.extract({ cwd: this.outputDir, strip: 1 })) // 解压 tar
158
- .on('finish', resolve)
159
- .on('error', reject);
160
- });
161
- logger.info(`Downloaded: ${this.packageName}@${version}`);
162
- } catch (error) {
163
- if (error?.response?.data && typeof error?.response?.data?.pipe === 'function') {
164
- let errorMessageBuffer = '';
165
- error.response.data.on?.('data', (chunk) => {
166
- errorMessageBuffer += chunk.toString('utf8'); // 收集错误信息
167
- });
168
- error.response.data.on?.('end', () => {
169
- if (error.response.status === 403) {
170
- logger.error('You do not have permission to download this package version.');
171
- }
172
- });
173
- }
174
- logger.error(`Download failed: ${this.packageName}`);
175
- }
176
- }
177
- }
178
-
179
- class PackageManager {
180
- token;
181
- baseURL;
182
-
183
- constructor({ baseURL }) {
184
- this.baseURL = baseURL;
185
- }
186
-
187
- getToken() {
188
- return this.token;
189
- }
190
-
191
- getBaseURL() {
192
- return this.baseURL;
193
- }
194
-
195
- url(path) {
196
- return this.baseURL + path;
197
- }
198
-
199
- async login(credentials) {
200
- try {
201
- const res1 = await axios.post(`${this.baseURL}-/verdaccio/sec/login`, credentials, {
202
- responseType: 'json',
203
- });
204
- this.token = res1.data.token;
205
- logger.info('Login success');
206
- } catch (error) {
207
- if (error?.response?.data?.error === 'license not valid') {
208
- showLicenseInfo(LicenseKeyError.notValid);
209
- }
210
- logger.error(`Login failed: ${this.baseURL}`);
211
- logger.error(error?.message, { error });
212
- }
213
- }
214
-
215
- getPackage(packageName) {
216
- return new Package(packageName, this);
217
- }
218
-
219
- async getProPackages() {
220
- const res = await axios.get(this.url('pro-packages'), {
221
- headers: {
222
- Authorization: `Bearer ${this.token}`,
223
- },
224
- responseType: 'json',
225
- });
226
- return {
227
- licensed_plugins: res.data?.data || [],
228
- commercial_plugins: res.data?.meta?.commercial_plugins || [],
229
- };
230
- }
231
-
232
- async getPackages() {
233
- const pkgs = await this.getProPackages();
234
-
235
- if (Array.isArray(pkgs)) {
236
- return {
237
- commercial_plugins: pkgs,
238
- licensed_plugins: pkgs,
239
- };
240
- }
241
- return pkgs;
242
- }
243
-
244
- async removePackage(packageName) {
245
- const dir = path.resolve(process.env.PLUGIN_STORAGE_PATH, packageName);
246
- const r = await fs.exists(dir);
247
- if (r) {
248
- logger.info(`Removed: ${packageName}`);
249
- await fs.rm(dir, { force: true, recursive: true });
250
- }
251
- }
252
-
253
- async download(options = {}) {
254
- const { version } = options;
255
- if (!this.token) {
256
- return;
257
- }
258
- const { commercial_plugins, licensed_plugins } = await this.getPackages();
259
- for (const pkg of commercial_plugins) {
260
- if (!licensed_plugins.includes(pkg)) {
261
- await this.removePackage(pkg);
262
- }
263
- }
264
- logger.info(`Download plugins...`);
265
- for (const pkg of licensed_plugins) {
266
- await this.getPackage(pkg).download({ version });
267
- }
268
- logger.info('Download plugins done');
269
- }
270
- }
271
-
272
- /**
273
- *
274
- * @param {Command} cli
275
- */
276
- module.exports = (cli) => {
277
- const pkg = cli.command('pkg');
278
- pkg
279
- .command('download-pro')
280
- .option('-V, --version [version]')
281
- .action(async () => {
282
- const {
283
- NOCOBASE_PKG_URL = 'https://pkg.nocobase.com/',
284
- NOCOBASE_PKG_USERNAME,
285
- NOCOBASE_PKG_PASSWORD,
286
- DISABLE_PKG_DOWNLOAD,
287
- } = process.env;
288
- if (DISABLE_PKG_DOWNLOAD === 'true') {
289
- logger.info('Package download is disabled.');
290
- return;
291
- }
292
- let accessKeyId;
293
- let accessKeySecret;
294
- try {
295
- ({ accessKeyId, accessKeySecret } = await getAccessKeyPair());
296
- } catch (e) {
297
- // logger.error('Get AccessKey Pair error', e);
298
- return;
299
- }
300
- if (NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD && !accessKeyId && !accessKeySecret) {
301
- logger.warn(
302
- 'NOCOBASE_PKG_USERNAME and NOCOBASE_PKG_PASSWORD will be deprecated in future versions. Please log in to NocoBase Service and refer to the documentation to learn how to install and upgrade commercial plugins.\n',
303
- );
304
- }
305
- if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD) && !(accessKeyId && accessKeySecret)) {
306
- return;
307
- }
308
- const credentials = accessKeyId
309
- ? { username: accessKeyId, password: accessKeySecret }
310
- : { username: NOCOBASE_PKG_USERNAME, password: NOCOBASE_PKG_PASSWORD };
311
- const pm = new PackageManager({ baseURL: NOCOBASE_PKG_URL });
312
- await pm.login(credentials);
313
- const file = path.resolve(__dirname, '../../package.json');
314
- const json = await fs.readJson(file);
315
- await pm.download({ version: json.version });
316
- await createStoragePluginsSymlink();
317
- });
318
- pkg.command('export-all').action(async () => {
319
- logger.info('Todo...');
320
- });
321
- };
@@ -1,37 +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 chalk = require('chalk');
11
- const { Command } = require('commander');
12
- const { run, isDev } = require('../util');
13
-
14
- /**
15
- *
16
- * @param {Command} cli
17
- */
18
- module.exports = (cli) => {
19
- cli
20
- .command('pm2')
21
- .allowUnknownOption()
22
- .action(() => {
23
- run('pm2', process.argv.slice(3));
24
- });
25
- cli
26
- .command('pm2-restart')
27
- .allowUnknownOption()
28
- .action(() => {
29
- run('pm2', ['restart', 'all']);
30
- });
31
- cli
32
- .command('pm2-stop')
33
- .allowUnknownOption()
34
- .action(() => {
35
- run('pm2', ['kill']);
36
- });
37
- };
@@ -1,88 +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 { Command } = require('commander');
11
- const { run, isDev, isPackageValid, generatePlaywrightPath, generatePlugins } = require('../util');
12
- const { dirname, resolve } = require('path');
13
- const { existsSync, mkdirSync, readFileSync, appendFileSync } = require('fs');
14
- const { readFile, writeFile } = require('fs').promises;
15
- const { createStoragePluginsSymlink, createDevPluginsSymlink } = require('@nocobase/utils/plugin-symlink');
16
-
17
- function runPatchPackage() {
18
- // run yarn patch-package
19
- // console.log('patching third party packages...');
20
- run('yarn', ['patch-package'], {
21
- stdio: 'pipe',
22
- });
23
- }
24
-
25
- function writeToExclude() {
26
- const excludePath = resolve(process.cwd(), '.git', 'info', 'exclude');
27
- const content = 'packages/pro-plugins/\n';
28
- const dirPath = dirname(excludePath);
29
-
30
- if (!existsSync(dirPath)) {
31
- try {
32
- mkdirSync(dirPath, { recursive: true });
33
- } catch (e) {
34
- console.log(`${e.message}, ignore write to git exclude`);
35
- return;
36
- }
37
- }
38
-
39
- let fileContent = '';
40
- if (existsSync(excludePath)) {
41
- fileContent = readFileSync(excludePath, 'utf-8');
42
- }
43
- if (!fileContent.includes(content)) {
44
- appendFileSync(excludePath, content);
45
- }
46
- }
47
-
48
- /**
49
- * @param {Command} cli
50
- */
51
- module.exports = (cli) => {
52
- const { APP_PACKAGE_ROOT } = process.env;
53
- cli
54
- .command('postinstall')
55
- .allowUnknownOption()
56
- .option('--skip-umi')
57
- .action(async (options) => {
58
- runPatchPackage();
59
- writeToExclude();
60
- generatePlugins();
61
- generatePlaywrightPath(true);
62
- await createStoragePluginsSymlink();
63
- if (!isDev()) {
64
- return;
65
- }
66
- await createDevPluginsSymlink();
67
- const cwd = process.cwd();
68
- if (!existsSync(resolve(cwd, '.env')) && existsSync(resolve(cwd, '.env.example'))) {
69
- const content = await readFile(resolve(cwd, '.env.example'), 'utf-8');
70
- await writeFile(resolve(cwd, '.env'), content, 'utf-8');
71
- }
72
- if (!existsSync(resolve(cwd, '.env.test')) && existsSync(resolve(cwd, '.env.test.example'))) {
73
- const content = await readFile(resolve(cwd, '.env.test.example'), 'utf-8');
74
- await writeFile(resolve(cwd, '.env.test'), content, 'utf-8');
75
- }
76
- if (!isPackageValid('umi')) {
77
- return;
78
- }
79
- if (!options.skipUmi) {
80
- run('umi', ['generate', 'tmp'], {
81
- stdio: 'pipe',
82
- env: {
83
- APP_ROOT: `${APP_PACKAGE_ROOT}/client`,
84
- },
85
- });
86
- }
87
- });
88
- };
@@ -1,148 +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
- const _ = require('lodash');
10
- const { Command } = require('commander');
11
- const { run, postCheck, downloadPro, promptForTs, checkDBDialect } = require('../util');
12
- const { existsSync, rmSync } = require('fs');
13
- const { resolve, isAbsolute } = require('path');
14
- const chalk = require('chalk');
15
- const chokidar = require('chokidar');
16
-
17
- function getSocketPath() {
18
- const { SOCKET_PATH } = process.env;
19
-
20
- if (isAbsolute(SOCKET_PATH)) {
21
- return SOCKET_PATH;
22
- }
23
-
24
- return resolve(process.cwd(), SOCKET_PATH);
25
- }
26
-
27
- function deleteSockFiles() {
28
- const { PM2_HOME } = process.env;
29
- if (existsSync(PM2_HOME)) {
30
- rmSync(PM2_HOME, { recursive: true });
31
- }
32
- const socketPath = getSocketPath();
33
- if (existsSync(socketPath)) {
34
- rmSync(socketPath);
35
- }
36
- }
37
-
38
- /**
39
- *
40
- * @param {Command} cli
41
- */
42
- module.exports = (cli) => {
43
- const { APP_PACKAGE_ROOT, NODE_ARGS } = process.env;
44
- cli
45
- .command('start')
46
- .option('-p, --port [port]')
47
- .option('-d, --daemon')
48
- .option('-i, --instances [instances]')
49
- .option('--db-sync')
50
- .option('--quickstart')
51
- .option('--launch-mode [launchMode]')
52
- .allowUnknownOption()
53
- .action(async (opts) => {
54
- checkDBDialect();
55
- if (opts.quickstart) {
56
- await downloadPro();
57
- }
58
-
59
- if (process.env.NO_WATCH_PLUGINS === true || process.env.NO_WATCH_PLUGINS === 'true') {
60
- const restart = _.debounce(async () => {
61
- console.log('restarting...');
62
- await run('yarn', ['nocobase', 'pm2-restart']);
63
- }, 500);
64
-
65
- const watcher = chokidar.watch('./storage/plugins/**/*', {
66
- cwd: process.cwd(),
67
- ignoreInitial: true,
68
- ignored: /(^|[\/\\])\../, // 忽略隐藏文件
69
- persistent: true,
70
- depth: 1, // 只监听第一层目录
71
- });
72
-
73
- watcher
74
- .on('ready', () => {
75
- isReady = true;
76
- })
77
- .on('addDir', async (pathname) => {
78
- if (!isReady) return;
79
- restart();
80
- })
81
- .on('unlinkDir', async (pathname) => {
82
- if (!isReady) return;
83
- restart();
84
- });
85
- }
86
-
87
- if (opts.port) {
88
- process.env.APP_PORT = opts.port;
89
- }
90
- if (process.argv.includes('-h') || process.argv.includes('--help')) {
91
- promptForTs();
92
- run('ts-node', [
93
- '-P',
94
- process.env.SERVER_TSCONFIG_PATH,
95
- '-r',
96
- 'tsconfig-paths/register',
97
- `${APP_PACKAGE_ROOT}/src/index.ts`,
98
- ...process.argv.slice(2),
99
- ]);
100
- return;
101
- }
102
- if (!existsSync(resolve(process.cwd(), `${APP_PACKAGE_ROOT}/lib/index.js`))) {
103
- console.log('The code is not compiled, please execute it first');
104
- console.log(chalk.yellow('$ yarn build'));
105
- console.log('If you want to run in development mode, please execute');
106
- console.log(chalk.yellow('$ yarn dev'));
107
- return;
108
- }
109
- await postCheck(opts);
110
- if (!opts.daemon) {
111
- deleteSockFiles();
112
- }
113
- const instances = opts.instances || process.env.CLUSTER_MODE;
114
- const instancesArgs = instances ? ['-i', instances] : [];
115
- if (opts.daemon) {
116
- await run('pm2', [
117
- 'start',
118
- ...instancesArgs,
119
- `${APP_PACKAGE_ROOT}/lib/index.js`,
120
- '--',
121
- ...process.argv.slice(2),
122
- ]);
123
- process.exit();
124
- } else {
125
- const launchMode = opts.launchMode || process.env.APP_LAUNCH_MODE || 'pm2';
126
- if (launchMode === 'pm2') {
127
- run(
128
- 'pm2-runtime',
129
- [
130
- 'start',
131
- ...instancesArgs,
132
- `${APP_PACKAGE_ROOT}/lib/index.js`,
133
- NODE_ARGS ? `--node-args="${NODE_ARGS}"` : undefined,
134
- '--',
135
- ...process.argv.slice(2),
136
- ].filter(Boolean),
137
- );
138
- } else {
139
- run(
140
- 'node',
141
- [`${APP_PACKAGE_ROOT}/lib/index.js`, ...(NODE_ARGS || '').split(' '), ...process.argv.slice(2)].filter(
142
- Boolean,
143
- ),
144
- );
145
- }
146
- }
147
- });
148
- };
@@ -1,36 +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 { resolve } = require('path');
11
- const { Command } = require('commander');
12
- const { run, nodeCheck, isPackageValid } = require('../util');
13
-
14
- /**
15
- *
16
- * @param {Command} cli
17
- */
18
- module.exports = (cli) => {
19
- cli
20
- .command('tar')
21
- .allowUnknownOption()
22
- .argument('[packages...]')
23
- .option('-v, --version', 'print version')
24
- .option('-c, --compile', 'compile the @nocobase/build package')
25
- .option('-w, --watch', 'watch compile the @nocobase/build package')
26
- .action(async (pkgs, options) => {
27
- nodeCheck();
28
- if (options.compile || options.watch || isPackageValid('@nocobase/build/src/index.ts')) {
29
- await run('yarn', ['build', options.watch ? '--watch' : ''], {
30
- cwd: resolve(process.cwd(), 'packages/core/build'),
31
- });
32
- if (options.watch) return;
33
- }
34
- await run('nocobase-build', [...pkgs, '--only-tar', options.version ? '--version' : '']);
35
- });
36
- };
@@ -1,55 +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 { run, checkDBDialect } = require('../util');
11
- const fg = require('fast-glob');
12
-
13
- const coreClientPackages = ['packages/core/client', 'packages/core/sdk'];
14
- const isCore = (dir) => dir.startsWith('packages/core');
15
-
16
- const getPackagesDir = (isClient) => {
17
- if (process.argv.length > 3 && !process.argv[3].startsWith('-')) {
18
- return [process.argv[3]];
19
- }
20
-
21
- const allPackageJson = fg.sync(['packages/*/*/package.json', 'packages/*/*/*/package.json'], {
22
- cwd: process.cwd(),
23
- onlyFiles: true,
24
- });
25
- const res = allPackageJson.map((pkg) => pkg.replace('/package.json', ''));
26
- return isClient
27
- ? res.filter((dir) => (isCore(dir) ? coreClientPackages.includes(dir) : true))
28
- : res.filter((dir) => (isCore(dir) ? !coreClientPackages.includes(dir) : true));
29
- };
30
-
31
- module.exports = (cli) => {
32
- cli.command('test-coverage:server').action(async () => {
33
- checkDBDialect();
34
- const packageRoots = getPackagesDir(false);
35
- for (const dir of packageRoots) {
36
- try {
37
- await run('yarn', ['test:server', dir, '--coverage']);
38
- } catch (e) {
39
- continue;
40
- }
41
- }
42
- });
43
-
44
- cli.command('test-coverage:client').action(async () => {
45
- checkDBDialect();
46
- const packageRoots = getPackagesDir(true);
47
- for (const dir of packageRoots) {
48
- try {
49
- await run('yarn', ['test:client', dir, '--coverage']);
50
- } catch (e) {
51
- continue;
52
- }
53
- }
54
- });
55
- };