From a85f6ed77f37cf5251e85668e9fa9d588057f15a Mon Sep 17 00:00:00 2001 From: Greg MacLellan Date: Mon, 16 Jun 2014 14:26:45 -0400 Subject: [PATCH] Create pems/ directory in same location as outputfile --- ca-store-generator.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ca-store-generator.js b/ca-store-generator.js index 74f3299..9f854f4 100644 --- a/ca-store-generator.js +++ b/ca-store-generator.js @@ -111,12 +111,10 @@ function parseCertData(lines) { return certs; } -function dumpCerts(certs, filename) { +function dumpCerts(certs, filename, pemsDir) { certs.forEach(function (cert, i) { - var pathname = path.join(__dirname, 'pems', 'ca-' + i + '.pem') - ; - - fs.writeFileSync(pathname, cert.quasiPEM()); + var pemsFile = path.join(pemsDir, 'ca-' + i + '.pem'); + fs.writeFileSync(pemsFile, cert.quasiPEM()); }); console.info("Wrote " + certs.length + " certificates in '" + path.join(__dirname, 'pems/').replace(/'/g, "\\'") + "'."); @@ -151,12 +149,17 @@ if (process.argv[2] == null) { console.error("Error: No file specified"); console.info("Usage: %s ", process.argv[1]); console.info(" where is the name of the file to write to, relative to %s", process.argv[1]); + console.info("Note that a 'pems/' directory will also be created at the same location as the , containing individual .pem files."); process.exit(3); } -//Expects a filename as the second command line argument; made relative to directory of this file +// main (combined) output file location, relative to this script's location var outputFile = path.resolve(__dirname, process.argv[2]); +// pems/ output directory, in the same directory as the outputFile +var outputPemsDir = path.resolve(outputFile, '../pems') + + console.info("Loading latest certificates from " + CERTDB_URL); request(CERTDB_URL, function (error, response, body) { if (error) { @@ -170,5 +173,5 @@ request(CERTDB_URL, function (error, response, body) { } var lines = body.split("\n"); - dumpCerts(parseCertData(lines), outputFile); + dumpCerts(parseCertData(lines), outputFile, outputPemsDir); });