publish.mjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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") a += 1;
  11. else if (flag === "minor") b += 1;
  12. else if (flag === "patch") c += 1;
  13. else throw new Error(`invalid flag "${flag}"`);
  14. const nextVersion = `${a}.${b}.${c}`;
  15. packageJson.version = nextVersion;
  16. tauriJson.package.version = nextVersion;
  17. await fs.writeFile(
  18. "./package.json",
  19. JSON.stringify(packageJson, undefined, 2)
  20. );
  21. await fs.writeFile(
  22. "./src-tauri/tauri.conf.json",
  23. JSON.stringify(tauriJson, undefined, 2)
  24. );
  25. execSync("git add ./package.json");
  26. execSync("git add ./src-tauri/tauri.conf.json");
  27. execSync(`git commit -m "v${nextVersion}"`);
  28. execSync(`git tag -a v${nextVersion} -m "v${nextVersion}"`);
  29. execSync(`git push`);
  30. execSync(`git push origin v${nextVersion}`);
  31. console.log(`Publish Successfully...`);
  32. }
  33. resolvePublish();