lightshortcuts 1.0.5 → 1.0.8
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 +65 -3
- package/bin/lsc.js +146 -25
- package/index.js +0 -0
- package/lib/LSC.js +1 -1
- package/lib/core/API.js +22 -1
- package/lib/core/apiUrl.js +1 -0
- package/lib/defaults.js +0 -0
- package/lib/shortcuts.js +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,9 +23,25 @@
|
|
|
23
23
|
**发布前需要先登录系统**,需要输入API地址和token:
|
|
24
24
|
|
|
25
25
|
```
|
|
26
|
-
lsc login
|
|
26
|
+
Usage: lsc login [options]
|
|
27
|
+
|
|
28
|
+
登录会话
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
-e, --env <type> 选择管控台的环境,e为dev、prod
|
|
32
|
+
|
|
33
|
+
示例1:
|
|
34
|
+
lsc login -e dev #切换到测试环境
|
|
35
|
+
示例2:
|
|
36
|
+
lsc login --env prod #切换到生产环境
|
|
27
37
|
```
|
|
28
38
|
|
|
39
|
+
3. 切换不同会话环境,name:dev、prod
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
lsc use <name>
|
|
43
|
+
```
|
|
44
|
+
|
|
29
45
|
3. 初始化发布配置
|
|
30
46
|
|
|
31
47
|
方式一:交互模式进行创建(推荐方式):
|
|
@@ -36,7 +52,7 @@
|
|
|
36
52
|
|
|
37
53
|
之后将在当前路径下创建发布配置文件lsc.config.json,请打开文件,根据需要做相应修改:
|
|
38
54
|
|
|
39
|
-
```
|
|
55
|
+
```
|
|
40
56
|
{
|
|
41
57
|
"pkgid": "XXXXX", //离线包唯一ID
|
|
42
58
|
"set_pkg_version": "1.0.1", //指定发布版本
|
|
@@ -78,7 +94,53 @@
|
|
|
78
94
|
|
|
79
95
|
在配置好发布文件的前提下,可以缩写成以下命令:
|
|
80
96
|
|
|
81
|
-
```
|
|
97
|
+
```
|
|
82
98
|
lsc login && lsc publish
|
|
83
99
|
```
|
|
100
|
+
6. 会话注销
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
Usage: lsc logout [options]
|
|
104
|
+
|
|
105
|
+
注销会话
|
|
106
|
+
|
|
107
|
+
Options:
|
|
108
|
+
-e, --env <type> 选择管控台的环境
|
|
109
|
+
-l, --link <link> 注销指定管控台链接
|
|
110
|
+
-t, --token <token> 注销指定token
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
7. 帮助
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
➜ ~ lsc --help
|
|
117
|
+
Usage: lsc [options] [command]
|
|
118
|
+
|
|
119
|
+
Options:
|
|
120
|
+
-V, --version output the version number
|
|
121
|
+
-h, --help display help for command
|
|
122
|
+
|
|
123
|
+
Commands:
|
|
124
|
+
login [options] 登录会话
|
|
125
|
+
logout [options] 注销会话
|
|
126
|
+
use <name> 设置当前发布版本
|
|
127
|
+
config 交互式配置离线包发布参数
|
|
128
|
+
init 快速初始化配置模板
|
|
129
|
+
publish|p 发布离线包
|
|
130
|
+
batch|b 发布离线包
|
|
131
|
+
help [command] display help for command
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
附:
|
|
137
|
+
|
|
138
|
+
1、在Windows系统运行命令时,如果提示“此系统上禁止运行脚本”,则按如下方法解决:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
方法:
|
|
142
|
+
1、以管理员身份运行 Windows PowerShell(管理员)
|
|
143
|
+
2、输入 set-ExecutionPolicy RemoteSigned ,然后输入A 回车
|
|
144
|
+
3、还可以通过 get-ExecutionPolicy 查看当前的状态
|
|
145
|
+
```
|
|
84
146
|
|
package/bin/lsc.js
CHANGED
|
@@ -10,22 +10,35 @@ const { merge, getZipFileList } = require("../lib/utils");
|
|
|
10
10
|
const fileExists = require("../lib/helpers/file-exists");
|
|
11
11
|
|
|
12
12
|
// 读取发布配置文件
|
|
13
|
-
const lscrcPath = path.join(
|
|
13
|
+
const lscrcPath = path.join(
|
|
14
|
+
process.env.HOME || process.env.USERPROFILE,
|
|
15
|
+
".lscrc.json"
|
|
16
|
+
);
|
|
17
|
+
|
|
14
18
|
const defaultConfig = require("../lib/defaults");
|
|
15
|
-
const { checkSession, initAxiosConfig } = require("../lib/core/API");
|
|
19
|
+
const { checkSession, initAxiosConfig, logout } = require("../lib/core/API");
|
|
16
20
|
// 主目录下登录配置文件
|
|
17
21
|
let confPath = path.join(process.cwd(), "./lsc.config.json");
|
|
18
22
|
|
|
19
|
-
program.version("0.0.
|
|
23
|
+
program.version("0.0.7");
|
|
20
24
|
|
|
21
25
|
// 登录并保存token
|
|
22
26
|
let lightBaseURL = "";
|
|
23
27
|
let loginQuestions = [
|
|
28
|
+
{
|
|
29
|
+
type: "list",
|
|
30
|
+
message: "现在配置的环境是?",
|
|
31
|
+
name: "env",
|
|
32
|
+
choices: [
|
|
33
|
+
{ key: 0, value: "dev", name: "测试环境", checked: true },
|
|
34
|
+
{ key: 1, value: "prod", name: "生产环境" },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
24
37
|
{
|
|
25
38
|
type: "input",
|
|
26
39
|
message: "请输入API前缀地址:",
|
|
27
40
|
name: "lightBaseURL",
|
|
28
|
-
default: lightBaseURL || defaultConfig.lightBaseURL,
|
|
41
|
+
default: () => lightBaseURL || defaultConfig.lightBaseURL,
|
|
29
42
|
validate: async (url) => {
|
|
30
43
|
lightBaseURL = url;
|
|
31
44
|
return true;
|
|
@@ -42,7 +55,7 @@ let loginQuestions = [
|
|
|
42
55
|
},
|
|
43
56
|
];
|
|
44
57
|
//校验是否已经登录
|
|
45
|
-
const loginAction = async function () {
|
|
58
|
+
const loginAction = async function (env) {
|
|
46
59
|
fileExists(lscrcPath)
|
|
47
60
|
.then(async (res) => {
|
|
48
61
|
// 是否需要交互处理
|
|
@@ -50,15 +63,29 @@ const loginAction = async function () {
|
|
|
50
63
|
if (res) {
|
|
51
64
|
// 存在文件
|
|
52
65
|
let lscRc = require(lscrcPath);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
if (
|
|
67
|
+
lscRc[`${env}`] &&
|
|
68
|
+
lscRc[`${env}`].lightBaseURL &&
|
|
69
|
+
lscRc[`${env}`].token
|
|
70
|
+
) {
|
|
71
|
+
lightBaseURL = lscRc[`${env}`].lightBaseURL;
|
|
72
|
+
// console.log(lightBaseURL);
|
|
73
|
+
let res = await validSession(
|
|
74
|
+
lscRc[`${env}`].lightBaseURL,
|
|
75
|
+
lscRc[`${env}`].token
|
|
76
|
+
);
|
|
77
|
+
if (!res) {
|
|
78
|
+
// 已有API链接
|
|
79
|
+
// loginQuestions.shift();
|
|
80
|
+
console.log(lscRc[`${env}`]);
|
|
81
|
+
console.log("\n");
|
|
82
|
+
} else {
|
|
83
|
+
// token仍有效
|
|
84
|
+
console.log(`已登录,当前通道:${env}`);
|
|
85
|
+
needLoginProcessF = false;
|
|
86
|
+
}
|
|
58
87
|
} else {
|
|
59
|
-
|
|
60
|
-
console.log("已登录");
|
|
61
|
-
needLoginProcessF = false;
|
|
88
|
+
needLoginProcessF = true;
|
|
62
89
|
}
|
|
63
90
|
} else {
|
|
64
91
|
// 不存在文件
|
|
@@ -66,8 +93,22 @@ const loginAction = async function () {
|
|
|
66
93
|
}
|
|
67
94
|
if (needLoginProcessF) {
|
|
68
95
|
inquirer.prompt(loginQuestions).then(async (answers) => {
|
|
69
|
-
|
|
70
|
-
|
|
96
|
+
// let lscRc = require(lscrcPath);
|
|
97
|
+
// lscRc.currentEnv = env;
|
|
98
|
+
let { lightBaseURL, token, env } = answers;
|
|
99
|
+
// await writeConfig(answers, lscrcPath);
|
|
100
|
+
|
|
101
|
+
let lscRc = {};
|
|
102
|
+
let fef = await fileExists(lscrcPath);
|
|
103
|
+
|
|
104
|
+
if (fef) {
|
|
105
|
+
lscRc = require(lscrcPath);
|
|
106
|
+
}
|
|
107
|
+
lscRc.currentEnv = env;
|
|
108
|
+
lscRc[`${env}`] = { lightBaseURL, token };
|
|
109
|
+
|
|
110
|
+
await writeConfig(lscRc, lscrcPath);
|
|
111
|
+
// console.log(JSON.stringify(lscRc));
|
|
71
112
|
return true;
|
|
72
113
|
});
|
|
73
114
|
}
|
|
@@ -79,12 +120,87 @@ const loginAction = async function () {
|
|
|
79
120
|
};
|
|
80
121
|
program
|
|
81
122
|
.command("login")
|
|
82
|
-
.description("
|
|
83
|
-
.
|
|
84
|
-
|
|
123
|
+
.description("登录会话")
|
|
124
|
+
.option("-e, --env <type>", "选择管控台的环境")
|
|
125
|
+
.action(async (opts) => {
|
|
126
|
+
let { env } = opts;
|
|
127
|
+
if (env == undefined) {
|
|
128
|
+
// 没传环境变量参数
|
|
129
|
+
let fef = await fileExists(lscrcPath);
|
|
130
|
+
if (fef) {
|
|
131
|
+
let { currentEnv } = require(lscrcPath);
|
|
132
|
+
if (currentEnv) {
|
|
133
|
+
env = currentEnv;
|
|
134
|
+
} else {
|
|
135
|
+
env = "dev";
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
env = "dev";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
await loginAction(env);
|
|
85
142
|
});
|
|
86
143
|
|
|
87
|
-
|
|
144
|
+
// 注销会话
|
|
145
|
+
program
|
|
146
|
+
.command("logout")
|
|
147
|
+
.description("注销会话")
|
|
148
|
+
.option("-e, --env <type>", "选择管控台的环境")
|
|
149
|
+
.option("-l, --link <link>", "注销指定管控台链接")
|
|
150
|
+
.option("-t, --token <token>", "注销指定token")
|
|
151
|
+
.action(async (opts) => {
|
|
152
|
+
let { env, link, token } = opts;
|
|
153
|
+
let baseUrl, authToken;
|
|
154
|
+
if (env == undefined) {
|
|
155
|
+
// 没传env环境变量参数
|
|
156
|
+
let fef = await fileExists(lscrcPath);
|
|
157
|
+
if (fef) {
|
|
158
|
+
// 有本地会话配置,读取本地会话
|
|
159
|
+
let r = require(lscrcPath);
|
|
160
|
+
if (r.currentEnv) {
|
|
161
|
+
// 有本地会话
|
|
162
|
+
env = r.currentEnv;
|
|
163
|
+
//如果传入url,token则用传入的,否则用本地的;
|
|
164
|
+
baseUrl = link ? link : r[`${env}`].lightBaseURL;
|
|
165
|
+
authToken = token ? token : r[`${env}`].token;
|
|
166
|
+
} else {
|
|
167
|
+
console.log("不存在本地会话,请传入url,token");
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
// 不存在本地会话时
|
|
171
|
+
console.log("不存在本地会话,请传入url,token");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (baseUrl && authToken) {
|
|
175
|
+
await initAxiosConfig(baseUrl, authToken);
|
|
176
|
+
let f = await logout(token);
|
|
177
|
+
console.log(`注销${f ? "成功" : "失败"}`);
|
|
178
|
+
}else{
|
|
179
|
+
console.log("不存在本地会话,请传入url,token");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// 设置当前发布版本
|
|
185
|
+
program
|
|
186
|
+
.command("use <name>")
|
|
187
|
+
.description("设置当前发布版本")
|
|
188
|
+
.action(async (opts) => {
|
|
189
|
+
let fef = await fileExists(lscrcPath);
|
|
190
|
+
if (fef) {
|
|
191
|
+
let lscRc = require(lscrcPath);
|
|
192
|
+
lscRc.currentEnv = opts;
|
|
193
|
+
if (lscRc[`${opts}`]) {
|
|
194
|
+
await writeConfig(lscRc, lscrcPath);
|
|
195
|
+
} else {
|
|
196
|
+
console.log("不存在的离线包环境,请先进行登录:lsc login");
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
console.log("登录文件不存在,请先进行登录:lsc login");
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
program.command("config").description("交互式配置离线包发布参数").action(function () {
|
|
88
204
|
let initConfig = {},
|
|
89
205
|
initAnswers = {};
|
|
90
206
|
inquirer
|
|
@@ -155,7 +271,7 @@ program.command("config").action(function () {
|
|
|
155
271
|
default: "dist.zip",
|
|
156
272
|
},
|
|
157
273
|
{
|
|
158
|
-
type: "
|
|
274
|
+
type: "list",
|
|
159
275
|
message: "是否处理上一版本离线包?",
|
|
160
276
|
name: "task_status",
|
|
161
277
|
choices: [
|
|
@@ -251,7 +367,7 @@ const initConfAction = function () {
|
|
|
251
367
|
}
|
|
252
368
|
});
|
|
253
369
|
};
|
|
254
|
-
program.command("init").action(function () {
|
|
370
|
+
program.command("init").description("快速初始化配置模板").action(function () {
|
|
255
371
|
initConfAction();
|
|
256
372
|
});
|
|
257
373
|
|
|
@@ -265,7 +381,9 @@ program
|
|
|
265
381
|
feConF = await fileExists(confPath);
|
|
266
382
|
//是否存在配置文件
|
|
267
383
|
if (feLscF && feConF) {
|
|
268
|
-
const
|
|
384
|
+
const lscRC = require(lscrcPath),
|
|
385
|
+
{ currentEnv } = lscRC,
|
|
386
|
+
{ lightBaseURL, token } = lscRC[`${currentEnv}`];
|
|
269
387
|
const publishConfArgs = require(confPath);
|
|
270
388
|
|
|
271
389
|
if (publishConfArgs.publishInfo) {
|
|
@@ -305,9 +423,12 @@ program
|
|
|
305
423
|
// 批量离线包发布.已经包名作为pkgid
|
|
306
424
|
program
|
|
307
425
|
.command("batch")
|
|
426
|
+
.description("发布离线包")
|
|
308
427
|
.alias("b")
|
|
309
428
|
.action(async function () {
|
|
310
|
-
const
|
|
429
|
+
const lscRC = require(lscrcPath),
|
|
430
|
+
{ currentEnv } = lscRC,
|
|
431
|
+
{ lightBaseURL, token } = lscRC[`${currentEnv}`];
|
|
311
432
|
const publishConfArgs = require(confPath);
|
|
312
433
|
|
|
313
434
|
let currPath = path.join(process.cwd(), publishConfArgs.pkg_dir);
|
|
@@ -334,7 +455,7 @@ async function writeConfig(configArgs, path = "./lsc.config.json") {
|
|
|
334
455
|
if (err) {
|
|
335
456
|
throw err;
|
|
336
457
|
}
|
|
337
|
-
console.log("
|
|
458
|
+
console.log("已更新");
|
|
338
459
|
});
|
|
339
460
|
}
|
|
340
461
|
|
|
@@ -343,7 +464,7 @@ async function validSession(lightBaseURL, token) {
|
|
|
343
464
|
await initAxiosConfig(lightBaseURL, token);
|
|
344
465
|
let f = await checkSession(token);
|
|
345
466
|
if (!f) {
|
|
346
|
-
await console.log("\n会话已过期或者无效,请重新确认:", f);
|
|
467
|
+
await console.log("\n会话已过期或者无效,请重新确认:", f, "\n");
|
|
347
468
|
}
|
|
348
469
|
return f;
|
|
349
470
|
}
|
package/index.js
CHANGED
|
File without changes
|
package/lib/LSC.js
CHANGED
|
@@ -82,7 +82,7 @@ async function publish(h5pkgid, app_id) {
|
|
|
82
82
|
}),
|
|
83
83
|
e = qotRes.filter((val) => val.status == 0),
|
|
84
84
|
f = e[0];
|
|
85
|
-
//
|
|
85
|
+
// 处理上一版本的问题:保持、暂停、下架
|
|
86
86
|
if (task_status != 0) {
|
|
87
87
|
let sm = { 0: "发布", 1: "暂停", 2: "下架" };
|
|
88
88
|
const uotRes = await updateOfflineTask({
|
package/lib/core/API.js
CHANGED
|
@@ -50,6 +50,26 @@ const checkSession = async function (token) {
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
// 注销会话
|
|
54
|
+
const logout = async function (token){
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
axios
|
|
57
|
+
.get(ApiList.logout)
|
|
58
|
+
.then((res) => {
|
|
59
|
+
let { data } = res;
|
|
60
|
+
if (data.err_no === 0) {
|
|
61
|
+
resolve(true);
|
|
62
|
+
} else {
|
|
63
|
+
resolve(false);
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
.catch((err) => {
|
|
67
|
+
console.warn(`注销会话报错!${err.response.data.data[0].error_info}`);
|
|
68
|
+
resolve(false);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
53
73
|
// 上传文件,__filePath:绝对路径
|
|
54
74
|
const fileUpload = async function (__filePath) {
|
|
55
75
|
return new Promise((resolve, reject) => {
|
|
@@ -160,7 +180,7 @@ const queryOfflineVersionlist = async function (app_id, h5app_id) {
|
|
|
160
180
|
{ id } = t;
|
|
161
181
|
//pkg_id
|
|
162
182
|
let qovRes = await axios.get(
|
|
163
|
-
`${ApiList.queryOfflineVersionlist}?app_id=${app_id}&pkg_id=${id}&page_no=1&page_size=
|
|
183
|
+
`${ApiList.queryOfflineVersionlist}?app_id=${app_id}&pkg_id=${id}&page_no=1&page_size=30`
|
|
164
184
|
);
|
|
165
185
|
return qovRes.data;
|
|
166
186
|
};
|
|
@@ -306,6 +326,7 @@ const updateOfflineTask = async function (uotArgs = {}) {
|
|
|
306
326
|
|
|
307
327
|
module.exports = {
|
|
308
328
|
allOfflinePkgLists,
|
|
329
|
+
logout,
|
|
309
330
|
checkSession,
|
|
310
331
|
fileUpload,
|
|
311
332
|
queryOfflinePkgList,
|
package/lib/core/apiUrl.js
CHANGED
|
@@ -5,6 +5,7 @@ const offlineURlPrefix = `/light/light-platform-client/v/appdiy/offline/`;
|
|
|
5
5
|
const ApiList = {
|
|
6
6
|
fileUpload: "/ltcommon/file/v/upload?bizType=h5_offline_src",
|
|
7
7
|
checkSession: "/light/light-platform-client/v/auth/check_session",
|
|
8
|
+
logout:"/light/light-platform-client/v/auth/logout",
|
|
8
9
|
queryOfflinePkgList: offlineURlPrefix + "query_offline_pkglist1",
|
|
9
10
|
queryOfflineVersionlist: offlineURlPrefix + "query_offline_versionlist",
|
|
10
11
|
addOfflineH5pkg: offlineURlPrefix + "add_offline_h5pkg",
|
package/lib/defaults.js
CHANGED
|
File without changes
|
package/lib/shortcuts.js
CHANGED
|
File without changes
|