prepublish.mjs 1018 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env zx
  2. import 'zx/globals';
  3. import { PROJECTS } from './utils.mjs';
  4. await $`pnpm snapshot`;
  5. const { version } = await fs.readJSON('./package.json');
  6. const projects = Object.keys(PROJECTS);
  7. const rootDirectory = path.resolve(__dirname, '..');
  8. const projectsDirectory = path.resolve(rootDirectory, 'projects');
  9. for (const projectName of projects) {
  10. const projectDirectory = path.resolve(projectsDirectory, projectName);
  11. cd(projectDirectory);
  12. // Add all changes and commit them.
  13. await $`git add -A .`;
  14. try {
  15. await $`git commit -m "version ${version} snapshot"`;
  16. } catch (e) {
  17. if (!e.stdout.includes('nothing to commit')) {
  18. throw e;
  19. }
  20. }
  21. // Tag the commit.
  22. await $`git tag -m "v${version}" v${version}`;
  23. // Push the changes on main.
  24. await $`git push origin HEAD:main --follow-tags`;
  25. }
  26. // Update submodules on the root directory.
  27. cd(rootDirectory);
  28. await $`git add projects`;
  29. await $`git commit -m 'Update snapshot' --allow-empty`;
  30. await $`git push --follow-tags`;