publish.mjs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import fs from "fs-extra";
  2. import { createRequire } from "module";
  3. import { execSync } from "child_process";
  4. import { resolveUpdateLog } from "./updatelog.mjs";
  5. const require = createRequire(import.meta.url);
  6. // publish
  7. async function resolvePublish() {
  8. const flag = process.argv[2] ?? "patch";
  9. const packageJson = require("../package.json");
  10. const tauriJson = require("../src-tauri/tauri.conf.json");
  11. let [a, b, c] = packageJson.version.split(".").map(Number);
  12. if (flag === "major") {
  13. a += 1;
  14. b = 0;
  15. c = 0;
  16. } else if (flag === "minor") {
  17. b += 1;
  18. c = 0;
  19. } else if (flag === "patch") {
  20. c += 1;
  21. } else throw new Error(`invalid flag "${flag}"`);
  22. const nextVersion = `${a}.${b}.${c}`;
  23. packageJson.version = nextVersion;
  24. tauriJson.package.version = nextVersion;
  25. // 发布更新前先写更新日志
  26. const nextTag = `v${nextVersion}`;
  27. await resolveUpdateLog(nextTag);
  28. await fs.writeFile(
  29. "./package.json",
  30. JSON.stringify(packageJson, undefined, 2)
  31. );
  32. await fs.writeFile(
  33. "./src-tauri/tauri.conf.json",
  34. JSON.stringify(tauriJson, undefined, 2)
  35. );
  36. execSync("git add ./package.json");
  37. execSync("git add ./src-tauri/tauri.conf.json");
  38. execSync(`git commit -m "v${nextVersion}"`);
  39. execSync(`git tag -a v${nextVersion} -m "v${nextVersion}"`);
  40. execSync(`git push`);
  41. execSync(`git push origin v${nextVersion}`);
  42. console.log(`Publish Successfully...`);
  43. }
  44. resolvePublish();