autorelease.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const fs = require("fs");
  2. const { exec, execSync } = require("child_process");
  3. const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
  4. const excalidrawPackage = `${excalidrawDir}/package.json`;
  5. const pkg = require(excalidrawPackage);
  6. const getShortCommitHash = () => {
  7. return execSync("git rev-parse --short HEAD").toString().trim();
  8. };
  9. const publish = () => {
  10. try {
  11. execSync(`yarn --frozen-lockfile`);
  12. execSync(`yarn --frozen-lockfile`, { cwd: excalidrawDir });
  13. execSync(`yarn run build:umd`, { cwd: excalidrawDir });
  14. execSync(`yarn --cwd ${excalidrawDir} publish`);
  15. } catch (error) {
  16. console.error(error);
  17. }
  18. };
  19. // get files changed between prev and head commit
  20. exec(`git diff --name-only HEAD^ HEAD`, async (error, stdout, stderr) => {
  21. if (error || stderr) {
  22. console.error(error);
  23. process.exit(1);
  24. }
  25. const changedFiles = stdout.trim().split("\n");
  26. const filesToIgnoreRegex = /src\/excalidraw-app|packages\/utils/;
  27. const excalidrawPackageFiles = changedFiles.filter((file) => {
  28. return (
  29. (file.indexOf("src") >= 0 || file.indexOf("package.json")) >= 0 &&
  30. !filesToIgnoreRegex.test(file)
  31. );
  32. });
  33. if (!excalidrawPackageFiles.length) {
  34. process.exit(0);
  35. }
  36. // update package.json
  37. pkg.version = `${pkg.version}-${getShortCommitHash()}`;
  38. pkg.name = "@excalidraw/excalidraw-next";
  39. fs.writeFileSync(excalidrawPackage, JSON.stringify(pkg, null, 2), "utf8");
  40. // update readme
  41. const data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
  42. fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
  43. publish();
  44. });