Created
August 12, 2016 16:14
-
-
Save qmacro/d9ad9d8a7171c3b76f54a8e7c77049bd 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
#!/usr/bin/env node | |
var stdin = process.stdin, | |
stdout = process.stdout, | |
aConfigLines = [], | |
https = require('https'), | |
sDocuRoot = "https://help.hana.ondemand.com/webide/", | |
sDocuPage = "233396e994584fe9b4c7ab6cb2798640.html"; | |
// Read in current .eslintrc.ext config from STDIN | |
stdin.resume(); | |
stdin.setEncoding("utf8"); | |
stdin.on("data", function (s) { | |
aConfigLines.push(s); | |
}); | |
// When all read in, go and fetch the SAP docu page | |
// and extract the links for the SAP rule IDs | |
stdin.on("end", function () { | |
var mConfig = JSON.parse(aConfigLines.join()); | |
// Fetch the docu page | |
https.get(sDocuRoot + sDocuPage, (mResponse) => { | |
var sHTML = ""; | |
mResponse.on("data", (d) => sHTML += d); | |
mResponse.on("end", () => { | |
// Find all the lines with rule -> help URL links and | |
// make the results into a nice rule:URL map | |
var mHelpLinks = sHTML.match(/<a class="link" href="([^"]+)" .+?>([^<]+)<\/a>/g) | |
.reduce((m, s) => { | |
var aResult = s.match(/href="(.+?)" .*>(.+)</); | |
m[aResult[2]] = sDocuRoot + aResult[1]; | |
return m; | |
}, {}); | |
// Process the config, specifically the rulesExt property, | |
// replacing helpUrl property values if we find them in our rule:URL map | |
mConfig.rulesExt = Object.keys(mConfig.rulesExt).reduce((m, sRule) => { | |
var mRuleInfo = mConfig.rulesExt[sRule]; | |
mRuleInfo.helpUrl = mHelpLinks[sRule] || mRuleInfo.helpUrl; | |
m[sRule] = mRuleInfo; | |
return m; | |
}, {}); | |
stdout.write(JSON.stringify(mConfig, null, 2)); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment