lightshortcuts 1.0.9 → 1.1.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/README.md +13 -2
- package/bin/lsc.js +655 -466
- package/docs/README.md +357 -0
- package/lib/LSC.js +303 -114
- package/lib/core/api.js +1134 -0
- package/lib/core/apiUrl.js +20 -8
- package/lib/defaults.js +7 -8
- package/lib/helpers/hsMd5.js +177 -0
- package/lib/helpers/hsUtils.js +74 -0
- package/lib/helpers/zip.js +164 -0
- package/lib/utils.js +66 -5
- package/lsc.config.json +22 -7
- package/package.json +2 -2
- package/lib/core/API.js +0 -453
package/bin/lsc.js
CHANGED
|
@@ -6,543 +6,732 @@ const { Command } = require("commander");
|
|
|
6
6
|
const inquirer = require("inquirer");
|
|
7
7
|
const program = new Command();
|
|
8
8
|
const { LSC } = require("../index");
|
|
9
|
-
const { merge, getZipFileList } = require("../lib/utils");
|
|
9
|
+
const { merge, getZipFileList, pwdMd5, fmtTime } = require("../lib/utils");
|
|
10
10
|
const fileExists = require("../lib/helpers/file-exists");
|
|
11
|
+
const { createZip } = require("../lib/helpers/zip");
|
|
11
12
|
|
|
13
|
+
const log = (message, ...args) => {
|
|
14
|
+
console.log(`[${fmtTime()}] ${message}`, ...args);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const error = (message, ...args) => {
|
|
18
|
+
console.error(`[${fmtTime()}] ${message}`, ...args);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const warn = (message, ...args) => {
|
|
22
|
+
console.warn(`[${fmtTime()}] ${message}`, ...args);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const info = (message, ...args) => {
|
|
26
|
+
console.info(`[${fmtTime()}] ${message}`, ...args);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// 主目录下登录配置文件
|
|
30
|
+
let confPath = path.join(process.cwd(), "./lsc.config.json");
|
|
12
31
|
// 读取发布配置文件
|
|
13
32
|
const lscrcPath = path.join(
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
process.cwd() || process.env.HOME || process.env.USERPROFILE,
|
|
34
|
+
".lscrc.json",
|
|
16
35
|
);
|
|
17
36
|
|
|
18
37
|
const defaultConfig = require("../lib/defaults");
|
|
19
38
|
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
39
|
+
submitLogin,
|
|
40
|
+
getCaptcha,
|
|
41
|
+
checkSession,
|
|
42
|
+
initAxiosConfig,
|
|
43
|
+
logout,
|
|
44
|
+
dealVersionList,
|
|
45
|
+
batchDealVersionList,
|
|
46
|
+
sendWechatWebhook,
|
|
25
47
|
} = require("../lib/core/API");
|
|
26
|
-
// 主目录下登录配置文件
|
|
27
|
-
let confPath = path.join(process.cwd(), "./lsc.config.json");
|
|
28
48
|
|
|
29
|
-
program.version("
|
|
49
|
+
program.version("1.1.0");
|
|
30
50
|
|
|
31
51
|
// 登录并保存token
|
|
32
52
|
let lightBaseURL = "";
|
|
33
53
|
let loginQuestions = [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
{
|
|
55
|
+
type: "list",
|
|
56
|
+
message: "现在配置的环境是?",
|
|
57
|
+
name: "env",
|
|
58
|
+
choices: [
|
|
59
|
+
{ key: 0, value: "dev", name: "测试环境", checked: true },
|
|
60
|
+
{ key: 1, value: "prod", name: "生产环境" },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "input",
|
|
65
|
+
message: "请输入API前缀地址:",
|
|
66
|
+
name: "lightBaseURL",
|
|
67
|
+
default: () => lightBaseURL || defaultConfig.lightBaseURL,
|
|
68
|
+
validate: async (url) => {
|
|
69
|
+
lightBaseURL = url;
|
|
70
|
+
return /^https?:\/\//.test(lightBaseURL);
|
|
42
71
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
72
|
+
filter: (url) => url.trim(),
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: "input",
|
|
76
|
+
message: "请输入手机号或邮箱:",
|
|
77
|
+
name: "account",
|
|
78
|
+
validate: async (account) => {
|
|
79
|
+
return (
|
|
80
|
+
/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$|^1[3456789]\d{9}$/.test(
|
|
81
|
+
account,
|
|
82
|
+
) && account.length > 0
|
|
83
|
+
);
|
|
52
84
|
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
85
|
+
filter: (account) => account.trim(),
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: "input",
|
|
89
|
+
message: "请输入密码:",
|
|
90
|
+
name: "rawPassword",
|
|
91
|
+
validate: async (rawPassword, answers) => {
|
|
92
|
+
if (rawPassword.length === 0) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
await initAxiosConfig(lightBaseURL, "No token");
|
|
96
|
+
let ps = pwdMd5(rawPassword, answers.account);
|
|
97
|
+
const { user_token } = await submitLogin({
|
|
98
|
+
account: answers.account,
|
|
99
|
+
password: ps,
|
|
100
|
+
});
|
|
101
|
+
if (user_token) {
|
|
102
|
+
answers.token = user_token;
|
|
103
|
+
answers.password = ps;
|
|
104
|
+
return true;
|
|
105
|
+
} else {
|
|
106
|
+
error("登录失败");
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
validatingText: "正在校验密码的有效性...",
|
|
111
|
+
},
|
|
112
|
+
// 企微推送启用问题
|
|
113
|
+
{
|
|
114
|
+
type: "confirm",
|
|
115
|
+
name: "enableWecomPush",
|
|
116
|
+
message: "是否启用企微推送?",
|
|
117
|
+
default: false,
|
|
118
|
+
},
|
|
119
|
+
// 企微链接问题(仅在启用时显示)
|
|
120
|
+
{
|
|
121
|
+
type: "input",
|
|
122
|
+
name: "wecomWebhook",
|
|
123
|
+
message: "请输入企微机器人Webhook链接:",
|
|
124
|
+
when: (answers) => answers.enableWecomPush,
|
|
125
|
+
validate: async (input) => {
|
|
126
|
+
try {
|
|
127
|
+
const result = await sendWechatWebhook(
|
|
128
|
+
input,
|
|
129
|
+
"为离线包发布配置企微机器人链接成功!",
|
|
130
|
+
);
|
|
131
|
+
log("配置机器人链接响应:", result);
|
|
132
|
+
return true;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
error("配置机器人链接失败:", error);
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
61
137
|
},
|
|
138
|
+
filter: (input) => input.trim(),
|
|
139
|
+
},
|
|
62
140
|
];
|
|
63
141
|
//校验是否已经登录
|
|
64
142
|
const loginAction = async function (env) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
143
|
+
fileExists(lscrcPath)
|
|
144
|
+
.then(async (res) => {
|
|
145
|
+
// 是否需要交互处理
|
|
146
|
+
let needLoginProcessF = true;
|
|
147
|
+
if (res) {
|
|
148
|
+
// 存在登录配置文件
|
|
149
|
+
log("存在登录配置文件");
|
|
150
|
+
let lscRc = require(lscrcPath);
|
|
151
|
+
// log(lscRc);
|
|
152
|
+
let { lightBaseURL, token, account, password } = lscRc[`${env}`];
|
|
153
|
+
if (lscRc[`${env}`] && lightBaseURL && token && account && password) {
|
|
154
|
+
// 提取登录配置文件字段,校验token是否有效
|
|
155
|
+
// lightBaseURL = lscRc[`${env}`].lightBaseURL;
|
|
156
|
+
log("检查会话有效性...");
|
|
157
|
+
await initAxiosConfig(lightBaseURL, token);
|
|
158
|
+
let validSessionRes = await validSession(lightBaseURL, token);
|
|
159
|
+
if (!validSessionRes) {
|
|
160
|
+
// 会话已过期或者无效,重新登录
|
|
161
|
+
await log("会话已过期或者无效,自动重新登录");
|
|
162
|
+
// 自动登录
|
|
163
|
+
let autoLoginRes = await submitLogin({
|
|
164
|
+
account,
|
|
165
|
+
password,
|
|
166
|
+
});
|
|
167
|
+
// log("登录响应:", res);
|
|
168
|
+
if (autoLoginRes.user_token) {
|
|
169
|
+
log(
|
|
170
|
+
`登录成功欢迎${autoLoginRes.user?.identity_name}`,
|
|
171
|
+
autoLoginRes.user_token,
|
|
172
|
+
);
|
|
173
|
+
//更新当前发布配置里面的token
|
|
174
|
+
lscRc[`${env}`].token = autoLoginRes.user_token;
|
|
175
|
+
//写入配置文件
|
|
176
|
+
// log("更新登录配置文件");
|
|
177
|
+
await writeConfig(lscRc, lscrcPath);
|
|
178
|
+
// log("登录配置已更新");
|
|
96
179
|
} else {
|
|
97
|
-
|
|
98
|
-
needLoginProcessF = true;
|
|
180
|
+
error("登录失败");
|
|
99
181
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
182
|
+
// 已有API链接
|
|
183
|
+
// loginQuestions.shift();
|
|
184
|
+
// log(lscRc[`${env}`]);
|
|
185
|
+
// log("\n");
|
|
186
|
+
} else {
|
|
187
|
+
// token仍有效
|
|
188
|
+
log(`已登录,当前通道:${env}`);
|
|
189
|
+
needLoginProcessF = false;
|
|
190
|
+
}
|
|
106
191
|
|
|
107
|
-
|
|
108
|
-
|
|
192
|
+
// 无需交互式登录处理
|
|
193
|
+
return;
|
|
194
|
+
} else {
|
|
195
|
+
needLoginProcessF = true;
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
// 不存在文件
|
|
199
|
+
needLoginProcessF = true;
|
|
200
|
+
}
|
|
201
|
+
if (needLoginProcessF) {
|
|
202
|
+
// 交互式登录处理
|
|
203
|
+
inquirer.prompt(loginQuestions).then(async (answers) => {
|
|
204
|
+
// let lscRc = require(lscrcPath);
|
|
205
|
+
// lscRc.currentEnv = env;
|
|
206
|
+
// log(`交互式登录问题:${JSON.stringify(answers)}`);
|
|
207
|
+
let { lightBaseURL, token, env, account, password, wecomWebhook } =
|
|
208
|
+
answers;
|
|
209
|
+
// await writeConfig(answers, lscrcPath);
|
|
109
210
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
lscRc.currentEnv = env;
|
|
114
|
-
lscRc[`${env}`] = { lightBaseURL, token };
|
|
211
|
+
let lscRc = {};
|
|
212
|
+
let fef = await fileExists(lscrcPath);
|
|
115
213
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
214
|
+
if (fef) {
|
|
215
|
+
lscRc = require(lscrcPath);
|
|
216
|
+
}
|
|
217
|
+
lscRc.currentEnv = env;
|
|
218
|
+
lscRc[`${env}`] = {
|
|
219
|
+
lightBaseURL,
|
|
220
|
+
token,
|
|
221
|
+
account,
|
|
222
|
+
password,
|
|
223
|
+
wecomWebhook,
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
await writeConfig(lscRc, lscrcPath);
|
|
227
|
+
// log(JSON.stringify(lscRc));
|
|
228
|
+
return true;
|
|
125
229
|
});
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
.catch((err) => {
|
|
233
|
+
log(err);
|
|
234
|
+
return false;
|
|
235
|
+
});
|
|
126
236
|
};
|
|
127
237
|
program
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
238
|
+
.command("login")
|
|
239
|
+
.description("登录会话")
|
|
240
|
+
.option("-e, --env <type>", "选择管控台的环境")
|
|
241
|
+
.action(async (opts) => {
|
|
242
|
+
let { env } = opts;
|
|
243
|
+
if (env == undefined) {
|
|
244
|
+
// 没传环境变量参数
|
|
245
|
+
let fef = await fileExists(lscrcPath);
|
|
246
|
+
if (fef) {
|
|
247
|
+
try {
|
|
248
|
+
let { currentEnv } = require(lscrcPath);
|
|
249
|
+
if (currentEnv) {
|
|
250
|
+
env = currentEnv;
|
|
251
|
+
} else {
|
|
252
|
+
env = "dev";
|
|
253
|
+
}
|
|
254
|
+
} catch (error) {
|
|
255
|
+
log(
|
|
256
|
+
`🔥🔥🔥读取登录配置文件失败:${error},请检查文件格式是否正确,或者删掉掉${lscrcPath}文件,使用lsc login重新登录!`,
|
|
257
|
+
);
|
|
146
258
|
}
|
|
147
|
-
|
|
148
|
-
|
|
259
|
+
} else {
|
|
260
|
+
env = "dev";
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
await loginAction(env);
|
|
264
|
+
});
|
|
265
|
+
//获取MD5密码
|
|
266
|
+
program
|
|
267
|
+
.command("md5")
|
|
268
|
+
.description("获取MD5密码")
|
|
269
|
+
.option("-p, --password <type>", "输入密码")
|
|
270
|
+
.option("-e, --email <type>", "输入邮箱")
|
|
271
|
+
.action(async (opts) => {
|
|
272
|
+
let { password, email } = opts;
|
|
273
|
+
//如何没有密码或者邮箱,通过交互式输入
|
|
274
|
+
if (!password || !email) {
|
|
275
|
+
inquirer
|
|
276
|
+
.prompt([
|
|
277
|
+
{
|
|
278
|
+
type: "input",
|
|
279
|
+
name: "password",
|
|
280
|
+
message: "请输入密码:",
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
type: "input",
|
|
284
|
+
name: "email",
|
|
285
|
+
message: "请输入邮箱:",
|
|
286
|
+
},
|
|
287
|
+
])
|
|
288
|
+
.then((answers) => {
|
|
289
|
+
password = answers.password;
|
|
290
|
+
email = answers.email;
|
|
291
|
+
log("密码MD5:", pwdMd5(password, email));
|
|
292
|
+
});
|
|
293
|
+
} else {
|
|
294
|
+
log("密码MD5:", pwdMd5(password, email));
|
|
295
|
+
}
|
|
296
|
+
});
|
|
149
297
|
|
|
150
298
|
// 注销会话
|
|
151
299
|
program
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
} else {
|
|
173
|
-
console.log("不存在本地会话,请传入url,token");
|
|
174
|
-
}
|
|
175
|
-
} else {
|
|
176
|
-
// 不存在本地会话时
|
|
177
|
-
console.log("不存在本地会话,请传入url,token");
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (baseUrl && authToken) {
|
|
181
|
-
await initAxiosConfig(baseUrl, authToken);
|
|
182
|
-
let f = await logout(token);
|
|
183
|
-
console.log(`注销${f ? "成功" : "失败"}`);
|
|
300
|
+
.command("logout")
|
|
301
|
+
.description("注销会话")
|
|
302
|
+
.option("-e, --env <type>", "选择管控台的环境")
|
|
303
|
+
.option("-l, --link <link>", "注销指定管控台链接")
|
|
304
|
+
.option("-t, --token <token>", "注销指定token")
|
|
305
|
+
.action(async (opts) => {
|
|
306
|
+
let { env, link, token } = opts;
|
|
307
|
+
let baseUrl, authToken;
|
|
308
|
+
if (env == undefined) {
|
|
309
|
+
// 没传env环境变量参数
|
|
310
|
+
let fef = await fileExists(lscrcPath);
|
|
311
|
+
if (fef) {
|
|
312
|
+
// 有本地会话配置,读取本地会话
|
|
313
|
+
let r = require(lscrcPath);
|
|
314
|
+
if (r.currentEnv) {
|
|
315
|
+
// 有本地会话
|
|
316
|
+
env = r.currentEnv;
|
|
317
|
+
//如果传入url,token则用传入的,否则用本地的;
|
|
318
|
+
baseUrl = link ? link : r[`${env}`].lightBaseURL;
|
|
319
|
+
authToken = token ? token : r[`${env}`].token;
|
|
184
320
|
} else {
|
|
185
|
-
|
|
321
|
+
log("不存在本地会话,请传入url,token");
|
|
186
322
|
}
|
|
187
|
-
|
|
323
|
+
} else {
|
|
324
|
+
// 不存在本地会话时
|
|
325
|
+
log("不存在本地会话,请传入url,token");
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (baseUrl && authToken) {
|
|
329
|
+
await initAxiosConfig(baseUrl, authToken);
|
|
330
|
+
let f = await logout(token);
|
|
331
|
+
log(`注销${f ? "成功" : "失败"}`);
|
|
332
|
+
} else {
|
|
333
|
+
log("不存在本地会话,请传入url,token");
|
|
334
|
+
}
|
|
335
|
+
});
|
|
188
336
|
|
|
189
337
|
// 设置当前发布版本
|
|
190
338
|
program
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
339
|
+
.command("use <name>")
|
|
340
|
+
.description("设置当前发布环境")
|
|
341
|
+
.action(async (opts) => {
|
|
342
|
+
let fef = await fileExists(lscrcPath);
|
|
343
|
+
if (fef) {
|
|
344
|
+
let lscRc = require(lscrcPath);
|
|
345
|
+
lscRc.currentEnv = opts;
|
|
346
|
+
if (lscRc[`${opts}`]) {
|
|
347
|
+
await writeConfig(lscRc, lscrcPath);
|
|
348
|
+
} else {
|
|
349
|
+
log("不存在的离线包环境,请先进行登录:lsc login");
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
log("登录文件不存在,请先进行登录:lsc login");
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
program
|
|
357
|
+
.command("config")
|
|
358
|
+
.description("交互式配置离线包发布参数")
|
|
359
|
+
.action(function () {
|
|
360
|
+
let initConfig = {},
|
|
361
|
+
initAnswers = {};
|
|
362
|
+
inquirer
|
|
363
|
+
.prompt([
|
|
364
|
+
{
|
|
365
|
+
type: "input",
|
|
366
|
+
message: "请输入离线包id:",
|
|
367
|
+
name: "pkgid",
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
type: "input",
|
|
371
|
+
message: "请指定离线包发布版本号:",
|
|
372
|
+
name: "set_pkg_version",
|
|
373
|
+
default: "1.0.1",
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
type: "input",
|
|
377
|
+
message: "APP版本iOS版本范围:",
|
|
378
|
+
name: "ios_version_scope",
|
|
379
|
+
default: "7.0.7",
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
type: "input",
|
|
383
|
+
message: "APP版本Android版本范围:",
|
|
384
|
+
name: "android_version_scope",
|
|
385
|
+
default: "7.0.7.0",
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
type: "input",
|
|
389
|
+
message: "APP版本Harmony版本范围:",
|
|
390
|
+
name: "harmony_version_scope",
|
|
391
|
+
default: "1.0.1",
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
type: "checkbox",
|
|
395
|
+
message: "请选择发布的APP:",
|
|
396
|
+
name: "publish_app_arr",
|
|
397
|
+
choices: [
|
|
398
|
+
{
|
|
399
|
+
key: "3542",
|
|
400
|
+
value: "3542",
|
|
401
|
+
name: "开发版",
|
|
402
|
+
checked: true,
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
key: "3543",
|
|
406
|
+
value: "3543",
|
|
407
|
+
name: "仿真版",
|
|
408
|
+
checked: true,
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
validate(answer) {
|
|
412
|
+
if (answer.length < 1) {
|
|
413
|
+
return "请至少选择一项";
|
|
202
414
|
}
|
|
415
|
+
return true;
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
type: "input",
|
|
420
|
+
message: "离线包压缩包存放相对位置:",
|
|
421
|
+
name: "pkg_dir",
|
|
422
|
+
default: "./dist/",
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
type: "input",
|
|
426
|
+
message: "离线包名称:",
|
|
427
|
+
name: "pkg_zip_name",
|
|
428
|
+
default: "dist.zip",
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
type: "list",
|
|
432
|
+
message: "是否处理上一版本离线包?",
|
|
433
|
+
name: "task_status",
|
|
434
|
+
choices: [
|
|
435
|
+
{ key: 0, value: 0, name: "保留", checked: true },
|
|
436
|
+
{ key: 1, value: 1, name: "暂停" },
|
|
437
|
+
{ key: 2, value: 2, name: "结束" },
|
|
438
|
+
],
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
type: "input",
|
|
442
|
+
message: "发布日志:",
|
|
443
|
+
name: "release_desc",
|
|
444
|
+
default: "功能更新",
|
|
445
|
+
when: (answers) => {
|
|
446
|
+
initAnswers = Object.assign({}, answers);
|
|
447
|
+
// log("initAnswers",initAnswers);
|
|
448
|
+
return true;
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
// {
|
|
452
|
+
// type: "input",
|
|
453
|
+
// message: "请输入API前缀地址:",
|
|
454
|
+
// name: "lightBaseURL",
|
|
455
|
+
// default: "https://xxx.xxx.xxx/lightadmin/pas-api",
|
|
456
|
+
// when: (answers) => {
|
|
457
|
+
// initAnswers = Object.assign({}, answers);
|
|
458
|
+
// // log("initAnswers",initAnswers);
|
|
459
|
+
// return true;
|
|
460
|
+
// },
|
|
461
|
+
// },
|
|
462
|
+
{
|
|
463
|
+
type: "confirm",
|
|
464
|
+
message: "是否使用以上配置?",
|
|
465
|
+
name: "useConfig",
|
|
466
|
+
default: true,
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
type: "confirm",
|
|
470
|
+
message: "是否保存配置?",
|
|
471
|
+
name: "saveConfig",
|
|
472
|
+
default: true,
|
|
473
|
+
when: function (answers) {
|
|
474
|
+
return answers.useConfig;
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
])
|
|
478
|
+
.then((asw) => {
|
|
479
|
+
let { useConfig, saveConfig } = asw;
|
|
480
|
+
if (useConfig) {
|
|
481
|
+
let totalConfig = {
|
|
482
|
+
...initAnswers,
|
|
483
|
+
apps_name: defaultConfig.publishInfo.apps_name,
|
|
484
|
+
};
|
|
485
|
+
if (saveConfig) {
|
|
486
|
+
// 保存配置
|
|
487
|
+
writeConfig(totalConfig);
|
|
488
|
+
}
|
|
489
|
+
log(totalConfig);
|
|
203
490
|
} else {
|
|
204
|
-
|
|
491
|
+
log("已结束!");
|
|
205
492
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
program
|
|
209
|
-
.command("config")
|
|
210
|
-
.description("交互式配置离线包发布参数")
|
|
211
|
-
.action(function () {
|
|
212
|
-
let initConfig = {},
|
|
213
|
-
initAnswers = {};
|
|
214
|
-
inquirer
|
|
215
|
-
.prompt([
|
|
216
|
-
// {
|
|
217
|
-
// type: "input",
|
|
218
|
-
// message: "请输入token:",
|
|
219
|
-
// name: "token",
|
|
220
|
-
// },
|
|
221
|
-
{
|
|
222
|
-
type: "input",
|
|
223
|
-
message: "请输入离线包id:",
|
|
224
|
-
name: "pkgid",
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
type: "input",
|
|
228
|
-
message: "请指定离线包发布版本号:",
|
|
229
|
-
name: "set_pkg_version",
|
|
230
|
-
default: "1.0.1",
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
type: "input",
|
|
234
|
-
message: "APP版本iOS版本范围:",
|
|
235
|
-
name: "ios_version_scope",
|
|
236
|
-
default: "7.0.6",
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
type: "input",
|
|
240
|
-
message: "APP版本Android版本范围:",
|
|
241
|
-
name: "android_version_scope",
|
|
242
|
-
default: "7.0.6.0",
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
type: "checkbox",
|
|
246
|
-
message: "请选择发布的APP:",
|
|
247
|
-
name: "publish_app_arr",
|
|
248
|
-
choices: [
|
|
249
|
-
{
|
|
250
|
-
key: "3577",
|
|
251
|
-
value: "3592",
|
|
252
|
-
name: "开发版_iOS",
|
|
253
|
-
checked: true,
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
key: "3577",
|
|
257
|
-
value: "3577",
|
|
258
|
-
name: "开发版_安卓",
|
|
259
|
-
checked: true,
|
|
260
|
-
},
|
|
261
|
-
],
|
|
262
|
-
validate(answer) {
|
|
263
|
-
if (answer.length < 1) {
|
|
264
|
-
return "请至少选择一项";
|
|
265
|
-
}
|
|
266
|
-
return true;
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
type: "input",
|
|
271
|
-
message: "离线包压缩包存放相对位置:",
|
|
272
|
-
name: "pkg_dir",
|
|
273
|
-
default: "./dist/",
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
type: "input",
|
|
277
|
-
message: "离线包名称:",
|
|
278
|
-
name: "pkg_zip_name",
|
|
279
|
-
default: "dist.zip",
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
type: "list",
|
|
283
|
-
message: "是否处理上一版本离线包?",
|
|
284
|
-
name: "task_status",
|
|
285
|
-
choices: [
|
|
286
|
-
{ key: 0, value: 0, name: "保留", checked: true },
|
|
287
|
-
{ key: 1, value: 1, name: "暂停" },
|
|
288
|
-
{ key: 2, value: 2, name: "结束" },
|
|
289
|
-
],
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
type: "input",
|
|
293
|
-
message: "发布日志:",
|
|
294
|
-
name: "release_desc",
|
|
295
|
-
default: "功能更新",
|
|
296
|
-
when: (answers) => {
|
|
297
|
-
initAnswers = Object.assign({}, answers);
|
|
298
|
-
// console.log("initAnswers",initAnswers);
|
|
299
|
-
return true;
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
// {
|
|
303
|
-
// type: "input",
|
|
304
|
-
// message: "请输入API前缀地址:",
|
|
305
|
-
// name: "lightBaseURL",
|
|
306
|
-
// default: "https://xxx.xxx.xxx/lightadmin/pas-api",
|
|
307
|
-
// when: (answers) => {
|
|
308
|
-
// initAnswers = Object.assign({}, answers);
|
|
309
|
-
// // console.log("initAnswers",initAnswers);
|
|
310
|
-
// return true;
|
|
311
|
-
// },
|
|
312
|
-
// },
|
|
313
|
-
{
|
|
314
|
-
type: "confirm",
|
|
315
|
-
message: "是否使用以上配置?",
|
|
316
|
-
name: "useConfig",
|
|
317
|
-
default: true,
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
type: "confirm",
|
|
321
|
-
message: "是否保存配置?",
|
|
322
|
-
name: "saveConfig",
|
|
323
|
-
default: true,
|
|
324
|
-
when: function (answers) {
|
|
325
|
-
return answers.useConfig;
|
|
326
|
-
},
|
|
327
|
-
},
|
|
328
|
-
])
|
|
329
|
-
.then((asw) => {
|
|
330
|
-
let { useConfig, saveConfig } = asw;
|
|
331
|
-
if (useConfig) {
|
|
332
|
-
let totalConfig = {
|
|
333
|
-
...initAnswers,
|
|
334
|
-
apps_name: defaultConfig.publishInfo.apps_name,
|
|
335
|
-
};
|
|
336
|
-
if (saveConfig) {
|
|
337
|
-
// 保存配置
|
|
338
|
-
writeConfig(totalConfig);
|
|
339
|
-
}
|
|
340
|
-
console.log(totalConfig);
|
|
341
|
-
} else {
|
|
342
|
-
console.log("已结束!");
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
});
|
|
493
|
+
});
|
|
494
|
+
});
|
|
346
495
|
|
|
347
496
|
// 初始化配置模板
|
|
348
497
|
const initConfAction = function () {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
});
|
|
498
|
+
fileExists(confPath).then((res) => {
|
|
499
|
+
if (res) {
|
|
500
|
+
log("注意,配置文件已经存在!!!内容如下:");
|
|
501
|
+
log(require(confPath));
|
|
502
|
+
// 存在配置文件,唤起交互输入
|
|
503
|
+
inquirer
|
|
504
|
+
.prompt([
|
|
505
|
+
{
|
|
506
|
+
type: "confirm",
|
|
507
|
+
message: "是否重新初始化?",
|
|
508
|
+
name: "initConfig",
|
|
509
|
+
default: false,
|
|
510
|
+
},
|
|
511
|
+
])
|
|
512
|
+
.then((answer) => {
|
|
513
|
+
if (answer.initConfig) {
|
|
514
|
+
let mergeConf = Object.assign(defaultConfig.publishInfo);
|
|
515
|
+
writeConfig(mergeConf, confPath);
|
|
516
|
+
} else {
|
|
517
|
+
log("配置无变化");
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
} else {
|
|
521
|
+
writeConfig(defaultConfig);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
377
524
|
};
|
|
378
525
|
program
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
526
|
+
.command("init")
|
|
527
|
+
.description("快速初始化配置模板")
|
|
528
|
+
.action(function () {
|
|
529
|
+
initConfAction();
|
|
530
|
+
});
|
|
384
531
|
|
|
385
532
|
// 单项目发布
|
|
386
533
|
program
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
534
|
+
.command("publish")
|
|
535
|
+
.alias("p")
|
|
536
|
+
.description("发布离线包")
|
|
537
|
+
.action(async () => {
|
|
538
|
+
let feLscF = await fileExists(lscrcPath),
|
|
539
|
+
feConF = await fileExists(confPath);
|
|
540
|
+
//是否存在配置文件
|
|
541
|
+
if (feLscF && feConF) {
|
|
542
|
+
const lscRC = require(lscrcPath),
|
|
543
|
+
{ currentEnv } = lscRC,
|
|
544
|
+
{ lightBaseURL, token, wecomWebhook } = lscRC[`${currentEnv}`];
|
|
545
|
+
const publishConfArgs = require(confPath);
|
|
399
546
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
547
|
+
if (publishConfArgs.publishInfo) {
|
|
548
|
+
log(
|
|
549
|
+
"温馨提示:程序已升级!\n请使用命令lsc config 或 lsc init 重新生成发布配置",
|
|
550
|
+
);
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
406
553
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
554
|
+
try {
|
|
555
|
+
// let lscConfig = require(confPath);
|
|
556
|
+
let totalConfig = {
|
|
557
|
+
publishInfo: { ...publishConfArgs, token },
|
|
558
|
+
lightBaseURL,
|
|
559
|
+
wecomWebhook,
|
|
560
|
+
};
|
|
561
|
+
// log("发布配置:\n", totalConfig);
|
|
562
|
+
LSC(totalConfig);
|
|
563
|
+
} catch (error) {
|
|
564
|
+
log("主程序异常", error);
|
|
565
|
+
}
|
|
566
|
+
} else {
|
|
567
|
+
// 不存在配置文件,唤起交互输入
|
|
568
|
+
let t = "",
|
|
569
|
+
f = "";
|
|
570
|
+
if (!feLscF) {
|
|
571
|
+
f = "登录";
|
|
572
|
+
t = "lsc login";
|
|
573
|
+
}
|
|
574
|
+
if (!feConF) {
|
|
575
|
+
f = "离线包发布";
|
|
576
|
+
t = "lsc config 或 lsc init";
|
|
577
|
+
}
|
|
578
|
+
log(`不存在${f}配置文件,请使用命令创建:${t}`);
|
|
579
|
+
}
|
|
580
|
+
});
|
|
433
581
|
|
|
434
582
|
// 批量离线包发布.已经包名作为pkgid
|
|
435
583
|
program
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
584
|
+
.command("batch")
|
|
585
|
+
.description("发布离线包")
|
|
586
|
+
.alias("b")
|
|
587
|
+
.action(async function () {
|
|
588
|
+
const lscRC = require(lscrcPath),
|
|
589
|
+
{ currentEnv } = lscRC,
|
|
590
|
+
{ lightBaseURL, token } = lscRC[`${currentEnv}`];
|
|
591
|
+
const publishConfArgs = require(confPath);
|
|
444
592
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
593
|
+
let currPath = path.join(process.cwd(), publishConfArgs.pkg_dir);
|
|
594
|
+
let zipLists = await getZipFileList(currPath);
|
|
595
|
+
for (let i = 0; i < zipLists.length; i++) {
|
|
596
|
+
const e = zipLists[i],
|
|
597
|
+
s = e.split("."),
|
|
598
|
+
pkgid = s[0];
|
|
599
|
+
let totalConfig = {
|
|
600
|
+
publishInfo: { ...publishConfArgs, token },
|
|
601
|
+
lightBaseURL,
|
|
602
|
+
};
|
|
603
|
+
let batchConfig = merge(totalConfig, {
|
|
604
|
+
publishInfo: { pkgid, pkg_zip_name: e },
|
|
605
|
+
});
|
|
606
|
+
// log("batchConfig\n", batchConfig);
|
|
607
|
+
await LSC(batchConfig);
|
|
608
|
+
}
|
|
609
|
+
});
|
|
462
610
|
|
|
463
611
|
// 处理离线包兼容版本相互重叠的情况
|
|
464
612
|
program
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
});
|
|
613
|
+
.command("deal version")
|
|
614
|
+
.description("处理离线包兼容版本相互重叠的情况,谨慎使用!")
|
|
615
|
+
.action(async function () {
|
|
616
|
+
let dv = [
|
|
617
|
+
{
|
|
618
|
+
type: "input",
|
|
619
|
+
message: "请输入app_id:",
|
|
620
|
+
name: "app_id",
|
|
621
|
+
default: 3592,
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
type: "input",
|
|
625
|
+
message: "请输入pkg_id:",
|
|
626
|
+
name: "pkg_id",
|
|
627
|
+
default: 2307,
|
|
628
|
+
},
|
|
629
|
+
];
|
|
630
|
+
inquirer.prompt(dv).then(async function (aws) {
|
|
631
|
+
const { app_id, pkg_id } = aws;
|
|
632
|
+
let f = await fileExists(lscrcPath);
|
|
633
|
+
if (f) {
|
|
634
|
+
let lscRc = require(lscrcPath),
|
|
635
|
+
{ currentEnv } = lscRc;
|
|
636
|
+
const { lightBaseURL, token } = lscRc[`${currentEnv}`];
|
|
637
|
+
await initAxiosConfig(lightBaseURL, token);
|
|
638
|
+
await dealVersionList({ app_id, pkg_id });
|
|
639
|
+
} else {
|
|
640
|
+
log("登录文件不存在,请先进行登录:lsc login");
|
|
641
|
+
}
|
|
495
642
|
});
|
|
643
|
+
});
|
|
496
644
|
|
|
497
645
|
// 处理离线包兼容版本相互重叠的情况
|
|
498
646
|
program
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
});
|
|
647
|
+
.command("clean all")
|
|
648
|
+
.description("批量处理离线包兼容版本相互重叠的情况,谨慎使用!")
|
|
649
|
+
.action(async function () {
|
|
650
|
+
log("批量处理离线包兼容版本相互重叠的情况,谨慎使用!");
|
|
651
|
+
let dv = [
|
|
652
|
+
{
|
|
653
|
+
type: "input",
|
|
654
|
+
message: "请输入app_id列表,以逗号分隔:",
|
|
655
|
+
name: "app_id",
|
|
656
|
+
default: "3592,3577,3580,3562",
|
|
657
|
+
},
|
|
658
|
+
];
|
|
659
|
+
inquirer.prompt(dv).then(async function (aws) {
|
|
660
|
+
const { app_id } = aws;
|
|
661
|
+
log((app_id + "").split(","));
|
|
662
|
+
let ids = (app_id + "").split(",");
|
|
663
|
+
let f = await fileExists(lscrcPath);
|
|
664
|
+
if (f) {
|
|
665
|
+
let lscRc = require(lscrcPath),
|
|
666
|
+
{ currentEnv } = lscRc;
|
|
667
|
+
const { lightBaseURL, token } = lscRc[`${currentEnv}`];
|
|
668
|
+
await initAxiosConfig(lightBaseURL, token);
|
|
669
|
+
await batchDealVersionList(ids);
|
|
670
|
+
} else {
|
|
671
|
+
log("登录文件不存在,请先进行登录:lsc login");
|
|
672
|
+
}
|
|
526
673
|
});
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
//打印当前地址
|
|
677
|
+
program
|
|
678
|
+
.command("pwd")
|
|
679
|
+
.alias("dir")
|
|
680
|
+
.description("打印当前地址")
|
|
681
|
+
.action(async function () {
|
|
682
|
+
console.log(process.cwd());
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
// 默认压缩当前dist目录下的所有文件(不包括自身生成的zip文件)压缩成一个zip文件
|
|
686
|
+
//支持传入dist目录路径--dir参数指定dist目录路径
|
|
687
|
+
program
|
|
688
|
+
.command("zip")
|
|
689
|
+
.description(
|
|
690
|
+
"将dist或指定目录下的所有文件(不包括自身生成的zip文件)压缩成一个zip文件",
|
|
691
|
+
)
|
|
692
|
+
.option("--dir <distDir>", "指定dist绝对路径")
|
|
693
|
+
//指定输出zip文件路径--output参数指定输出zip文件路径
|
|
694
|
+
.option("--output <outputZipFile>", "指定输出zip文件路径")
|
|
695
|
+
//指定zip文件名--zipFilename参数指定zip文件名
|
|
696
|
+
.option("--zn <zipFilename>", "指定zip文件名")
|
|
697
|
+
.action(async function (cmd) {
|
|
698
|
+
log("压缩dist目录下的所有文件(不包括自身生成的zip文件)压缩成一个zip文件");
|
|
699
|
+
try {
|
|
700
|
+
let lscConfig = require(path.join(process.cwd(), "./lsc.config.json"));
|
|
701
|
+
await createZip({
|
|
702
|
+
sourceFolder: cmd.dir || path.join(process.cwd(), lscConfig.pkg_dir),
|
|
703
|
+
outputZipFile:
|
|
704
|
+
cmd.output || path.join(process.cwd(), lscConfig.pkg_dir),
|
|
705
|
+
zipFilename: cmd.zn || lscConfig.pkg_zip_name,
|
|
706
|
+
});
|
|
707
|
+
} catch (e) {
|
|
708
|
+
throw new Error(
|
|
709
|
+
`压缩发生异常: ${e.message},请先使用lsc config或lsc init创建`,
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
});
|
|
527
713
|
|
|
528
714
|
async function writeConfig(configArgs, path = "./lsc.config.json") {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
715
|
+
// 写入文件内容(如果文件不存在会创建一个文件)
|
|
716
|
+
writeFile(path, JSON.stringify(configArgs), { flag: "w" }, function (err) {
|
|
717
|
+
log("写入配置文件...");
|
|
718
|
+
// log(configArgs);
|
|
719
|
+
if (err) {
|
|
720
|
+
throw err;
|
|
721
|
+
}
|
|
722
|
+
log("写入配置文件成功");
|
|
723
|
+
});
|
|
536
724
|
}
|
|
537
725
|
|
|
538
726
|
// 查询会话的有效性
|
|
539
727
|
async function validSession(lightBaseURL, token) {
|
|
728
|
+
try {
|
|
540
729
|
await initAxiosConfig(lightBaseURL, token);
|
|
541
730
|
let f = await checkSession(token);
|
|
542
|
-
if (!f) {
|
|
543
|
-
await console.log("\n会话已过期或者无效,请重新确认:", f, "\n");
|
|
544
|
-
}
|
|
545
731
|
return f;
|
|
732
|
+
} catch (e) {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
546
735
|
}
|
|
547
736
|
|
|
548
737
|
program.parse(process.argv);
|