From b52fc86671ae42f19fd395c5c4ab35bf490b9104 Mon Sep 17 00:00:00 2001 From: Greg MacLellan Date: Mon, 16 Jun 2014 14:11:15 -0400 Subject: [PATCH] Pass parameters to ca-store-generator.js to avoid platform differences in command-line execution of multiple commands --- ca-store-generator.js | 16 +++++++++++----- package.json | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ca-store-generator.js b/ca-store-generator.js index 26a09ea..653028a 100644 --- a/ca-store-generator.js +++ b/ca-store-generator.js @@ -6,7 +6,6 @@ var fs = require('fs') , path = require('path') , request = require('request') , 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 ; @@ -112,7 +111,7 @@ function parseCertData(lines) { return certs; } -function dumpCerts(certs) { +function dumpCerts(certs, filename) { certs.forEach(function (cert, i) { var pathname = path.join(__dirname, 'pems', 'ca-' + i + '.pem') ; @@ -123,7 +122,7 @@ function dumpCerts(certs) { + path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'."); fs.writeFileSync( - OUTFILE + filename , HEADER + 'var cas = module.exports = [\n' + certs.map(function (cert) { return cert.quasiPEM(); }).join(',\n\n') @@ -145,9 +144,16 @@ function dumpCerts(certs) { + " return module.exports;\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) { if (error) { console.error(error.stacktrace); @@ -160,5 +166,5 @@ request(CERTDB_URL, function (error, response, body) { } var lines = body.split("\n"); - dumpCerts(parseCertData(lines)); + dumpCerts(parseCertData(lines), outputFile); }); diff --git a/package.json b/package.json index 04986d1..a8839e1 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "description": "The module you need to solve node's SSL woes when including a custom certificate.", "main": "ssl-root-cas", "scripts": { - "test": "node ca-store-generator.js", - "prepublish": "node ca-store-generator.js; mv ssl-root-cas-latest.js ssl-root-cas.js", - "postinstall": "node ca-store-generator.js; mv ssl-root-cas-latest.js latest.js" + "test": "node ca-store-generator.js ssl-root-cas-test.js", + "prepublish": "node ca-store-generator.js ssl-root-cas.js", + "postinstall": "node ca-store-generator.js latest.js" }, "repository": { "type": "git",