@nocobase/cli 1.6.0-alpha.2 → 1.6.0-alpha.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.
- package/nocobase.conf.tpl +2 -0
- package/package.json +4 -4
- package/src/commands/create-nginx-conf.js +11 -4
- package/src/commands/dev.js +3 -6
- package/src/commands/pkg.js +28 -4
- package/src/commands/start.js +16 -8
- package/src/util.js +41 -4
package/nocobase.conf.tpl
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "1.6.0-alpha.
|
|
3
|
+
"version": "1.6.0-alpha.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"nocobase": "./bin/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nocobase/app": "1.6.0-alpha.
|
|
11
|
+
"@nocobase/app": "1.6.0-alpha.20",
|
|
12
12
|
"@types/fs-extra": "^11.0.1",
|
|
13
13
|
"@umijs/utils": "3.5.20",
|
|
14
14
|
"chalk": "^4.1.1",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"tsx": "^4.19.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@nocobase/devtools": "1.6.0-alpha.
|
|
28
|
+
"@nocobase/devtools": "1.6.0-alpha.20"
|
|
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": "c127664eb2b900edd5c18c9344046cd663a06c3b"
|
|
36
36
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const { resolve } = require('path');
|
|
10
|
+
const { resolve, posix } = require('path');
|
|
11
11
|
const { Command } = require('commander');
|
|
12
12
|
const { readFileSync, writeFileSync } = require('fs');
|
|
13
13
|
|
|
@@ -19,11 +19,18 @@ module.exports = (cli) => {
|
|
|
19
19
|
cli.command('create-nginx-conf').action(async (name, options) => {
|
|
20
20
|
const file = resolve(__dirname, '../../nocobase.conf.tpl');
|
|
21
21
|
const data = readFileSync(file, 'utf-8');
|
|
22
|
+
let otherLocation = '';
|
|
23
|
+
if (process.env.APP_PUBLIC_PATH !== '/') {
|
|
24
|
+
otherLocation = `location / {
|
|
25
|
+
alias ${posix.resolve(process.cwd())}/node_modules/@nocobase/app/dist/client/;
|
|
26
|
+
try_files $uri $uri/ /index.html;
|
|
27
|
+
}`;
|
|
28
|
+
}
|
|
22
29
|
const replaced = data
|
|
23
|
-
.replace(/\{\{cwd\}\}/g,
|
|
30
|
+
.replace(/\{\{cwd\}\}/g, posix.resolve(process.cwd()))
|
|
24
31
|
.replace(/\{\{publicPath\}\}/g, process.env.APP_PUBLIC_PATH)
|
|
25
|
-
.replace(/\{\{apiPort\}\}/g, process.env.APP_PORT)
|
|
26
|
-
|
|
32
|
+
.replace(/\{\{apiPort\}\}/g, process.env.APP_PORT)
|
|
33
|
+
.replace(/\{\{otherLocation\}\}/g, otherLocation);
|
|
27
34
|
const targetFile = resolve(process.cwd(), 'storage', 'nocobase.conf');
|
|
28
35
|
writeFileSync(targetFile, replaced);
|
|
29
36
|
});
|
package/src/commands/dev.js
CHANGED
|
@@ -30,10 +30,10 @@ module.exports = (cli) => {
|
|
|
30
30
|
cli
|
|
31
31
|
.command('dev')
|
|
32
32
|
.option('-p, --port [port]')
|
|
33
|
-
.option('--client')
|
|
34
|
-
.option('--server')
|
|
33
|
+
.option('-c, --client')
|
|
34
|
+
.option('-s, --server')
|
|
35
35
|
.option('--db-sync')
|
|
36
|
-
.option('--inspect [port]')
|
|
36
|
+
.option('-i, --inspect [port]')
|
|
37
37
|
.allowUnknownOption()
|
|
38
38
|
.action(async (opts) => {
|
|
39
39
|
let subprocess;
|
|
@@ -89,16 +89,13 @@ module.exports = (cli) => {
|
|
|
89
89
|
|
|
90
90
|
watcher
|
|
91
91
|
.on('ready', () => {
|
|
92
|
-
console.log('Initial scan complete.');
|
|
93
92
|
isReady = true;
|
|
94
93
|
})
|
|
95
94
|
.on('addDir', async (pathname) => {
|
|
96
|
-
console.log('addDir....', isReady);
|
|
97
95
|
if (!isReady) return;
|
|
98
96
|
restartClient();
|
|
99
97
|
})
|
|
100
98
|
.on('unlinkDir', async (pathname) => {
|
|
101
|
-
console.log('unlinkDir....', isReady);
|
|
102
99
|
if (!isReady) return;
|
|
103
100
|
restartClient();
|
|
104
101
|
});
|
package/src/commands/pkg.js
CHANGED
|
@@ -140,7 +140,7 @@ class Package {
|
|
|
140
140
|
.on('finish', resolve)
|
|
141
141
|
.on('error', reject);
|
|
142
142
|
});
|
|
143
|
-
console.log(chalk.greenBright(`
|
|
143
|
+
console.log(chalk.greenBright(`Downloaded: ${this.packageName}@${version}`));
|
|
144
144
|
} catch (error) {
|
|
145
145
|
console.log(chalk.redBright(`Download failed: ${this.packageName}`));
|
|
146
146
|
}
|
|
@@ -189,21 +189,45 @@ class PackageManager {
|
|
|
189
189
|
},
|
|
190
190
|
responseType: 'json',
|
|
191
191
|
});
|
|
192
|
-
return
|
|
192
|
+
return {
|
|
193
|
+
licensed_plugins: res.data?.data || [],
|
|
194
|
+
commercial_plugins: res.data?.meta?.commercial_plugins || [],
|
|
195
|
+
};
|
|
193
196
|
}
|
|
194
197
|
|
|
195
198
|
async getPackages() {
|
|
196
199
|
const pkgs = await this.getProPackages();
|
|
200
|
+
|
|
201
|
+
if (Array.isArray(pkgs)) {
|
|
202
|
+
return {
|
|
203
|
+
commercial_plugins: pkgs,
|
|
204
|
+
licensed_plugins: pkgs,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
197
207
|
return pkgs;
|
|
198
208
|
}
|
|
199
209
|
|
|
210
|
+
async removePackage(packageName) {
|
|
211
|
+
const dir = path.resolve(process.env.PLUGIN_STORAGE_PATH, packageName);
|
|
212
|
+
const r = await fs.exists(dir);
|
|
213
|
+
if (r) {
|
|
214
|
+
console.log(chalk.yellowBright(`Removed: ${packageName}`));
|
|
215
|
+
await fs.rm(dir, { force: true, recursive: true });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
200
219
|
async download(options = {}) {
|
|
201
220
|
const { version } = options;
|
|
202
221
|
if (!this.token) {
|
|
203
222
|
return;
|
|
204
223
|
}
|
|
205
|
-
const
|
|
206
|
-
for (const pkg of
|
|
224
|
+
const { commercial_plugins, licensed_plugins } = await this.getPackages();
|
|
225
|
+
for (const pkg of commercial_plugins) {
|
|
226
|
+
if (!licensed_plugins.includes(pkg)) {
|
|
227
|
+
await this.removePackage(pkg);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
for (const pkg of licensed_plugins) {
|
|
207
231
|
await this.getPackage(pkg).download({ version });
|
|
208
232
|
}
|
|
209
233
|
}
|
package/src/commands/start.js
CHANGED
|
@@ -8,19 +8,30 @@
|
|
|
8
8
|
*/
|
|
9
9
|
const _ = require('lodash');
|
|
10
10
|
const { Command } = require('commander');
|
|
11
|
-
const {
|
|
11
|
+
const { run, postCheck, downloadPro, promptForTs } = require('../util');
|
|
12
12
|
const { existsSync, rmSync } = require('fs');
|
|
13
|
-
const { resolve } = require('path');
|
|
13
|
+
const { resolve, isAbsolute } = require('path');
|
|
14
14
|
const chalk = require('chalk');
|
|
15
15
|
const chokidar = require('chokidar');
|
|
16
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
|
+
|
|
17
27
|
function deleteSockFiles() {
|
|
18
|
-
const {
|
|
28
|
+
const { PM2_HOME } = process.env;
|
|
19
29
|
if (existsSync(PM2_HOME)) {
|
|
20
30
|
rmSync(PM2_HOME, { recursive: true });
|
|
21
31
|
}
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
const socketPath = getSocketPath();
|
|
33
|
+
if (existsSync(socketPath)) {
|
|
34
|
+
rmSync(socketPath);
|
|
24
35
|
}
|
|
25
36
|
}
|
|
26
37
|
|
|
@@ -58,16 +69,13 @@ module.exports = (cli) => {
|
|
|
58
69
|
|
|
59
70
|
watcher
|
|
60
71
|
.on('ready', () => {
|
|
61
|
-
console.log('Initial scan complete.');
|
|
62
72
|
isReady = true;
|
|
63
73
|
})
|
|
64
74
|
.on('addDir', async (pathname) => {
|
|
65
|
-
console.log('addDir....', isReady);
|
|
66
75
|
if (!isReady) return;
|
|
67
76
|
restart();
|
|
68
77
|
})
|
|
69
78
|
.on('unlinkDir', async (pathname) => {
|
|
70
|
-
console.log('unlinkDir....', isReady);
|
|
71
79
|
if (!isReady) return;
|
|
72
80
|
restart();
|
|
73
81
|
});
|
package/src/util.js
CHANGED
|
@@ -11,11 +11,12 @@ const net = require('net');
|
|
|
11
11
|
const chalk = require('chalk');
|
|
12
12
|
const execa = require('execa');
|
|
13
13
|
const fg = require('fast-glob');
|
|
14
|
-
const { dirname, join, resolve, sep } = require('path');
|
|
14
|
+
const { dirname, join, resolve, sep, isAbsolute } = require('path');
|
|
15
15
|
const { readFile, writeFile } = require('fs').promises;
|
|
16
16
|
const { existsSync, mkdirSync, cpSync, writeFileSync } = require('fs');
|
|
17
17
|
const dotenv = require('dotenv');
|
|
18
|
-
const fs = require('fs');
|
|
18
|
+
const fs = require('fs-extra');
|
|
19
|
+
const os = require('os');
|
|
19
20
|
const moment = require('moment-timezone');
|
|
20
21
|
|
|
21
22
|
exports.isPackageValid = (pkg) => {
|
|
@@ -164,6 +165,10 @@ exports.promptForTs = () => {
|
|
|
164
165
|
};
|
|
165
166
|
|
|
166
167
|
exports.downloadPro = async () => {
|
|
168
|
+
const { NOCOBASE_PKG_USERNAME, NOCOBASE_PKG_PASSWORD } = process.env;
|
|
169
|
+
if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
167
172
|
await exports.run('yarn', ['nocobase', 'pkg', 'download-pro']);
|
|
168
173
|
};
|
|
169
174
|
|
|
@@ -321,6 +326,32 @@ function areTimeZonesEqual(timeZone1, timeZone2) {
|
|
|
321
326
|
return moment.tz(timeZone1).format('Z') === moment.tz(timeZone2).format('Z');
|
|
322
327
|
}
|
|
323
328
|
|
|
329
|
+
function generateGatewayPath() {
|
|
330
|
+
if (process.env.SOCKET_PATH) {
|
|
331
|
+
if (isAbsolute(process.env.SOCKET_PATH)) {
|
|
332
|
+
return process.env.SOCKET_PATH;
|
|
333
|
+
}
|
|
334
|
+
return resolve(process.cwd(), process.env.SOCKET_PATH);
|
|
335
|
+
}
|
|
336
|
+
if (process.env.NOCOBASE_RUNNING_IN_DOCKER === 'true') {
|
|
337
|
+
return resolve(os.homedir(), '.nocobase', 'gateway.sock');
|
|
338
|
+
}
|
|
339
|
+
return resolve(process.cwd(), 'storage/gateway.sock');
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function generatePm2Home() {
|
|
343
|
+
if (process.env.PM2_HOME) {
|
|
344
|
+
if (isAbsolute(process.env.PM2_HOME)) {
|
|
345
|
+
return process.env.PM2_HOME;
|
|
346
|
+
}
|
|
347
|
+
return resolve(process.cwd(), process.env.PM2_HOME);
|
|
348
|
+
}
|
|
349
|
+
if (process.env.NOCOBASE_RUNNING_IN_DOCKER === 'true') {
|
|
350
|
+
return resolve(os.homedir(), '.nocobase', 'pm2');
|
|
351
|
+
}
|
|
352
|
+
return resolve(process.cwd(), './storage/.pm2');
|
|
353
|
+
}
|
|
354
|
+
|
|
324
355
|
exports.initEnv = function initEnv() {
|
|
325
356
|
const env = {
|
|
326
357
|
APP_ENV: 'development',
|
|
@@ -337,10 +368,11 @@ exports.initEnv = function initEnv() {
|
|
|
337
368
|
LOCAL_STORAGE_DEST: 'storage/uploads',
|
|
338
369
|
PLUGIN_STORAGE_PATH: resolve(process.cwd(), 'storage/plugins'),
|
|
339
370
|
MFSU_AD: 'none',
|
|
371
|
+
MAKO_AD: 'none',
|
|
340
372
|
WS_PATH: '/ws',
|
|
341
|
-
|
|
373
|
+
// PM2_HOME: generatePm2Home(),
|
|
374
|
+
// SOCKET_PATH: generateGatewayPath(),
|
|
342
375
|
NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),
|
|
343
|
-
PM2_HOME: resolve(process.cwd(), './storage/.pm2'),
|
|
344
376
|
PLUGIN_PACKAGE_PREFIX: '@nocobase/plugin-,@nocobase/plugin-sample-,@nocobase/preset-',
|
|
345
377
|
SERVER_TSCONFIG_PATH: './tsconfig.server.json',
|
|
346
378
|
PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), 'storage/playwright/.auth/admin.json'),
|
|
@@ -423,6 +455,11 @@ exports.initEnv = function initEnv() {
|
|
|
423
455
|
`process.env.DB_TIMEZONE="${process.env.DB_TIMEZONE}" and process.env.TZ="${process.env.TZ}" are different`,
|
|
424
456
|
);
|
|
425
457
|
}
|
|
458
|
+
|
|
459
|
+
process.env.PM2_HOME = generatePm2Home();
|
|
460
|
+
process.env.SOCKET_PATH = generateGatewayPath();
|
|
461
|
+
fs.mkdirpSync(dirname(process.env.SOCKET_PATH), { force: true, recursive: true });
|
|
462
|
+
fs.mkdirpSync(process.env.PM2_HOME, { force: true, recursive: true });
|
|
426
463
|
};
|
|
427
464
|
|
|
428
465
|
exports.generatePlugins = function () {
|