@lazycatcloud/lzc-cli 1.2.42 → 1.2.43
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 +42 -0
- package/lib/appstore/publish.js +139 -1
- package/lib/utils.js +4 -0
- package/package.json +3 -2
- package/scripts/cli.js +2 -1
package/changelog.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# 1.2.43
|
|
2
|
+
|
|
3
|
+
1. 支持通过命令行注册应用,新上架的应用不再需要通过界面配置
|
|
4
|
+
|
|
5
|
+
# 1.2.42
|
|
6
|
+
|
|
7
|
+
1. 限制 subdomain 为空时,构建和安装失败
|
|
8
|
+
2. 修复创建的模板中没有带上 .gitingore 文件
|
|
9
|
+
|
|
10
|
+
# 1.2.41
|
|
11
|
+
|
|
12
|
+
1. 使用 rsync daemon 修复 Windows 系统下 rsync 无法使用本机原生 ssh 传输
|
|
13
|
+
|
|
14
|
+
# 1.2.39
|
|
15
|
+
|
|
16
|
+
1. 修复 Windows 系统下,无法构建和安装问题
|
|
17
|
+
|
|
18
|
+
# 1.2.38
|
|
19
|
+
|
|
20
|
+
1. 修复 Windows 系统下,buildscript 脚本执行错误,导致无法构建
|
|
21
|
+
|
|
22
|
+
# 1.2.37
|
|
23
|
+
|
|
24
|
+
1. 修复 Windows 系统下,构建包时获取 LocalIP 错误
|
|
25
|
+
|
|
26
|
+
# 1.2.34
|
|
27
|
+
|
|
28
|
+
1. devshell 模式下,默认打开后台常驻
|
|
29
|
+
|
|
30
|
+
# 1.2.29
|
|
31
|
+
|
|
32
|
+
1. 修复开发者第一次devshelll需要填写密码,需要安装最新开发者工具(0.1.6)
|
|
33
|
+
2. 调整文案,移除不必要的日志
|
|
34
|
+
|
|
35
|
+
# 1.2.28
|
|
36
|
+
|
|
37
|
+
1. 简化创建项目流程
|
|
38
|
+
2. 支持自动请求生成安卓所需要apk包
|
|
39
|
+
|
|
40
|
+
# 1.2.27
|
|
41
|
+
|
|
42
|
+
1. 修复第一次使用开发者 `dns` 生效慢的问题
|
package/lib/appstore/publish.js
CHANGED
|
@@ -4,7 +4,13 @@ import FormData from "form-data"
|
|
|
4
4
|
import fs from "node:fs"
|
|
5
5
|
import inquirer from "inquirer"
|
|
6
6
|
import path from "node:path"
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
isFileExist,
|
|
9
|
+
isPngWithFile,
|
|
10
|
+
unzipSync,
|
|
11
|
+
loadFromYaml,
|
|
12
|
+
isValidPackageName
|
|
13
|
+
} from "../utils.js"
|
|
8
14
|
|
|
9
15
|
async function askChangeLog() {
|
|
10
16
|
const noEmpty = (value) => value != ""
|
|
@@ -18,6 +24,112 @@ async function askChangeLog() {
|
|
|
18
24
|
])
|
|
19
25
|
}
|
|
20
26
|
|
|
27
|
+
async function getCategories(baseUrl) {
|
|
28
|
+
const response = await request(`${baseUrl}/categories`, { method: "GET" })
|
|
29
|
+
const data = await response.json()
|
|
30
|
+
return data
|
|
31
|
+
.sort((a, b) => a.index - b.index)
|
|
32
|
+
.map((cat) => ({
|
|
33
|
+
name: cat.name,
|
|
34
|
+
value: cat.name
|
|
35
|
+
}))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function askPublishAppInfo(baseUrl, manifest) {
|
|
39
|
+
// 获取分类列表
|
|
40
|
+
const categories = await getCategories(baseUrl)
|
|
41
|
+
|
|
42
|
+
const questions = [
|
|
43
|
+
{
|
|
44
|
+
type: "input",
|
|
45
|
+
name: "name",
|
|
46
|
+
message: "请输入应用名称:",
|
|
47
|
+
default: manifest["name"],
|
|
48
|
+
validate: (input) => (input.trim() !== "" ? true : "应用名称不能为空")
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: "input",
|
|
52
|
+
name: "appId",
|
|
53
|
+
message: "请输入应用ID:",
|
|
54
|
+
default: manifest["package"],
|
|
55
|
+
validate: (input) =>
|
|
56
|
+
isValidPackageName(input) ? true : "应用ID不符合规范"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: "input",
|
|
60
|
+
name: "description",
|
|
61
|
+
message: "请输入应用描述:",
|
|
62
|
+
default: manifest["description"] || ""
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "input",
|
|
66
|
+
name: "brief",
|
|
67
|
+
message: "请输入应用简介(简单的概述):",
|
|
68
|
+
default: ""
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: "checkbox",
|
|
72
|
+
name: "category",
|
|
73
|
+
message: "请选择应用分类:",
|
|
74
|
+
choices: categories,
|
|
75
|
+
validate: (input) => (input.length > 0 ? true : "请至少选择一个分类")
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: "input",
|
|
79
|
+
name: "keywords",
|
|
80
|
+
message: "请输入关键词(用逗号分隔):",
|
|
81
|
+
default: ""
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: "input",
|
|
85
|
+
name: "source",
|
|
86
|
+
message: "请输入应用来源:",
|
|
87
|
+
default: manifest["homepage"] || ""
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: "input",
|
|
91
|
+
name: "author",
|
|
92
|
+
message: "请输入作者名称:",
|
|
93
|
+
default: manifest["author"] || ""
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
const answers = await inquirer.prompt(questions)
|
|
98
|
+
return answers
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function askWhetherCreateLPK(baseUrl, manifest) {
|
|
102
|
+
const answers = await inquirer.prompt([
|
|
103
|
+
{
|
|
104
|
+
name: "continue",
|
|
105
|
+
type: "input",
|
|
106
|
+
message:
|
|
107
|
+
"检测到您当前的应用,还没有在懒猫微服中创建,是否使用当前的安装包中的信息进行创建? [y/n]",
|
|
108
|
+
default: "y"
|
|
109
|
+
}
|
|
110
|
+
])
|
|
111
|
+
if (answers.continue.toLowerCase() === "y") {
|
|
112
|
+
const appInfo = await askPublishAppInfo(baseUrl, manifest)
|
|
113
|
+
const crateAppRes = await request(`${baseUrl}/apps`, {
|
|
114
|
+
method: "POST",
|
|
115
|
+
body: JSON.stringify(appInfo)
|
|
116
|
+
})
|
|
117
|
+
logger.debug("create app res: ", await crateAppRes.text())
|
|
118
|
+
logger.info(`创建 ${manifest["package"]} 应用成功!`)
|
|
119
|
+
} else {
|
|
120
|
+
logger.info(`当前想发布的应用没有在 '懒猫微服的开发者中心' 创建,请按照以下步骤创建:
|
|
121
|
+
|
|
122
|
+
1. 浏览器打开 https://developer.lazycat.cloud/manage
|
|
123
|
+
2. 登录您的开发者帐号
|
|
124
|
+
3. 登录成功后,您可以查看到您帐号中的应用,同时您也可以对您的应用进行管理
|
|
125
|
+
4. 点击 '新增',根据您的应用信息进行填写
|
|
126
|
+
5. 填写完成后,点击创建即可
|
|
127
|
+
6. 创建成功后,您可以通过 'lzc-cli appstore publish' 来发布应用了
|
|
128
|
+
`)
|
|
129
|
+
process.exit(1)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
21
133
|
export class Publish {
|
|
22
134
|
constructor(baseUrl = "https://developer.lazycat.cloud/api/v2/developer") {
|
|
23
135
|
this.baseUrl = baseUrl
|
|
@@ -53,6 +165,27 @@ export class Publish {
|
|
|
53
165
|
}
|
|
54
166
|
}
|
|
55
167
|
|
|
168
|
+
async checkAppIdExist(pkgPath) {
|
|
169
|
+
const tempDir = fs.mkdtempSync(".lzc-cli-publish")
|
|
170
|
+
try {
|
|
171
|
+
unzipSync(pkgPath, tempDir, ["manifest.yml"])
|
|
172
|
+
const manifest = loadFromYaml(path.join(tempDir, "manifest.yml"))
|
|
173
|
+
const checkUrl = this.baseUrl + `/apps/${manifest["package"]}/check_exist`
|
|
174
|
+
const res = await request(checkUrl, { method: "GET" })
|
|
175
|
+
if (res.status >= 400) {
|
|
176
|
+
logger.error("检测应用是否存在出错, 错误状态码为: ", res.status)
|
|
177
|
+
logger.error(await res.text())
|
|
178
|
+
return { manifest, appIdExisted: true } // 默认认为已经存在
|
|
179
|
+
} else {
|
|
180
|
+
const text = (await res.text()).trim()
|
|
181
|
+
logger.debug(`check appId[${manifest["package"]}] exist: ${text}`)
|
|
182
|
+
return { manifest, appIdExisted: text == "true" }
|
|
183
|
+
}
|
|
184
|
+
} finally {
|
|
185
|
+
fs.rmSync(tempDir, { recursive: true })
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
56
189
|
/**
|
|
57
190
|
* @param {string} pkgPath
|
|
58
191
|
* @param {string} changelog
|
|
@@ -60,6 +193,11 @@ export class Publish {
|
|
|
60
193
|
async publish(pkgPath, changelog) {
|
|
61
194
|
if (!Publish.preCheck(pkgPath)) return
|
|
62
195
|
|
|
196
|
+
const { manifest, appIdExisted } = await this.checkAppIdExist(pkgPath)
|
|
197
|
+
if (!appIdExisted) {
|
|
198
|
+
await askWhetherCreateLPK(this.baseUrl, manifest)
|
|
199
|
+
}
|
|
200
|
+
|
|
63
201
|
await autoLogin()
|
|
64
202
|
|
|
65
203
|
if (!changelog) {
|
package/lib/utils.js
CHANGED
|
@@ -475,6 +475,10 @@ export async function resolveDomain(domain) {
|
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
export function unzipSync(zipPath, destPath, entries = []) {
|
|
478
|
+
if (!isFileExist(zipPath)) {
|
|
479
|
+
throw `${zipPath} 找不到该文件`
|
|
480
|
+
}
|
|
481
|
+
|
|
478
482
|
// 确保目标目录存在
|
|
479
483
|
fs.mkdirSync(destPath, { recursive: true })
|
|
480
484
|
// 创建 zip 实例
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lazycatcloud/lzc-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.43",
|
|
4
4
|
"description": "lazycat cloud developer kit",
|
|
5
5
|
"files": [
|
|
6
6
|
"template",
|
|
7
7
|
"scripts",
|
|
8
|
-
"lib"
|
|
8
|
+
"lib",
|
|
9
|
+
"changelog.md"
|
|
9
10
|
],
|
|
10
11
|
"bin": {
|
|
11
12
|
"lzc-cli": "./scripts/cli.js"
|
package/scripts/cli.js
CHANGED
|
@@ -19,6 +19,7 @@ import env from "../lib/env.js"
|
|
|
19
19
|
// logger level middleware
|
|
20
20
|
const logLevelOriginalFactory = logger.methodFactory
|
|
21
21
|
logger.methodFactory = function (methodName, logLevel, loggerName) {
|
|
22
|
+
let debug = logLevel <= logger.levels.DEBUG
|
|
22
23
|
let rawMethod = logLevelOriginalFactory(methodName, logLevel, loggerName)
|
|
23
24
|
return function (...args) {
|
|
24
25
|
let color = (msg) => chalk.gray
|
|
@@ -41,7 +42,7 @@ logger.methodFactory = function (methodName, logLevel, loggerName) {
|
|
|
41
42
|
}
|
|
42
43
|
const prefix = loggerName ?? methodName
|
|
43
44
|
rawMethod(
|
|
44
|
-
`[${prefix}] ` +
|
|
45
|
+
(debug ? `[${prefix}] ` : "") +
|
|
45
46
|
args
|
|
46
47
|
.map((a) => {
|
|
47
48
|
let res = a
|