@taole/deploy-helper 1.2.2 → 1.2.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/index.mjs +48 -3
- package/lib/project.mjs +14 -8
- package/package.json +3 -2
package/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { Client } from 'node-scp'
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import { join, basename, dirname } from "path";
|
|
6
6
|
import { simpleGit } from 'simple-git';
|
|
7
|
+
import updateNotifier from 'update-notifier';
|
|
7
8
|
import { runPipeline, checkYunxiaoToken, triggerPipeline } from './lib/pipelineApi.mjs';
|
|
8
9
|
import { setDebug, log } from './lib/util.mjs';
|
|
9
10
|
import path from 'path';
|
|
@@ -125,8 +126,31 @@ function registerCommand(command, handler, help) {
|
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
function cmdVersion() {
|
|
130
|
+
const { version } = getPackageJson();
|
|
131
|
+
console.log(`当前版本: ${version}`);
|
|
132
|
+
console.log(`检查更新请使用命令: check-update`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function cmdCheckUpdate(notifier) {
|
|
136
|
+
const packageJson = getPackageJson();
|
|
137
|
+
console.log(`当前版本: ${packageJson.version}`);
|
|
138
|
+
try {
|
|
139
|
+
const info = await notifier.fetchInfo();
|
|
140
|
+
console.log(`最新版本: ${info.latest}`);
|
|
141
|
+
if (info.latest === info.current) {
|
|
142
|
+
console.log('已是最新版');
|
|
143
|
+
} else {
|
|
144
|
+
console.log(`建议更新: npm i -g ${packageJson.name}`);
|
|
145
|
+
}
|
|
146
|
+
} catch {
|
|
147
|
+
console.log('无法获取最新版本信息');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
128
151
|
// 注册命令
|
|
129
152
|
function doRegisterCommands() {
|
|
153
|
+
|
|
130
154
|
registerCommand("create", cmdProjectCreate, "创建项目");
|
|
131
155
|
registerCommand("publish", cmdProjectPublish, "更新项目到H5平台");
|
|
132
156
|
registerCommand("pull", cmdProjectPull, "拉取已有项目到本地");
|
|
@@ -134,6 +158,11 @@ function doRegisterCommands() {
|
|
|
134
158
|
registerCommand("whoami", cmdWhoami, "查看当前登录用户信息");
|
|
135
159
|
registerCommand("logout", cmdLogout, "退出登录");
|
|
136
160
|
registerCommand("login", cmdLogin, "登录");
|
|
161
|
+
registerCommand("version", cmdVersion, "查看当前版本(-v/--version)");
|
|
162
|
+
registerCommand("check-update", cmdCheckUpdate, "检查是否有新版本");
|
|
163
|
+
// 别名不展示在 help 列表
|
|
164
|
+
commandMap["-v"] = { handler: cmdVersion, help: "" };
|
|
165
|
+
commandMap["--version"] = { handler: cmdVersion, help: "" };
|
|
137
166
|
}
|
|
138
167
|
|
|
139
168
|
doRegisterCommands();
|
|
@@ -142,11 +171,14 @@ async function main() {
|
|
|
142
171
|
const packageJson = getPackageJson();
|
|
143
172
|
const version = packageJson.version;
|
|
144
173
|
|
|
174
|
+
const notifier = updateNotifier({
|
|
175
|
+
pkg: packageJson,
|
|
176
|
+
updateCheckInterval: 1000 * 60 * 60 * 24,
|
|
177
|
+
});
|
|
178
|
+
|
|
145
179
|
// process.argv.includes("--debug") ||
|
|
146
180
|
// 默认开启debug debug目前只是打印日志的时候额外打印时间
|
|
147
181
|
setDebug(true);
|
|
148
|
-
log(`deploy-helper v${version}`);
|
|
149
|
-
|
|
150
182
|
|
|
151
183
|
// await devTest();
|
|
152
184
|
// log(`process.argv: ${process.argv[2]} ${process.argv[3]} ${process.argv[4]}`);
|
|
@@ -161,10 +193,22 @@ async function main() {
|
|
|
161
193
|
command = "help";
|
|
162
194
|
}
|
|
163
195
|
|
|
196
|
+
const isVersionCommand = ["version", "-v", "--version"].includes(command);
|
|
197
|
+
const isCheckUpdateCommand = command === "check-update";
|
|
198
|
+
if (!isVersionCommand && !isCheckUpdateCommand) {
|
|
199
|
+
log(`deploy-helper v${version}`);
|
|
200
|
+
notifier.notify({
|
|
201
|
+
defer: false,
|
|
202
|
+
message: `发现新版本 {latestVersion}(当前 {currentVersion}),建议更新:\n{updateCommand}`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
164
206
|
if(registeredCommand){
|
|
165
207
|
const handler = registeredCommand.handler;
|
|
166
208
|
try {
|
|
167
|
-
await Promise.resolve(
|
|
209
|
+
await Promise.resolve(
|
|
210
|
+
handler === cmdCheckUpdate ? cmdCheckUpdate(notifier) : handler()
|
|
211
|
+
);
|
|
168
212
|
process.exit(0);
|
|
169
213
|
} catch (error) {
|
|
170
214
|
log(`执行命令失败: ${error}`);
|
|
@@ -186,6 +230,7 @@ async function main() {
|
|
|
186
230
|
console.log(`command: pipeline {pipelineName|pipelineId} [branch] 触发流水线{pipelineName|pipelineId}, 指定分支(可省略)`);
|
|
187
231
|
Object.keys(commandMap).forEach(command => {
|
|
188
232
|
const cmdObj = commandMap[command];
|
|
233
|
+
if (!cmdObj.help) return;
|
|
189
234
|
console.log(`command: ${command} ${cmdObj.help}`);
|
|
190
235
|
})
|
|
191
236
|
process.exit(0);
|
package/lib/project.mjs
CHANGED
|
@@ -246,12 +246,14 @@ export const cmdProjectCreate = async () => {
|
|
|
246
246
|
log(`项目创建成功, 项目目录: ${name}`);
|
|
247
247
|
git = simpleGit(projectDir);
|
|
248
248
|
const targetPackageJson = getJsonConfig(projectDir, "package.json");
|
|
249
|
-
targetPackageJson.name
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
249
|
+
if (targetPackageJson.name !== name) {
|
|
250
|
+
targetPackageJson.name = name;
|
|
251
|
+
fs.writeFileSync(
|
|
252
|
+
path.join(projectDir, "package.json"),
|
|
253
|
+
JSON.stringify(targetPackageJson, null, 2)
|
|
254
|
+
);
|
|
255
|
+
log(`项目package.json覆盖成功`);
|
|
256
|
+
}
|
|
255
257
|
const readmePath = path.join(projectDir, "README.md");
|
|
256
258
|
if (fs.existsSync(readmePath)) {
|
|
257
259
|
const readmeContent = fs.readFileSync(readmePath, "utf8");
|
|
@@ -275,8 +277,12 @@ export const cmdProjectCreate = async () => {
|
|
|
275
277
|
log(`README.md 追加访问信息成功`);
|
|
276
278
|
}
|
|
277
279
|
}
|
|
278
|
-
await git.
|
|
279
|
-
|
|
280
|
+
const status = await git.status();
|
|
281
|
+
if (!status.isClean()) {
|
|
282
|
+
await git.add(".");
|
|
283
|
+
await git.commit(`-#DH-07 feat: 项目初始化`);
|
|
284
|
+
log(`项目初始化提交成功`);
|
|
285
|
+
}
|
|
280
286
|
log(`请cd至项目目录: ${projectDir} 手动执行: npm install 安装依赖`);
|
|
281
287
|
process.exit(0);
|
|
282
288
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taole/deploy-helper",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"type": "module",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"form-data": "^4.0.5",
|
|
30
30
|
"inquirer": "^12.11.1",
|
|
31
31
|
"node-scp": "^0.0.25",
|
|
32
|
-
"simple-git": "^3.28.0"
|
|
32
|
+
"simple-git": "^3.28.0",
|
|
33
|
+
"update-notifier": "^7.3.1"
|
|
33
34
|
}
|
|
34
35
|
}
|