You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autorelease.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 (e) {
  16. console.error(e);
  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 file.indexOf("src") >= 0 && !filesToIgnoreRegex.test(file);
  29. });
  30. if (!excalidrawPackageFiles.length) {
  31. process.exit(0);
  32. }
  33. // update package.json
  34. pkg.version = `${pkg.version}-${getShortCommitHash()}`;
  35. pkg.name = "@excalidraw/excalidraw-next";
  36. fs.writeFileSync(excalidrawPackage, JSON.stringify(pkg, null, 2), "utf8");
  37. // update readme
  38. const data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
  39. fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
  40. publish();
  41. });