diff --git a/lib/conf.js b/lib/conf.js index 277462f46..17983e4c2 100644 --- a/lib/conf.js +++ b/lib/conf.js @@ -87,8 +87,11 @@ config = require("nomnom").options({ default: 'sitespeed-result', help: 'The result base directory', callback: function(file) { - if (!fs.existsSync(file)) - return "Couldn't find the basedir:" + file; + if (!fs.existsSync(file)) { + fs.mkdirs(file, function(err){ + if (err) return console.error("Couldn't create the result base dir:" + err); + }); + } } }, userAgent: { @@ -285,15 +288,19 @@ config.run = {}; config.run.date = new Date(); // Setup the absolute result dir + +var startPath = (config.resultBaseDir.charAt(0) === path.sep) ? config.resultBaseDir : path.join(__dirname, '../', + config.resultBaseDir); + if (config.url) { config.urlObject = urlParser.parse(config.url); - config.run.absResultDir = path.join(__dirname, '../',config.resultBaseDir, config.urlObject.hostname, dateFormat(config.run.date, "yyyy-mm-dd-HH-MM-ss") ); + config.run.absResultDir = path.join(startPath, config.urlObject.hostname, dateFormat(config.run.date, "yyyy-mm-dd-HH-MM-ss") ); } else if (config.file) { // TODO handle the file name in a good way if it contains chars that will not fit in a dir - config.run.absResultDir = path.join(__dirname, '../',config.resultBaseDir, config.file, dateFormat(config.run.date, "yyyy-mm-dd-HH-MM-ss") ); + config.run.absResultDir = path.join(startPath, config.file, dateFormat(config.run.date, "yyyy-mm-dd-HH-MM-ss") ); } else if (config.sites) { // The log file will end up here - config.run.absResultDir = path.join(__dirname, '../',config.resultBaseDir, 'sites', dateFormat(config.run.date, "yyyy-mm-dd-HH-MM-ss")); + config.run.absResultDir = path.join(startPath, 'sites', dateFormat(config.run.date, "yyyy-mm-dd-HH-MM-ss")); } // Parse the proxy info as a real URL diff --git a/lib/runner.js b/lib/runner.js index a2a104d2c..a0437326d 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -101,7 +101,11 @@ Runner.prototype._setupConfigurationForSite = function(args, cb) { var url = args.url; config.url = url; config.urlObject = urlParser.parse(config.url); - config.run.absResultDir = path.join(__dirname, '../', config.resultBaseDir, 'sites', dateFormat(config.run.date, + + var startPath = (config.resultBaseDir.charAt(0) === path.sep) ? config.resultBaseDir : path.join(__dirname, '../', + config.resultBaseDir); + + config.run.absResultDir = path.join(startPath, 'sites', dateFormat(config.run.date, "yyyy-mm-dd-HH-MM-ss"), config.urlObject.hostname); // setup the directories needed var dataDir = path.join(config.run.absResultDir, config.dataDir);