|
@@ -2,6 +2,8 @@ import { writeFileSync, existsSync } from "fs";
|
|
|
import { execSync } from "child_process";
|
|
|
import moment from "moment";
|
|
|
import packageJson from "./package.json" assert { type: "json" };
|
|
|
+import * as readline from "node:readline/promises";
|
|
|
+import { stdin as input, stdout as output } from "node:process";
|
|
|
|
|
|
console.log("> prebuild");
|
|
|
console.log("> prebuild create .env.*.local");
|
|
@@ -15,6 +17,29 @@ console.log(" 构建日期为 " + buildDate);
|
|
|
const revision = execSync("git rev-parse HEAD").toString().trim().slice(0, 7);
|
|
|
console.log(" 当前的git版本为 " + revision);
|
|
|
|
|
|
+const branchName = execSync("git branch --show-current").toString().trim();
|
|
|
+const branchNum = branchName.match(/.*(\d+\.\d+.\d+)$/)[1];
|
|
|
+if (branchNum !== packageJson.version) {
|
|
|
+ const rl = readline.createInterface({ input, output });
|
|
|
+
|
|
|
+ /** @type string */
|
|
|
+ const answer = await rl.question(
|
|
|
+ "package.json的版本号与git分支不一致,是否停止构建?(Y/N)"
|
|
|
+ );
|
|
|
+
|
|
|
+ console.log(`${answer}`);
|
|
|
+
|
|
|
+ rl.close();
|
|
|
+ const upAnswer = answer.toUpperCase();
|
|
|
+ if (upAnswer === "Y") {
|
|
|
+ process.exit(1);
|
|
|
+ } else if (upAnswer === "N") {
|
|
|
+ console.log("继续构建");
|
|
|
+ } else {
|
|
|
+ console.error("无效输入");
|
|
|
+ process.exit(1);
|
|
|
+ }
|
|
|
+}
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
|
writeFileSync(
|
|
|
".env.production.local",
|