release.mjs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { $, argv } from 'zx';
  2. import { consola } from 'consola';
  3. import { rawCommitsToMarkdown } from './shared/commits.mjs';
  4. import { addToChangelog } from './shared/changelog.mjs';
  5. $.verbose = false;
  6. const isDryRun = argv['dry-run'] ?? false;
  7. const now = new Date();
  8. const currentShortSha = (await $`git rev-parse --short HEAD`).stdout.trim();
  9. const calver = now.toISOString().slice(0, 10).replace(/-/g, '.');
  10. const version = `${calver}-${currentShortSha}`;
  11. const { stdout: rawCommits } = await $`git log --pretty=oneline $(git describe --tags --abbrev=0)..HEAD`;
  12. const markdown = rawCommitsToMarkdown({ rawCommits });
  13. consola.info(`Changelog: \n\n${markdown}\n\n`);
  14. if (isDryRun) {
  15. consola.info(`[dry-run] Not creating version nor tag`);
  16. consola.info('Aborting');
  17. process.exit(0);
  18. }
  19. const shouldContinue = await consola.prompt(
  20. 'This script will create a new version and tag, and update the changelog. Continue?',
  21. {
  22. type: 'confirm',
  23. },
  24. );
  25. if (!shouldContinue) {
  26. consola.info('Aborting');
  27. process.exit(0);
  28. }
  29. consola.info('Updating changelog');
  30. await addToChangelog({ changelog: markdown, version });
  31. consola.success('Changelog updated');
  32. try {
  33. consola.info('Committing changelog changes');
  34. await $`git add CHANGELOG.md`;
  35. await $`git commit -m "docs(changelog): update changelog for ${version}"`;
  36. consola.success('Changelog changes committed');
  37. consola.info('Creating version and tag');
  38. await $`npm version ${version} -m "chore(version): release ${version}"`;
  39. consola.info('Npm version released with tag');
  40. } catch (error) {
  41. consola.error(error);
  42. consola.info('Aborting');
  43. process.exit(1);
  44. }