prebuild.mjs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { writeFileSync, existsSync } from "fs";
  2. import { execSync } from "child_process";
  3. import moment from "moment";
  4. import packageJson from "./package.json" assert { type: "json" };
  5. console.log("> prebuild");
  6. console.log("> prebuild create .env.*.local");
  7. // const packageJson = require("./package.json");
  8. const buildDate = moment().format("YYYY-MM-DD HH:mm:ss");
  9. console.log(" 构建日期为 " + buildDate);
  10. // eslint-disable-next-line @typescript-eslint/no-unsafe-call
  11. const revision = execSync("git rev-parse HEAD").toString().trim().slice(0, 7);
  12. console.log(" 当前的git版本为 " + revision);
  13. // eslint-disable-next-line @typescript-eslint/no-unsafe-call
  14. writeFileSync(
  15. ".env.production.local",
  16. `VITE_FE_VERSION=${packageJson.version}
  17. VITE_BUILD_DATE=${buildDate}
  18. VITE_GIT_REPO_VERSION=${revision}
  19. `
  20. );
  21. // 如果不存在则创建,对真正的构建无影响
  22. if (!existsSync("./src/devLoginParams.ts")) {
  23. writeFileSync(
  24. "./src/devLoginParams.ts",
  25. `
  26. export const isAdmin = false;
  27. export let forceChange = false;
  28. forceChange = true;
  29. // 很多任务,选分组2
  30. export const loginName = "";
  31. export const password = "";
  32. export const examId = "";
  33. export const markerId = "";
  34. `
  35. );
  36. }
  37. console.log();