Pass parameters to ca-store-generator.js to avoid platform differences in command-line execution of multiple commands

This commit is contained in:
Greg MacLellan 2014-06-16 14:11:15 -04:00
parent 32d1bc36b4
commit b52fc86671
2 changed files with 14 additions and 8 deletions

View File

@ -6,7 +6,6 @@ var fs = require('fs')
, path = require('path') , path = require('path')
, request = require('request') , request = require('request')
, CERTDB_URL = 'https://mxr.mozilla.org/nss/source/lib/ckfw/builtins/certdata.txt?raw=1' , CERTDB_URL = 'https://mxr.mozilla.org/nss/source/lib/ckfw/builtins/certdata.txt?raw=1'
, OUTFILE = path.join(__dirname, './ssl-root-cas-latest.js')
, HEADER , HEADER
; ;
@ -112,7 +111,7 @@ function parseCertData(lines) {
return certs; return certs;
} }
function dumpCerts(certs) { function dumpCerts(certs, filename) {
certs.forEach(function (cert, i) { certs.forEach(function (cert, i) {
var pathname = path.join(__dirname, 'pems', 'ca-' + i + '.pem') var pathname = path.join(__dirname, 'pems', 'ca-' + i + '.pem')
; ;
@ -123,7 +122,7 @@ function dumpCerts(certs) {
+ path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'."); + path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'.");
fs.writeFileSync( fs.writeFileSync(
OUTFILE filename
, HEADER , HEADER
+ 'var cas = module.exports = [\n' + 'var cas = module.exports = [\n'
+ certs.map(function (cert) { return cert.quasiPEM(); }).join(',\n\n') + certs.map(function (cert) { return cert.quasiPEM(); }).join(',\n\n')
@ -145,9 +144,16 @@ function dumpCerts(certs) {
+ " return module.exports;\n" + " return module.exports;\n"
+ "};\n" + "};\n"
); );
console.info("Wrote '" + OUTFILE.replace(/'/g, "\\'") + "'."); console.info("Wrote '" + filename.replace(/'/g, "\\'") + "'.");
} }
//Expects a filename as the second command line argument
var outputFile = process.argv[2];
if(outputFile == null) {
outputFile = path.join(__dirname, 'ssl-root-cas-latest.js');
}
console.info("Loading latest certificates from " + CERTDB_URL);
request(CERTDB_URL, function (error, response, body) { request(CERTDB_URL, function (error, response, body) {
if (error) { if (error) {
console.error(error.stacktrace); console.error(error.stacktrace);
@ -160,5 +166,5 @@ request(CERTDB_URL, function (error, response, body) {
} }
var lines = body.split("\n"); var lines = body.split("\n");
dumpCerts(parseCertData(lines)); dumpCerts(parseCertData(lines), outputFile);
}); });

View File

@ -4,9 +4,9 @@
"description": "The module you need to solve node's SSL woes when including a custom certificate.", "description": "The module you need to solve node's SSL woes when including a custom certificate.",
"main": "ssl-root-cas", "main": "ssl-root-cas",
"scripts": { "scripts": {
"test": "node ca-store-generator.js", "test": "node ca-store-generator.js ssl-root-cas-test.js",
"prepublish": "node ca-store-generator.js; mv ssl-root-cas-latest.js ssl-root-cas.js", "prepublish": "node ca-store-generator.js ssl-root-cas.js",
"postinstall": "node ca-store-generator.js; mv ssl-root-cas-latest.js latest.js" "postinstall": "node ca-store-generator.js latest.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",