@lazycatcloud/lzc-cli 1.2.61 → 1.2.63
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/changelog.md +10 -0
- package/lib/appstore/login.js +124 -113
- package/lib/utils.js +1 -2
- package/package.json +1 -1
- package/template/_lpk/manifest.yml.in +1 -1
package/changelog.md
CHANGED
package/lib/appstore/login.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fetch from "node-fetch"
|
|
2
2
|
import path from "path"
|
|
3
|
+
import url from "url"
|
|
3
4
|
import logger from "loglevel"
|
|
4
5
|
import env from "../config/env.js"
|
|
5
6
|
import inquirer from "inquirer"
|
|
@@ -7,146 +8,156 @@ import inquirer from "inquirer"
|
|
|
7
8
|
const accountServerUrl = "https://account.lazycat.cloud"
|
|
8
9
|
|
|
9
10
|
function join(...params) {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
let x = ""
|
|
12
|
+
try {
|
|
13
|
+
// fix: url path join failed for windows
|
|
14
|
+
const u = new url.URL(params[0])
|
|
15
|
+
params.splice(0, 1)
|
|
16
|
+
u.pathname = path.posix.join(u.pathname, ...params)
|
|
17
|
+
x = u.toString()
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.warn(error)
|
|
20
|
+
x = path.join(...params)
|
|
21
|
+
}
|
|
22
|
+
return x
|
|
12
23
|
}
|
|
13
24
|
|
|
14
25
|
async function login(username, password) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
return fetch(join(accountServerUrl, "/api/login/signin"), {
|
|
27
|
+
method: "POST",
|
|
28
|
+
body: new URLSearchParams({
|
|
29
|
+
username: username,
|
|
30
|
+
password: password
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
.then(async (res) => {
|
|
34
|
+
let bodyText = await res.text()
|
|
35
|
+
let body = JSON.parse(bodyText)
|
|
36
|
+
if (body.success) {
|
|
37
|
+
return Promise.resolve(body.data)
|
|
38
|
+
}
|
|
39
|
+
return Promise.reject(body.message)
|
|
40
|
+
})
|
|
41
|
+
.then((data) => {
|
|
42
|
+
env.set({ token: data.token }, true)
|
|
43
|
+
logger.info("登录成功!")
|
|
44
|
+
})
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
async function isLogin() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
try {
|
|
49
|
+
let token = env.get("token")
|
|
50
|
+
if (!token) {
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
return fetch(join(accountServerUrl, "/api/user/current"), {
|
|
54
|
+
method: "GET",
|
|
55
|
+
headers: {
|
|
56
|
+
"X-User-Token": token
|
|
57
|
+
}
|
|
58
|
+
}).then(async (res) => {
|
|
59
|
+
let bodyText = await res.text()
|
|
60
|
+
let body = JSON.parse(bodyText)
|
|
61
|
+
if (body.success) {
|
|
62
|
+
return token
|
|
63
|
+
}
|
|
64
|
+
logger.debug(body.message)
|
|
65
|
+
return false
|
|
66
|
+
})
|
|
67
|
+
} catch (e) {
|
|
68
|
+
logger.trace(e)
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
60
71
|
}
|
|
61
72
|
|
|
62
73
|
async function askUserInfo() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
const noEmpty = (value) => value != ""
|
|
75
|
+
return await inquirer.prompt([
|
|
76
|
+
{
|
|
77
|
+
type: "input",
|
|
78
|
+
name: "username",
|
|
79
|
+
message: "请输入登录用户名",
|
|
80
|
+
validate: noEmpty
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: "password",
|
|
84
|
+
mask: "*",
|
|
85
|
+
name: "password",
|
|
86
|
+
message: "请输入登录密码",
|
|
87
|
+
validate: noEmpty
|
|
88
|
+
}
|
|
89
|
+
])
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
async function interactiveLogin() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
try {
|
|
94
|
+
let info = await askUserInfo()
|
|
95
|
+
await login(info.username, info.password)
|
|
96
|
+
} catch (e) {
|
|
97
|
+
logger.debug("login error: ", e)
|
|
98
|
+
logger.error("帐号或者密码错误,请重新输入!")
|
|
99
|
+
return interactiveLogin()
|
|
100
|
+
}
|
|
90
101
|
}
|
|
91
102
|
|
|
92
103
|
function tipsFirstLogin() {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
let token = env.get("token")
|
|
105
|
+
if (!token) {
|
|
106
|
+
// 还没登录过的用户提示用户前往 https://developer.lazycat.cloud/manage 注册开发者账号
|
|
107
|
+
logger.info("请登录懒猫微服社区账号,账号注册以及开发者权限申请地址: https://developer.lazycat.cloud/manage")
|
|
108
|
+
}
|
|
98
109
|
}
|
|
99
110
|
|
|
100
111
|
export async function reLogin() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
112
|
+
let token = await isLogin()
|
|
113
|
+
if (token) {
|
|
114
|
+
const questions = [
|
|
115
|
+
{
|
|
116
|
+
name: "relogin",
|
|
117
|
+
type: "input",
|
|
118
|
+
default: "n",
|
|
119
|
+
message: "检测到已经登录,是否重新登录(y/n):"
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
const answers = await inquirer.prompt(questions)
|
|
123
|
+
if (answers.relogin.toLowerCase() === "n") {
|
|
124
|
+
logger.info(`token: ${token}`)
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
tipsFirstLogin()
|
|
129
|
+
}
|
|
130
|
+
await interactiveLogin()
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
export async function autoLogin() {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
let token = await isLogin()
|
|
135
|
+
if (token) {
|
|
136
|
+
logger.debug("appstore 已经登录")
|
|
137
|
+
return
|
|
138
|
+
} else {
|
|
139
|
+
tipsFirstLogin()
|
|
140
|
+
}
|
|
130
141
|
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
logger.debug("token错误,尝试自动登录")
|
|
143
|
+
await interactiveLogin()
|
|
133
144
|
}
|
|
134
145
|
|
|
135
146
|
export async function request(url, options = {}) {
|
|
136
|
-
|
|
147
|
+
await autoLogin()
|
|
137
148
|
|
|
138
|
-
|
|
149
|
+
const token = env.get("token")
|
|
139
150
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
let headers = {
|
|
152
|
+
"X-User-Token": token,
|
|
153
|
+
cookie: `userToken=${token}`
|
|
154
|
+
}
|
|
155
|
+
if (options.headers) {
|
|
156
|
+
headers = Object.assign({}, options.headers, headers)
|
|
157
|
+
}
|
|
147
158
|
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
options = Object.assign({}, options, { headers })
|
|
160
|
+
logger.trace(`fetch ${url}`, options)
|
|
150
161
|
|
|
151
|
-
|
|
162
|
+
return fetch(url, options)
|
|
152
163
|
}
|
package/lib/utils.js
CHANGED
|
@@ -384,9 +384,8 @@ export function isValidAppId(appId) {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
export function isValidPackageName(packageName) {
|
|
387
|
-
// 暂时去掉 - 的支持
|
|
388
387
|
const regex = new RegExp(
|
|
389
|
-
"^[a-z][a-z0-9]*([-][a-z0-9]+)*(
|
|
388
|
+
"^[a-z][a-z0-9]*([-][a-z0-9]+)*(?:\\.[a-z][a-z0-9]*([-][a-z0-9]+)*)*$"
|
|
390
389
|
)
|
|
391
390
|
return regex.test(packageName)
|
|
392
391
|
}
|
package/package.json
CHANGED