bump-versions.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import semver from 'semver';
  2. import { loadConfig, getCurrentVersion, getReleaseType } from 'shipjs-lib';
  3. import printDryRunBanner from 'shipjs/src/step/printDryRunBanner';
  4. import confirmNextVersion from 'shipjs/src/step/prepare/confirmNextVersion';
  5. import updateVersion from 'shipjs/src/step/prepare/updateVersion';
  6. import updateVersionMonorepo from 'shipjs/src/step/prepare/updateVersionMonorepo';
  7. import installDependencies from 'shipjs/src/step/prepare/installDependencies';
  8. import printHelp from '../step/printHelp';
  9. async function bumpVersions({
  10. help = false,
  11. dir = '.',
  12. dryRun = false,
  13. increment = 'patch',
  14. preid = 'RC',
  15. }) {
  16. if (help) {
  17. printHelp();
  18. return;
  19. }
  20. if (dryRun) {
  21. printDryRunBanner();
  22. }
  23. const config = await loadConfig(dir, 'bump-versions.config');
  24. // get current version
  25. const { monorepo } = config;
  26. const currentVersion = monorepo && monorepo.mainVersionFile
  27. ? getCurrentVersion(dir, monorepo.mainVersionFile)
  28. : getCurrentVersion(dir);
  29. // determine next version
  30. let nextVersion = semver.inc(currentVersion, increment, preid); // set preid if type is 'prerelease'
  31. nextVersion = await confirmNextVersion({
  32. yes: true,
  33. currentVersion,
  34. nextVersion,
  35. dryRun,
  36. });
  37. const releaseType = getReleaseType(nextVersion);
  38. // update
  39. const updateVersionFn = monorepo
  40. ? updateVersionMonorepo
  41. : updateVersion;
  42. await updateVersionFn({
  43. config, nextVersion, releaseType, dir, dryRun,
  44. });
  45. }
  46. const arg = {
  47. '--dir': String,
  48. '--help': Boolean,
  49. '--dry-run': Boolean,
  50. '--increment': String,
  51. '--preid': String,
  52. // Aliases
  53. '-d': '--dir',
  54. '-h': '--help',
  55. '-D': '--dry-run',
  56. '-i': '--increment',
  57. };
  58. export default {
  59. arg,
  60. fn: bumpVersions,
  61. };