bump-versions.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. updateDependencies = true,
  14. increment = 'patch',
  15. preid = 'RC',
  16. }) {
  17. if (help) {
  18. printHelp();
  19. return;
  20. }
  21. if (dryRun) {
  22. printDryRunBanner();
  23. }
  24. const config = await loadConfig(dir, 'bump-versions.config');
  25. const { monorepo } = config;
  26. if (!updateDependencies) {
  27. monorepo.updateDependencies = false;
  28. }
  29. // get current version
  30. const currentVersion = monorepo && monorepo.mainVersionFile
  31. ? getCurrentVersion(dir, monorepo.mainVersionFile)
  32. : getCurrentVersion(dir);
  33. // determine next version
  34. let nextVersion = semver.inc(currentVersion, increment, preid); // set preid if type is 'prerelease'
  35. nextVersion = await confirmNextVersion({
  36. yes: true,
  37. currentVersion,
  38. nextVersion,
  39. dryRun,
  40. });
  41. const releaseType = getReleaseType(nextVersion);
  42. // update
  43. const updateVersionFn = monorepo
  44. ? updateVersionMonorepo
  45. : updateVersion;
  46. await updateVersionFn({
  47. config, nextVersion, releaseType, dir, dryRun,
  48. });
  49. }
  50. const arg = {
  51. '--dir': String,
  52. '--help': Boolean,
  53. '--dry-run': Boolean,
  54. '--update-dependencies': Boolean,
  55. '--increment': String,
  56. '--preid': String,
  57. // Aliases
  58. '-d': '--dir',
  59. '-h': '--help',
  60. '-D': '--dry-run',
  61. '-i': '--increment',
  62. };
  63. export default {
  64. arg,
  65. fn: bumpVersions,
  66. };