Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. function vm(inputVersion = '') {
  2.  
  3. let [ major, minor, patch ] = inputVersion.split('.');
  4. let currentVersion = {
  5. major: major && parseInt(major, 10) || 0,
  6. minor: minor && parseInt(minor, 10) || 0,
  7. patch: patch && parseInt(patch, 10) || 1,
  8. };
  9. let previousVersion = null;
  10.  
  11. this.release = () => {
  12. return `${currentVersion.major}.${currentVersion.minor}.${currentVersion.patch}`;
  13. }
  14.  
  15. this.major = () => {
  16. previousVersion = { ...currentVersion };
  17. currentVersion.major += 1;
  18. currentVersion.minor = 0;
  19. currentVersion.patch = 0;
  20. return this;
  21. }
  22.  
  23. this.minor = () => {
  24. previousVersion = { ...currentVersion };
  25. currentVersion.minor += 1;
  26. currentVersion.patch = 0;
  27. return this;
  28. }
  29.  
  30. this.patch = () => {
  31. previousVersion = { ...currentVersion };
  32. currentVersion.patch += 1;
  33. return this;
  34. }
  35.  
  36. this.rollback = () => {
  37. if (!Boolean(previousVersion)){
  38. throw new Error('Can`t rollback.')
  39. }
  40. currentVersion = { ...previousVersion };
  41. return this;
  42. }
  43. return this;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement