diff --git a/index.js b/index.js index e57dac7..bf786d7 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,24 @@ -module.exports = function(dest, options){ - try{ +module.exports = function (dest, options) { + try { var root = __dirname; var fs = require('fs'); - + var jsonSettings = fs.readFileSync(root + '/defaults/settings.json'); var defaults = JSON.parse(jsonSettings); - - if(typeof options !== "object"){ + + if (typeof options !== "object") { options = defaults; - } - else{ - for(var key in defaults){ - if(options[key] === undefined){ + } else { + for (var key in defaults) { + if (typeof (options[key]) === "undefined") { options[key] = defaults[key]; + } + else if (typeof options[key] === "object") { + for (var k in defaults[key]) { + if (typeof (options[key][k]) === "undefined") { + options[key][k] = defaults[key][k]; + } + } } } } @@ -22,14 +28,13 @@ module.exports = function(dest, options){ patterns.clearfix = fs.readFileSync(root + '/system/patterns/clearfix'); patterns.reset = fs.readFileSync(root + '/system/patterns/reset'); patterns.debug = fs.readFileSync(root + '/system/patterns/debug'); - + var build = require('./build.js'); var res = build(options, patterns); - if(dest === undefined){ + if (dest === undefined) { console.log('It`s test mode, because you don`t set destination folder'); - } - else{ + } else { var buildFile = dest + '/' + options.filename + '.' + res.type; fs.writeFileSync(buildFile, res.grid); console.log('Grid placed into ' + buildFile); @@ -37,8 +42,7 @@ module.exports = function(dest, options){ console.log('Grid length is ' + res.grid.length + ' :)'); console.log("Its work! Good day!"); - } - catch(err){ + } catch (err) { console.log("Oops -> " + err); } } \ No newline at end of file