Merge pull request #4 from gregmac/master
Have ca-store-generator.js accept output filename as param
This commit is contained in:
commit
eb4f543a77
|
@ -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,18 +111,16 @@ function parseCertData(lines) {
|
|||
return certs;
|
||||
}
|
||||
|
||||
function dumpCerts(certs) {
|
||||
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, "\\'") + "'.");
|
||||
|
||||
fs.writeFileSync(
|
||||
OUTFILE
|
||||
filename
|
||||
, HEADER
|
||||
+ 'var cas = module.exports = [\n'
|
||||
+ certs.map(function (cert) { return cert.quasiPEM(); }).join(',\n\n')
|
||||
|
@ -145,9 +142,25 @@ function dumpCerts(certs) {
|
|||
+ " return module.exports;\n"
|
||||
+ "};\n"
|
||||
);
|
||||
console.info("Wrote '" + OUTFILE.replace(/'/g, "\\'") + "'.");
|
||||
console.info("Wrote '" + filename.replace(/'/g, "\\'") + "'.");
|
||||
}
|
||||
|
||||
if (process.argv[2] == null) {
|
||||
console.error("Error: No file specified");
|
||||
console.info("Usage: %s <outputfile>", process.argv[1]);
|
||||
console.info(" where <outputfile> 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 <outputfile>, containing individual .pem files.");
|
||||
process.exit(3);
|
||||
}
|
||||
|
||||
// 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) {
|
||||
console.error(error.stacktrace);
|
||||
|
@ -160,5 +173,5 @@ request(CERTDB_URL, function (error, response, body) {
|
|||
}
|
||||
|
||||
var lines = body.split("\n");
|
||||
dumpCerts(parseCertData(lines));
|
||||
dumpCerts(parseCertData(lines), outputFile, outputPemsDir);
|
||||
});
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue