diff --git a/.gitignore b/.gitignore index d2c3534..a83b1e3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,6 @@ node_modules output/ passModels/ -certificates/pass.cer -certificates/passCertificate-exported.p12 -certificates/passcertificate.pem -certificates/passkey.pem -certificates/source-AppleWWDRCA.cer +certificates/ improvements.rtf +config.json diff --git a/config.json b/config.json deleted file mode 100644 index e22ef3a..0000000 --- a/config.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "certificates": { - "dir": "certificates", - "files": { - "wwdr": "WWDR.pem", - "signerCert": "passcertificate.pem", - "signerKey": "passkey.pem" - }, - "credentials": { - "privateKeySecret": "123456" - } - }, - "output": { - "dir": "output" - }, - "models": { - "dir": "passModels" - } -} \ No newline at end of file diff --git a/index.js b/index.js index 2613952..8f3b5e2 100644 --- a/index.js +++ b/index.js @@ -391,20 +391,41 @@ function init(configPath) { let setup = require(configPathResolved); - loadConfiguration(setup).then(function(config) { - Certificates.wwdr = config[0]; - Certificates.signerCert = config[1]; - Certificates.signerKey = config[2]; + let queue = [ + new Promise(function(success, reject) { + fs.access(path.resolve(setup.models.dir), function(err) { + if (err) { + return reject("A valid pass model directory is required. Please provide one in the configuration file under voice 'models.dir'.") + } + + return success(null); + }); + }), + new Promise((success) => fs.access(path.resolve(setup.output.dir), success)), + loadConfiguration(setup) + ]; + + Promise.all(queue) + .then(function(results) { + let paths = results.slice(0, 2); + let certs = results[results.length-1]; + + if (!paths[0]) { + Configuration.passModelsDir = setup.models.dir; + } + + if (!paths[1] && setup.output.shouldWrite) { + Configuration.output.dir = setup.output.dir; + } + + Certificates.wwdr = certs[0]; + Certificates.signerCert = certs[1]; + Certificates.signerKey = certs[2]; Certificates.status = true; }) .catch(function(error) { - throw new Error(`Error: ${error}`); + throw new Error(error); }); - - Configuration.passModelsDir = setup.models.dir; - Configuration.output.dir = setup.output.dir; - // for a future implementation - Configuration.output.shouldWrite = false } module.exports = { init, RequestHandler };