Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. // TODO: Count number of changes... only create PR if > 0
  2. // TODO: Only change version if new number is greater. Will need semver lib.
  3. target.versionReplace = function() {
  4. var currentDeps = fs.readFileSync('C:\\Users\\stfrance\\Desktop\\tempdeps.xml', "utf8");
  5. var newDeps = fs.readFileSync('C:\\Users\\stfrance\\Downloads\\IndividualNuGetPackages\\IndividualNuGetPackages\\unified_deps.xml', "utf8");
  6.  
  7. var currentDepsArr = currentDeps.split('\n');
  8. var newDepsArr = newDeps.split('\n');
  9. var newDepsDict = {};
  10.  
  11. newDepsArr.forEach(function (newDep) {
  12. // add to dictionary
  13. var depDetails = newDep.split("\"");
  14. //console.log(JSON.stringify(depDetails));
  15. var name = depDetails[1];
  16. var version = depDetails[3];
  17. //console.log(name + ' ' + version);
  18. newDepsDict[name] = version;
  19. });
  20.  
  21. var updatedDeps = [];
  22.  
  23. currentDepsArr.forEach(function (currentDep) {
  24. var depDetails = currentDep.split("\"");
  25. var name = depDetails[1];
  26. var version = depDetails[3];
  27.  
  28. // find if there is a match in new
  29. if (newDepsDict[name]) {
  30. // update the version
  31. depDetails[3] = newDepsDict[name];
  32. updatedDeps.push(depDetails.join('\"'));
  33. } else {
  34. updatedDeps.push(currentDep);
  35. }
  36. });
  37.  
  38. // list new ones that arent in current
  39. newDepsArr.forEach(function (newDep) {
  40. // add to dictionary
  41. var depDetails = newDep.split("\"");
  42. //console.log(JSON.stringify(depDetails));
  43. var name = depDetails[1];
  44. var version = depDetails[3];
  45.  
  46. var currentContainsNew = false;
  47. currentDepsArr.forEach(function (currentDep) {
  48. var depDetails = currentDep.split("\"");
  49. var currName = depDetails[1];
  50.  
  51. if (currName === name) {
  52. currentContainsNew = true;
  53. }
  54. });
  55.  
  56. if (!currentContainsNew) {
  57. console.log(name);
  58. }
  59. });
  60.  
  61. // write it as a new file where currentDeps is
  62. fs.writeFileSync("C:\\Users\\stfrance\\Desktop\\NEW.txt", updatedDeps.join("\n"));
  63. console.log('Done.');
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement