upload-miniprogram 0.0.23 → 1.0.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 +12 -13
- package/bin/upload-miniprogram.js +11 -8
- package/lib/index.js +4 -2
- package/package.json +2 -3
- package/upload-miniprogram.js +0 -191
package/README.md
CHANGED
|
@@ -29,28 +29,26 @@ npm install --save-dev upload-miniprogram
|
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
31
|
# 基本用法
|
|
32
|
-
upload-miniprogram --appid your-appid --project-path ./dist --version
|
|
32
|
+
upload-miniprogram --appid your-appid --project-path ./dist --app-version V0.0.1 --env development --desc "功能更新"
|
|
33
33
|
|
|
34
34
|
# 完整参数
|
|
35
35
|
upload-miniprogram \
|
|
36
36
|
--appid your-appid \
|
|
37
37
|
--project-path ./dist \
|
|
38
|
-
--
|
|
39
|
-
--
|
|
40
|
-
--
|
|
41
|
-
--env production
|
|
38
|
+
--env development \
|
|
39
|
+
--app-version V0.0.1 \
|
|
40
|
+
--desc "功能更新"
|
|
42
41
|
```
|
|
43
42
|
|
|
44
43
|
### 参数说明
|
|
45
44
|
|
|
46
|
-
| 参数 | 缩写 | 必填 | 说明 |
|
|
47
|
-
|
|
48
|
-
| --appid | -a | 是 | 小程序ID
|
|
49
|
-
| --project-path | -p | 是 | 小程序项目打包后的代码路径
|
|
50
|
-
| --
|
|
51
|
-
| --
|
|
52
|
-
| --
|
|
53
|
-
| --env | -e | 否 | 环境变量 (development\|staging\|uat\|production) |
|
|
45
|
+
| 参数 | 缩写 | 必填 | 说明 | 参数修改说明|
|
|
46
|
+
|------|------|------|------|------|
|
|
47
|
+
| --appid | -a | 是 | 小程序ID |每个项目固定1-2个,可能跟环境不同,确定后不需再修改|
|
|
48
|
+
| --project-path | -p | 是 | 小程序项目打包后的代码路径 |一般是 ./dist 或 ./dist/weapp 每个项目固定1个路径,确定后不需再修改|
|
|
49
|
+
| --env | -e | 否 | 环境变量 (development\|staging\|uat\|production) | 按每个Jerkins链接的环境设置|
|
|
50
|
+
| --app-version | -V | 是 | 上传至小程序的版本号 |每次构建时需要重新填写|
|
|
51
|
+
| --desc | -d | 否 | 版本描述 |每次构建时需要重新填写|
|
|
54
52
|
|
|
55
53
|
### 编程方式
|
|
56
54
|
|
|
@@ -106,6 +104,7 @@ ${WORKSPACE}/../mp-ci-upload-key/private.{appid}.key
|
|
|
106
104
|
|
|
107
105
|
|
|
108
106
|
|
|
107
|
+
|
|
109
108
|
## 许可证
|
|
110
109
|
|
|
111
110
|
MIT
|
|
@@ -21,11 +21,14 @@ console.log('options', options);
|
|
|
21
21
|
if (options.env) {
|
|
22
22
|
process.env.NODE_ENV = options.env;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
uploadMiniprogram({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
24
|
+
if (options.appVersion && options.appid && options.projectPath && options.env) {
|
|
25
|
+
uploadMiniprogram({
|
|
26
|
+
appid: options.appid,
|
|
27
|
+
projectPath: options.projectPath,
|
|
28
|
+
version: options.appVersion,
|
|
29
|
+
desc: options.desc,
|
|
30
|
+
user: options.user
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
console.error("执行失败: 缺少必要参数 appid, project-path(projectPath), app-version(appVersion), env(value in development|staging|uat|production)");
|
|
34
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
// https://www.npmjs.com/package/miniprogram-ci
|
|
2
|
+
|
|
1
3
|
const ci = require("miniprogram-ci");
|
|
2
4
|
const { execSync } = require("child_process");
|
|
3
|
-
const inquirer = require("inquirer");
|
|
5
|
+
// const inquirer = require("inquirer");
|
|
4
6
|
|
|
5
7
|
class UploadMiniprogram {
|
|
6
8
|
constructor(options = {}) {
|
|
@@ -163,7 +165,7 @@ class UploadMiniprogram {
|
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
if (questions.length > 0) {
|
|
166
|
-
const answers = await inquirer.prompt(questions);
|
|
168
|
+
const answers = []; //await inquirer.prompt(questions); // TODO: 删掉inquir试试
|
|
167
169
|
this.options = { ...this.options, ...answers };
|
|
168
170
|
}
|
|
169
171
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "upload-miniprogram",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "chatlabs 集成 微信小程序CI/CD上传工具,支持自动上传代码和生成预览二维码",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,11 +22,10 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"miniprogram-ci": "^1.9.0",
|
|
25
|
-
"inquirer": "^8.2.4",
|
|
26
25
|
"commander": "^9.4.1"
|
|
27
26
|
},
|
|
28
27
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
28
|
+
"node": ">=14.8.0"
|
|
30
29
|
},
|
|
31
30
|
"repository": {
|
|
32
31
|
"type": "git",
|
package/upload-miniprogram.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-commonjs */
|
|
2
|
-
// https://www.npmjs.com/package/miniprogram-ci
|
|
3
|
-
|
|
4
|
-
const ci = require("miniprogram-ci");
|
|
5
|
-
const { execSync } = require("child_process");
|
|
6
|
-
const inquirer = require("inquirer");
|
|
7
|
-
|
|
8
|
-
const WORKSPACE = process.env.WORKSPACE;
|
|
9
|
-
|
|
10
|
-
let APP_ID = ""; // 小程序ID
|
|
11
|
-
let PROJECT_PATH = ""; // 小程序项目打包后的代码路径
|
|
12
|
-
|
|
13
|
-
const PRIVATE_KEY_PATH_JENKINS =
|
|
14
|
-
"${WORKSPACE}/../mp-ci-upload-key/private.${APP_ID}.key".replace(
|
|
15
|
-
"${WORKSPACE}",
|
|
16
|
-
WORKSPACE
|
|
17
|
-
); // 小程序私钥路径(需要存在Jerkin服务器,不要存在项目文件里)
|
|
18
|
-
const PREVIEW_CODE_PATH_JENKINS = "${WORKSPACE}/../mp-ci-qrcode-back".replace(
|
|
19
|
-
"${WORKSPACE}",
|
|
20
|
-
WORKSPACE
|
|
21
|
-
); // 小程序预览Code的路径
|
|
22
|
-
const PRIVATE_KEY_PATH_LOCAL = "./scripts/private.${APP_ID}.key"; // 小程序私钥路径(需要存在Jerkin服务器,不要存在项目文件里,如不需要本地执行,可以忽略该配置)
|
|
23
|
-
const PREVIEW_CODE_PATH_LOCAL = "./scripts/previewCode"; // 本地预览二维码路径(本地运行命令时才会用到,也要配置本地的IP,如不需要本地执行,可以忽略该配置)
|
|
24
|
-
const PREVIEW_CODE_FILE_NAME = "code.jpg"; // 预览二维码文件名 "code-${version}.jpg"
|
|
25
|
-
|
|
26
|
-
const ENV = process.env.NODE_ENV;
|
|
27
|
-
const ENV_MAP = {
|
|
28
|
-
development: { v: ".dev", desc: "【Dev环境】", robot: 1 },
|
|
29
|
-
staging: { v: ".staging", desc: "【Staging环境】", robot: 2 },
|
|
30
|
-
uat: { v: ".uat", desc: "【Uat环境】", robot: 3 },
|
|
31
|
-
production: { v: "", desc: "【正式环境】", robot: 5 },
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const env_argv = process.argv;
|
|
35
|
-
console.log("argvs", env_argv);
|
|
36
|
-
|
|
37
|
-
let v_in_argv, d_in_argv, u_in_argv;
|
|
38
|
-
|
|
39
|
-
env_argv.forEach((item) => {
|
|
40
|
-
if (item.includes("version")) {
|
|
41
|
-
v_in_argv = item.split("=")[1];
|
|
42
|
-
}
|
|
43
|
-
if (item.includes("desc")) {
|
|
44
|
-
d_in_argv = item.split("=")[1];
|
|
45
|
-
}
|
|
46
|
-
if (item.includes("user")) {
|
|
47
|
-
u_in_argv = item.split("=")[1];
|
|
48
|
-
}
|
|
49
|
-
if (item.includes("appid")) {
|
|
50
|
-
APP_ID = item.split("=")[1];
|
|
51
|
-
}
|
|
52
|
-
if (item.includes("project-path")) {
|
|
53
|
-
PROJECT_PATH = item.split("=")[1];
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// 获取 Git 邮箱
|
|
58
|
-
function getGitEmail() {
|
|
59
|
-
try {
|
|
60
|
-
return execSync("git config --global user.email", {
|
|
61
|
-
encoding: "utf8",
|
|
62
|
-
}).trim();
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error("无法获取 Git 邮箱:", error.message);
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const executeUploadMPCode = async () => {
|
|
70
|
-
const gitEmail = getGitEmail();
|
|
71
|
-
const JerkinsURL = process.env.BUILD_URL ?? "";
|
|
72
|
-
const isJerkin = Boolean(JerkinsURL);
|
|
73
|
-
|
|
74
|
-
const version = `${v_in_argv}${ENV_MAP[ENV].v}`;
|
|
75
|
-
const desc = `${d_in_argv || ""}`;
|
|
76
|
-
const fullDesc = `${ENV_MAP[ENV].desc} ${desc} upload by ${
|
|
77
|
-
gitEmail || u_in_argv || "Jenkins "
|
|
78
|
-
} ${JerkinsURL ? `from JerkinsURL: ${JerkinsURL}` : ""} `;
|
|
79
|
-
|
|
80
|
-
const project = new ci.Project({
|
|
81
|
-
appid: APP_ID,
|
|
82
|
-
type: "miniProgram",
|
|
83
|
-
projectPath: PROJECT_PATH,
|
|
84
|
-
privateKeyPath: isJerkin
|
|
85
|
-
? PRIVATE_KEY_PATH_JENKINS.replace("${APP_ID}", APP_ID)
|
|
86
|
-
: PRIVATE_KEY_PATH_LOCAL.replace("${APP_ID}", APP_ID),
|
|
87
|
-
ignores: ["node_modules/**/*"],
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// 上传小程序
|
|
91
|
-
|
|
92
|
-
console.log("========= 运行上传小程序函数 ==========");
|
|
93
|
-
const uploadResult = await ci.upload({
|
|
94
|
-
project,
|
|
95
|
-
robot: ENV_MAP[ENV].robot,
|
|
96
|
-
version: version,
|
|
97
|
-
desc: fullDesc,
|
|
98
|
-
setting: {
|
|
99
|
-
useProjectConfig: true,
|
|
100
|
-
},
|
|
101
|
-
// onProgressUpdate: console.log,
|
|
102
|
-
});
|
|
103
|
-
console.log("上传小程序结果 uploadResult: ", uploadResult);
|
|
104
|
-
|
|
105
|
-
console.log("========= 运行预览并生成二维码函数 ==========");
|
|
106
|
-
const qrCodePath = `${
|
|
107
|
-
isJerkin ? PREVIEW_CODE_PATH_JENKINS : PREVIEW_CODE_PATH_LOCAL
|
|
108
|
-
}/${PREVIEW_CODE_FILE_NAME.replace("${version}", version)}`;
|
|
109
|
-
const previewResult = await ci.preview({
|
|
110
|
-
project,
|
|
111
|
-
robot: ENV_MAP[ENV].robot,
|
|
112
|
-
desc: `${version} ${fullDesc}`,
|
|
113
|
-
setting: {
|
|
114
|
-
useProjectConfig: true,
|
|
115
|
-
},
|
|
116
|
-
qrcodeFormat: "image",
|
|
117
|
-
qrcodeOutputDest: qrCodePath, // 服务器链接,可以定期清除,这个是必填字段
|
|
118
|
-
// onProgressUpdate: console.log,
|
|
119
|
-
});
|
|
120
|
-
console.log(
|
|
121
|
-
`二维码路径:${qrCodePath} (可能不生效或无权限,建议直接从小程序助手进入查看)`
|
|
122
|
-
);
|
|
123
|
-
console.log("预览并生成二维码结果 previewResult: ", previewResult);
|
|
124
|
-
|
|
125
|
-
console.log("========= 小程序上传结果 ==========");
|
|
126
|
-
console.log(`由机器人${ENV_MAP[ENV].robot}上传`);
|
|
127
|
-
console.log(`版本:${version}`);
|
|
128
|
-
console.log(`描述: ${fullDesc}`);
|
|
129
|
-
console.log("============ end ==============");
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
(async () => {
|
|
133
|
-
if (!ENV_MAP[ENV]) {
|
|
134
|
-
console.error("env is not supported: ", ENV);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (!v_in_argv || !APP_ID || !PROJECT_PATH) {
|
|
139
|
-
console.error("version is required");
|
|
140
|
-
|
|
141
|
-
const questions = [];
|
|
142
|
-
|
|
143
|
-
if (!APP_ID) {
|
|
144
|
-
questions.push({
|
|
145
|
-
type: "input",
|
|
146
|
-
name: "appid",
|
|
147
|
-
message: "请输入小程序ID",
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (!PROJECT_PATH) {
|
|
152
|
-
questions.push({
|
|
153
|
-
type: "input",
|
|
154
|
-
name: "projectPath",
|
|
155
|
-
message: "请输入小程序项目打包后的代码路径",
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (!v_in_argv) {
|
|
160
|
-
questions.push({
|
|
161
|
-
type: "input",
|
|
162
|
-
name: "version",
|
|
163
|
-
message: "请输入版本号",
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
if (!d_in_argv) {
|
|
167
|
-
questions.push({
|
|
168
|
-
type: "input",
|
|
169
|
-
name: "desc",
|
|
170
|
-
message: "请输入版本描述",
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
inquirer.prompt(questions).then(function (answers) {
|
|
175
|
-
let { version = "", desc = "", appid = "", projectPath = "" } = answers;
|
|
176
|
-
|
|
177
|
-
v_in_argv = version;
|
|
178
|
-
if (desc) d_in_argv = desc;
|
|
179
|
-
if (appid) APP_ID = appid;
|
|
180
|
-
if (projectPath) PROJECT_PATH = projectPath;
|
|
181
|
-
if (version) {
|
|
182
|
-
executeUploadMPCode();
|
|
183
|
-
} else {
|
|
184
|
-
console.log("版本号不能为空");
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
return;
|
|
188
|
-
} else {
|
|
189
|
-
executeUploadMPCode();
|
|
190
|
-
}
|
|
191
|
-
})();
|