lightshortcuts 1.0.3 → 1.0.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Light快捷指令
2
2
 
3
- 仅适用于Light管控台的快捷指令,用于快速处理离线包的一些处理,如发布等。请向相关平台管理员获取地址和token、AppID。
3
+ 仅适用于Light管控台的快捷指令,用于快速处理离线包的一些处理,如发布等。请向相关平台管理员获取API地址和token、AppID。
4
4
 
5
5
  #### 使用说明
6
6
 
@@ -18,15 +18,17 @@
18
18
  npm update -g lightshortcuts
19
19
  ```
20
20
 
21
- 2. 初始化发布配置
21
+ 2. 登录管控台系统
22
22
 
23
- 方式一:使用模板一键初始化:
23
+ **发布前需要先登录系统**,需要输入API地址和token:
24
24
 
25
- ```bash
26
- lsc init
25
+ ```
26
+ lsc login
27
27
  ```
28
28
 
29
- 方式二:交互模式进行创建:
29
+ 3. 初始化发布配置
30
+
31
+ 方式一:交互模式进行创建(推荐方式):
30
32
 
31
33
  ```bash
32
34
  lsc config
@@ -36,29 +38,31 @@
36
38
 
37
39
  ```json
38
40
  {
39
- "publishInfo": {
40
- "token": "XXXXX", //登录token
41
- "pkgid": "XXXXX", //离线包ID
42
- "set_pkg_version": "1.0.1", //指定发布版本
43
- "publish_app_arr": [3577, 3592], //AppID列表发布到指定App,默认开发版
44
- "apps_name": {
45
- "3592": "开发版_iOS",
46
- "3577": "开发版_安卓"
47
- },
48
- "android_version_scope": "7.0.6.0", //Android端离线包兼容版本
49
- "ios_version_scope": "7.0.6", //iOS端离线包兼容版本
50
- "pkg_zip_name": "dist.zip",//离线包压缩包文件名
51
- "pkg_dir": "./dist/", //离线包相对所在路径
52
- "release_desc": "功能更新", //发布日志
53
- "task_status": "0" //发布当前版本后,对上一版本的处理:0:发布(不处理),1:暂停,2:结束(下架)
54
- },
55
- "lightBaseURL": "https://xxx.xxx.xxx/lightadmin/pas-api"//Light管控台地址
41
+ "pkgid": "XXXXX", //离线包唯一ID
42
+ "set_pkg_version": "1.0.1", //指定发布版本
43
+ "publish_app_arr": [3577, 3592], //AppID列表发布到指定App,默认开发版
44
+ "apps_name": {
45
+ "3592": "开发版_iOS",
46
+ "3577": "开发版_安卓"
47
+ },
48
+ "android_version_scope": "7.0.6.0", //Android端离线包兼容版本
49
+ "ios_version_scope": "7.0.6", //iOS端离线包兼容版本
50
+ "pkg_zip_name": "dist.zip",//离线包压缩包文件名
51
+ "pkg_dir": "./dist/", //离线包相对所在路径
52
+ "release_desc": "若干功能更新", //发布日志
53
+ "task_status": "0" //发布当前版本后,对上一版本的处理:0:发布(不处理),1:暂停,2:结束(下架)
56
54
  }
57
55
  ```
58
56
 
59
-
57
+ 方式二:使用模板一键初始化:
60
58
 
61
- 3. 离线包发布
59
+ ```bash
60
+ lsc init
61
+ ```
62
+
63
+ 之后再根据项目进行修改。
64
+
65
+ 4. 离线包发布
62
66
 
63
67
  - 单项目发布:
64
68
 
@@ -72,4 +76,9 @@
72
76
  lsc batch #或简写为 lsc b
73
77
  ```
74
78
 
75
-
79
+ 在配置好发布文件的前提下,可以缩写成以下命令:
80
+
81
+ ```bash
82
+ lsc login && lsc publish
83
+ ```
84
+
package/bin/lsc.js CHANGED
@@ -1,31 +1,99 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { access, statSync, constants, writeFile, readdirSync } = require("fs");
3
+ const { writeFile } = require("fs");
4
4
  const path = require("path");
5
5
  const { Command } = require("commander");
6
6
  const inquirer = require("inquirer");
7
7
  const program = new Command();
8
8
  const { LSC } = require("../index");
9
9
  const { merge, getZipFileList } = require("../lib/utils");
10
- const loadModSync = require("../lib/helpers/loadModSync");
10
+ const fileExists = require("../lib/helpers/file-exists");
11
11
 
12
12
  // 读取发布配置文件
13
+ const lscrcPath = path.join(process.env.HOME, ".lscrc.json");
13
14
  const defaultConfig = require("../lib/defaults");
14
- const { checkSession } = require("../lib/core/API");
15
+ const { checkSession, initAxiosConfig } = require("../lib/core/API");
16
+ // 主目录下登录配置文件
15
17
  let confPath = path.join(process.cwd(), "./lsc.config.json");
16
18
 
17
- program.version("0.0.2");
19
+ program.version("0.0.3");
20
+
21
+ // 登录并保存token
22
+ let lightBaseURL = "";
23
+ let loginQuestions = [
24
+ {
25
+ type: "input",
26
+ message: "请输入API前缀地址:",
27
+ name: "lightBaseURL",
28
+ default: lightBaseURL || defaultConfig.lightBaseURL,
29
+ validate: async (url) => {
30
+ lightBaseURL = url;
31
+ return true;
32
+ },
33
+ },
34
+ {
35
+ type: "input",
36
+ message: "请输入token:",
37
+ name: "token",
38
+ validate: async (token) => {
39
+ return await validSession(lightBaseURL, token);
40
+ },
41
+ validatingText: "正在校验token的有效性...",
42
+ },
43
+ ];
44
+ //校验是否已经登录
45
+ const loginAction = async function () {
46
+ fileExists(lscrcPath)
47
+ .then(async (res) => {
48
+ // 是否需要交互处理
49
+ let needLoginProcessF = true;
50
+ if (res) {
51
+ // 存在文件
52
+ let lscRc = require(lscrcPath);
53
+ lightBaseURL = lscRc.lightBaseURL;
54
+ let res = await validSession(lscRc.lightBaseURL, lscRc.token);
55
+ if (!res) {
56
+ // 已有API链接
57
+ // loginQuestions.shift();
58
+ } else {
59
+ // token仍有效
60
+ console.log("已登录");
61
+ needLoginProcessF = false;
62
+ }
63
+ } else {
64
+ // 不存在文件
65
+ needLoginProcessF = true;
66
+ }
67
+ if (needLoginProcessF) {
68
+ inquirer.prompt(loginQuestions).then(async (answers) => {
69
+ await writeConfig(answers, lscrcPath);
70
+ console.log(JSON.stringify(answers));
71
+ return true;
72
+ });
73
+ }
74
+ })
75
+ .catch((err) => {
76
+ console.log(err);
77
+ return false;
78
+ });
79
+ };
80
+ program
81
+ .command("login")
82
+ .description("输入登录token")
83
+ .action(async () => {
84
+ await loginAction();
85
+ });
18
86
 
19
87
  program.command("config").action(function () {
20
88
  let initConfig = {},
21
89
  initAnswers = {};
22
90
  inquirer
23
91
  .prompt([
24
- {
25
- type: "input",
26
- message: "请输入token:",
27
- name: "token",
28
- },
92
+ // {
93
+ // type: "input",
94
+ // message: "请输入token:",
95
+ // name: "token",
96
+ // },
29
97
  {
30
98
  type: "input",
31
99
  message: "请输入离线包id:",
@@ -101,18 +169,23 @@ program.command("config").action(function () {
101
169
  message: "发布日志:",
102
170
  name: "release_desc",
103
171
  default: "功能更新",
104
- },
105
- {
106
- type: "input",
107
- message: "请输入API前缀地址:",
108
- name: "lightBaseURL",
109
- default: "https://xxx.xxx.xxx/lightadmin/pas-api",
110
- when:(answers)=>{
111
- initAnswers = Object.assign({},answers);
172
+ when: (answers) => {
173
+ initAnswers = Object.assign({}, answers);
112
174
  // console.log("initAnswers",initAnswers);
113
175
  return true;
114
- }
176
+ },
115
177
  },
178
+ // {
179
+ // type: "input",
180
+ // message: "请输入API前缀地址:",
181
+ // name: "lightBaseURL",
182
+ // default: "https://xxx.xxx.xxx/lightadmin/pas-api",
183
+ // when: (answers) => {
184
+ // initAnswers = Object.assign({}, answers);
185
+ // // console.log("initAnswers",initAnswers);
186
+ // return true;
187
+ // },
188
+ // },
116
189
  {
117
190
  type: "confirm",
118
191
  message: "是否使用以上配置?",
@@ -130,13 +203,11 @@ program.command("config").action(function () {
130
203
  },
131
204
  ])
132
205
  .then((asw) => {
133
- // console.log("initAnswersXXXXX",initAnswers);
134
- // 用户输入的结果最终会在这里输出
135
206
  let { useConfig, saveConfig } = asw;
136
207
  if (useConfig) {
137
208
  let totalConfig = {
138
- publishInfo: {...initAnswers,apps_name:defaultConfig.publishInfo.apps_name},
139
- lightBaseURL:asw.lightBaseURL,
209
+ ...initAnswers,
210
+ apps_name: defaultConfig.publishInfo.apps_name,
140
211
  };
141
212
  if (saveConfig) {
142
213
  // 保存配置
@@ -149,23 +220,28 @@ program.command("config").action(function () {
149
220
  });
150
221
  });
151
222
 
152
- program.command("init").action(function () {
153
- let confPath = path.join(process.cwd(), "./lsc.config.json");
154
- access(confPath, constants.F_OK, (err) => {
155
- if (!err) {
223
+ // 初始化配置模板
224
+ const initConfAction = function () {
225
+ fileExists(confPath).then((res) => {
226
+ if (res) {
227
+ console.log("注意,配置文件已经存在!!!内容如下:");
228
+ console.log(require(confPath));
156
229
  // 存在配置文件,唤起交互输入
157
230
  inquirer
158
231
  .prompt([
159
232
  {
160
233
  type: "confirm",
161
- message: "注意!!!配置文件已经存在,是否重新初始化?",
234
+ message: "是否重新初始化?",
162
235
  name: "initConfig",
163
236
  default: false,
164
237
  },
165
238
  ])
166
239
  .then((answer) => {
167
240
  if (answer.initConfig) {
168
- writeConfig(defaultConfig);
241
+ let mergeConf = Object.assign(
242
+ defaultConfig.publishInfo
243
+ );
244
+ writeConfig(mergeConf, confPath);
169
245
  } else {
170
246
  console.log("配置无变化");
171
247
  }
@@ -174,6 +250,9 @@ program.command("init").action(function () {
174
250
  writeConfig(defaultConfig);
175
251
  }
176
252
  });
253
+ };
254
+ program.command("init").action(function () {
255
+ initConfAction();
177
256
  });
178
257
 
179
258
  // 单项目发布
@@ -181,23 +260,46 @@ program
181
260
  .command("publish")
182
261
  .alias("p")
183
262
  .description("发布离线包")
184
- .action(() => {
185
- access(confPath, constants.F_OK, (err) => {
186
- if (!err) {
187
- try {
188
- let lscConfig = require(confPath);
189
- let totalConfig = merge(defaultConfig, lscConfig);
190
- LSC(totalConfig);
191
- } catch (error) {
192
- console.log("主程序异常", error);
193
- }
194
- } else {
195
- // 不存在配置文件,唤起交互输入
263
+ .action(async () => {
264
+ let feLscF = await fileExists(lscrcPath),
265
+ feConF = await fileExists(confPath);
266
+ //是否存在配置文件
267
+ if (feLscF && feConF) {
268
+ const { lightBaseURL, token } = require(lscrcPath);
269
+ const publishConfArgs = require(confPath);
270
+
271
+ if (publishConfArgs.publishInfo) {
196
272
  console.log(
197
- "不存在配置文件,请先进行配置或者使用如下命令创建:lsc init"
273
+ "温馨提示:程序已升级!\n请使用命令lsc config 或 lsc init 重新生成发布配置"
198
274
  );
275
+ return;
199
276
  }
200
- });
277
+
278
+ try {
279
+ // let lscConfig = require(confPath);
280
+ let totalConfig = {
281
+ publishInfo: { ...publishConfArgs, token },
282
+ lightBaseURL,
283
+ };
284
+ // console.log("发布配置:\n", totalConfig);
285
+ LSC(totalConfig);
286
+ } catch (error) {
287
+ console.log("主程序异常", error);
288
+ }
289
+ } else {
290
+ // 不存在配置文件,唤起交互输入
291
+ let t = "",
292
+ f = "";
293
+ if (!feLscF) {
294
+ f = "登录";
295
+ t = "lsc login";
296
+ }
297
+ if (!feConF) {
298
+ f = "离线包发布";
299
+ t = "lsc config 或 lsc init";
300
+ }
301
+ console.log(`不存在${f}配置文件,请使用命令创建:${t}`);
302
+ }
201
303
  });
202
304
 
203
305
  // 批量离线包发布.已经包名作为pkgid
@@ -205,35 +307,45 @@ program
205
307
  .command("batch")
206
308
  .alias("b")
207
309
  .action(async function () {
208
- let currPath = path.join(process.cwd(), "./dist/");
310
+ const { lightBaseURL, token } = require(lscrcPath);
311
+ const publishConfArgs = require(confPath);
312
+
313
+ let currPath = path.join(process.cwd(), publishConfArgs.pkg_dir);
209
314
  let zipLists = await getZipFileList(currPath);
210
315
  for (let i = 0; i < zipLists.length; i++) {
211
316
  const e = zipLists[i],
212
317
  s = e.split("."),
213
318
  pkgid = s[0];
214
- let lscConfig = require(confPath);
215
- let totalConfig = merge(defaultConfig, lscConfig);
319
+ let totalConfig = {
320
+ publishInfo: { ...publishConfArgs, token },
321
+ lightBaseURL,
322
+ };
216
323
  let batchConfig = merge(totalConfig, {
217
324
  publishInfo: { pkgid, pkg_zip_name: e },
218
325
  });
219
- // console.log("batchConfig", batchConfig);
326
+ // console.log("batchConfig\n", batchConfig);
220
327
  await LSC(batchConfig);
221
328
  }
222
329
  });
223
330
 
224
- async function writeConfig(configArgs) {
331
+ async function writeConfig(configArgs, path = "./lsc.config.json") {
225
332
  // 写入文件内容(如果文件不存在会创建一个文件)
226
- writeFile(
227
- "./lsc.config.json",
228
- JSON.stringify(configArgs),
229
- { flag: "w" },
230
- function (err) {
231
- if (err) {
232
- throw err;
233
- }
234
- console.log("创建配置模板成功,请打开文件进行相应修改");
333
+ writeFile(path, JSON.stringify(configArgs), { flag: "w" }, function (err) {
334
+ if (err) {
335
+ throw err;
235
336
  }
236
- );
337
+ console.log("创建配置模板成功,可根据需要进行相应修改");
338
+ });
339
+ }
340
+
341
+ // 查询会话的有效性
342
+ async function validSession(lightBaseURL, token) {
343
+ await initAxiosConfig(lightBaseURL, token);
344
+ let f = await checkSession(token);
345
+ if (!f) {
346
+ await console.log("\n会话已过期或者无效,请重新确认:", f);
347
+ }
348
+ return f;
237
349
  }
238
350
 
239
351
  program.parse(process.argv);
package/lib/core/API.js CHANGED
@@ -9,6 +9,12 @@ const { ApiList } = require("./apiUrl");
9
9
  // 存储APP的离线包
10
10
  let allOfflinePkgLists = {};
11
11
 
12
+ const initAxiosConfig = async function(lightBaseURL,token){
13
+ //全局配置
14
+ axios.defaults.baseURL = lightBaseURL;
15
+ axios.defaults.headers["cookie"] = `token=${token}`;
16
+ };
17
+
12
18
  // 添加响应拦截器
13
19
  axios.interceptors.response.use(
14
20
  function (response) {
@@ -311,4 +317,5 @@ module.exports = {
311
317
  queryOfflineTask,
312
318
  updateOfflineTask,
313
319
  syncPkgList,
320
+ initAxiosConfig
314
321
  };
package/lib/defaults.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var defaults = {
3
3
  publishInfo: {
4
- token: "XXXXX", //登录token
4
+ // token: "XXXXX", //登录token
5
5
  pkgid: "XXXXX", //离线包ID
6
6
  set_pkg_version: "1.0.1", //指定发布版本
7
7
  publish_app_arr: [3577, 3592], //发布到指定APP,默认开发版
@@ -0,0 +1,10 @@
1
+ const fs = require('fs')
2
+ const util = require('util')
3
+
4
+ const stat = util.promisify(fs.stat)
5
+
6
+ const fileExists = async (file) => stat(file)
7
+ .then((stat) => stat.isFile())
8
+ .catch(() => false)
9
+
10
+ module.exports = fileExists
package/lsc.config.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
- "publishInfo": {
3
- "token": "XXXXX",
4
- "pkgid": "XXXXX",
5
- "set_pkg_version": "1.2.9",
6
- "publish_app_arr": [3592, 3577],
7
- "android_version_scope": "7.0.7.0",
8
- "ios_version_scope": "7.0.7",
9
- "pkg_zip_name": "XXXXX.zip",
10
- "pkg_dir": "./dist/",
11
- "task_status": "2"
12
- },
13
- "lightBaseURL": "https://XXXXX.XXXXX./lightadmin/pas-api"
2
+ "token": "XXXXX",
3
+ "pkgid": "XXXXX",
4
+ "set_pkg_version": "1.2.1",
5
+ "publish_app_arr": [3592, 3577],
6
+ "android_version_scope": "7.0.7.0",
7
+ "ios_version_scope": "7.0.7",
8
+ "pkg_zip_name": "XXXXX.zip",
9
+ "pkg_dir": "./dist/",
10
+ "task_status": "2"
14
11
  }
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "inquirer": "^8.2.0",
10
10
  "qs": "^6.10.3"
11
11
  },
12
- "version": "1.0.3",
12
+ "version": "1.0.4",
13
13
  "description": "Light离线包自动发布工具",
14
14
  "main": "index.js",
15
15
  "devDependencies": {},