@jayfong/x-server 2.78.2 → 2.79.0
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/lib/_cjs/cli/env_util.js
CHANGED
|
@@ -10,7 +10,7 @@ var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
|
10
10
|
var _vtils = require("vtils");
|
|
11
11
|
var _yaml = require("yaml");
|
|
12
12
|
class EnvUtil {
|
|
13
|
-
static async getAllChannel(cwd) {
|
|
13
|
+
static async getAllChannel(cwd, excludeChannels) {
|
|
14
14
|
const channelFiles = await (0, _globby.default)(['.env@*'], {
|
|
15
15
|
cwd: cwd,
|
|
16
16
|
onlyFiles: true,
|
|
@@ -19,11 +19,14 @@ class EnvUtil {
|
|
|
19
19
|
if (channelFiles.length === 0) {
|
|
20
20
|
return [];
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
let channels = (0, _vtils.uniq)(channelFiles.map(channel => channel.split('@').pop().split('.')[0]));
|
|
23
|
+
if (excludeChannels?.length) {
|
|
24
|
+
channels = (0, _vtils.difference)(channels, excludeChannels);
|
|
25
|
+
}
|
|
23
26
|
return channels;
|
|
24
27
|
}
|
|
25
|
-
static async chooseChannel(cwd) {
|
|
26
|
-
const channels = await EnvUtil.getAllChannel(cwd);
|
|
28
|
+
static async chooseChannel(cwd, excludeChannels) {
|
|
29
|
+
const channels = await EnvUtil.getAllChannel(cwd, excludeChannels);
|
|
27
30
|
if (channels.length === 0) return undefined;
|
|
28
31
|
if (channels.length === 1) return channels[0];
|
|
29
32
|
const res = await _inquirer.default.prompt([{
|
|
@@ -35,12 +38,14 @@ class EnvUtil {
|
|
|
35
38
|
return res.channel || undefined;
|
|
36
39
|
}
|
|
37
40
|
static async withChannel(options) {
|
|
38
|
-
if (options.channel
|
|
39
|
-
const
|
|
41
|
+
if (options.channel?.startsWith('_')) {
|
|
42
|
+
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
43
|
+
const channel = await EnvUtil.chooseChannel(options.cwd, excludeChannels);
|
|
40
44
|
console.log(`========= ${channel} =========`);
|
|
41
45
|
await options.cb(channel);
|
|
42
|
-
} else if (options.channel
|
|
43
|
-
const
|
|
46
|
+
} else if (options.channel?.startsWith('@')) {
|
|
47
|
+
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
48
|
+
const channels = await EnvUtil.getAllChannel(options.cwd, excludeChannels);
|
|
44
49
|
for (const channel of channels) {
|
|
45
50
|
console.log(`========= ${channel} =========`);
|
|
46
51
|
await options.cb(channel);
|
|
@@ -120,7 +120,7 @@ class CryptoService {
|
|
|
120
120
|
* @param key - 用于加密的密钥(仅支持16字节的密钥)。
|
|
121
121
|
*/
|
|
122
122
|
aesEncrypt(text, key) {
|
|
123
|
-
const cipher = _nodeCrypto.default.createCipheriv('aes-128-ecb', key, null);
|
|
123
|
+
const cipher = _nodeCrypto.default.createCipheriv('aes-128-ecb', key.substring(0, 16), null);
|
|
124
124
|
let encrypted = cipher.update(text, 'utf8', 'base64');
|
|
125
125
|
encrypted += cipher.final('base64');
|
|
126
126
|
return encrypted;
|
|
@@ -133,7 +133,7 @@ class CryptoService {
|
|
|
133
133
|
* @param key - 用于解密的密钥(仅支持16字节的密钥)。
|
|
134
134
|
*/
|
|
135
135
|
aesDecrypt(text, key) {
|
|
136
|
-
const decipher = _nodeCrypto.default.createDecipheriv('aes-128-ecb', key, null);
|
|
136
|
+
const decipher = _nodeCrypto.default.createDecipheriv('aes-128-ecb', key.substring(0, 16), null);
|
|
137
137
|
let decrypted = decipher.update(text, 'base64', 'utf8');
|
|
138
138
|
decrypted += decipher.final('utf8');
|
|
139
139
|
return decrypted;
|
package/lib/cli/env_util.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare class EnvUtil {
|
|
|
9
9
|
static RE_NEWLINES: RegExp;
|
|
10
10
|
static NEWLINES_MATCH: RegExp;
|
|
11
11
|
static COMMENT_MATCH: RegExp;
|
|
12
|
-
static getAllChannel(cwd: string): Promise<string[]>;
|
|
13
|
-
static chooseChannel(cwd: string): Promise<string | undefined>;
|
|
12
|
+
static getAllChannel(cwd: string, excludeChannels?: string[]): Promise<string[]>;
|
|
13
|
+
static chooseChannel(cwd: string, excludeChannels?: string[]): Promise<string | undefined>;
|
|
14
14
|
static withChannel(options: {
|
|
15
15
|
cwd: string;
|
|
16
16
|
channel?: string;
|
package/lib/cli/env_util.js
CHANGED
|
@@ -2,10 +2,10 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
3
|
import globby from 'globby';
|
|
4
4
|
import inquirer from 'inquirer';
|
|
5
|
-
import { dedent, escapeRegExp, isPlainObject, uniq } from 'vtils';
|
|
5
|
+
import { dedent, difference, escapeRegExp, isPlainObject, uniq } from 'vtils';
|
|
6
6
|
import { parse as yamlParse } from 'yaml';
|
|
7
7
|
export class EnvUtil {
|
|
8
|
-
static async getAllChannel(cwd) {
|
|
8
|
+
static async getAllChannel(cwd, excludeChannels) {
|
|
9
9
|
const channelFiles = await globby(['.env@*'], {
|
|
10
10
|
cwd: cwd,
|
|
11
11
|
onlyFiles: true,
|
|
@@ -14,11 +14,14 @@ export class EnvUtil {
|
|
|
14
14
|
if (channelFiles.length === 0) {
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
let channels = uniq(channelFiles.map(channel => channel.split('@').pop().split('.')[0]));
|
|
18
|
+
if (excludeChannels?.length) {
|
|
19
|
+
channels = difference(channels, excludeChannels);
|
|
20
|
+
}
|
|
18
21
|
return channels;
|
|
19
22
|
}
|
|
20
|
-
static async chooseChannel(cwd) {
|
|
21
|
-
const channels = await EnvUtil.getAllChannel(cwd);
|
|
23
|
+
static async chooseChannel(cwd, excludeChannels) {
|
|
24
|
+
const channels = await EnvUtil.getAllChannel(cwd, excludeChannels);
|
|
22
25
|
if (channels.length === 0) return undefined;
|
|
23
26
|
if (channels.length === 1) return channels[0];
|
|
24
27
|
const res = await inquirer.prompt([{
|
|
@@ -30,12 +33,14 @@ export class EnvUtil {
|
|
|
30
33
|
return res.channel || undefined;
|
|
31
34
|
}
|
|
32
35
|
static async withChannel(options) {
|
|
33
|
-
if (options.channel
|
|
34
|
-
const
|
|
36
|
+
if (options.channel?.startsWith('_')) {
|
|
37
|
+
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
38
|
+
const channel = await EnvUtil.chooseChannel(options.cwd, excludeChannels);
|
|
35
39
|
console.log(`========= ${channel} =========`);
|
|
36
40
|
await options.cb(channel);
|
|
37
|
-
} else if (options.channel
|
|
38
|
-
const
|
|
41
|
+
} else if (options.channel?.startsWith('@')) {
|
|
42
|
+
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
43
|
+
const channels = await EnvUtil.getAllChannel(options.cwd, excludeChannels);
|
|
39
44
|
for (const channel of channels) {
|
|
40
45
|
console.log(`========= ${channel} =========`);
|
|
41
46
|
await options.cb(channel);
|
package/lib/services/crypto.js
CHANGED
|
@@ -115,7 +115,7 @@ export class CryptoService {
|
|
|
115
115
|
* @param key - 用于加密的密钥(仅支持16字节的密钥)。
|
|
116
116
|
*/
|
|
117
117
|
aesEncrypt(text, key) {
|
|
118
|
-
const cipher = crypto.createCipheriv('aes-128-ecb', key, null);
|
|
118
|
+
const cipher = crypto.createCipheriv('aes-128-ecb', key.substring(0, 16), null);
|
|
119
119
|
let encrypted = cipher.update(text, 'utf8', 'base64');
|
|
120
120
|
encrypted += cipher.final('base64');
|
|
121
121
|
return encrypted;
|
|
@@ -128,7 +128,7 @@ export class CryptoService {
|
|
|
128
128
|
* @param key - 用于解密的密钥(仅支持16字节的密钥)。
|
|
129
129
|
*/
|
|
130
130
|
aesDecrypt(text, key) {
|
|
131
|
-
const decipher = crypto.createDecipheriv('aes-128-ecb', key, null);
|
|
131
|
+
const decipher = crypto.createDecipheriv('aes-128-ecb', key.substring(0, 16), null);
|
|
132
132
|
let decrypted = decipher.update(text, 'base64', 'utf8');
|
|
133
133
|
decrypted += decipher.final('utf8');
|
|
134
134
|
return decrypted;
|