publish.mjs 1.3 KB

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