Created
July 18, 2019 01:54
-
-
Save johnrees/a188e702f4f58963c00b7c5c20e8a779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const file = fs.readFileSync(".gitmodules").toString(); | |
function parseGitModules(data, _callback) { | |
var gitModules = data.split("["), | |
subModulesCollections = []; | |
gitModules.forEach(function(submodules) { | |
if (/^submodule*/.test(submodules)) { | |
var submodule = submodules.split("\n\t"), | |
moduleDetails = {}; | |
submodule.forEach(function(sub) { | |
var parseSubmoduleDetails = [], | |
sub = sub | |
.replace(/\n/g, "") | |
.replace(/\s/g, "") | |
.replace(/\"/g, "="); | |
parseSubmoduleDetails = sub.split("="); | |
switch (parseSubmoduleDetails[0]) { | |
case "submodule": | |
moduleDetails.submodule = parseSubmoduleDetails[1]; | |
break; | |
case "path": | |
moduleDetails.path = parseSubmoduleDetails[1]; | |
break; | |
case "branch": | |
moduleDetails.branch = parseSubmoduleDetails[1]; | |
break; | |
case "url": | |
moduleDetails.url = parseSubmoduleDetails[1]; | |
break; | |
} | |
}); | |
subModulesCollections.push(moduleDetails); | |
} | |
}); | |
// callback(null, subModulesCollections); | |
return subModulesCollections; | |
} | |
console.log(parseGitModules(file)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment