From a9698f87555ac700b7ff40f2d65ff567a7b6fcf0 Mon Sep 17 00:00:00 2001 From: Matt DuVall Date: Thu, 10 Jul 2014 22:10:34 -0700 Subject: [PATCH] Initial folder support --- bin/colorguard | 27 ++++++++++++++++++++++++--- test/fixtures/simple2.css | 4 ++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/simple2.css diff --git a/bin/colorguard b/bin/colorguard index 9148a51e..0b399b97 100755 --- a/bin/colorguard +++ b/bin/colorguard @@ -10,10 +10,20 @@ process.title = 'colorguard'; var colorguard = require('..'); var css = []; -var options; +var options, + dirFiles; -if (argv.file) { - css = fs.readFileSync(path.resolve(process.cwd(), argv.file), 'utf8'); +if (argv.folder) { + dirFiles = getCssFiles(argv.folder); + dirFiles.forEach(function(fileName) { + var filePath = argv.folder + fileName; + css = css.concat(getFileContents(argv.folder + fileName)); + }); + + run(css.join()); +} +else if (argv.file) { + css = getFileContents(argv.file); run(css); } else { @@ -29,6 +39,17 @@ else { }); } +function getCssFiles(dirpath) { + var files = fs.readdirSync(path.resolve(process.cwd(), dirpath), 'utf8'); + return files.filter(function(fileName) { + return fileName.split('.')[1] === 'css'; + }); +} + +function getFileContents(dirpath) { + return fs.readFileSync(path.resolve(process.cwd(), dirpath), 'utf8'); +} + function run(css) { if (argv.options) { options = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), argv.options), 'utf8')); diff --git a/test/fixtures/simple2.css b/test/fixtures/simple2.css new file mode 100644 index 00000000..cf43d399 --- /dev/null +++ b/test/fixtures/simple2.css @@ -0,0 +1,4 @@ +.classname2 { + background-image: -webkit-linear-gradient(rgba(0,0,0,1), #020202); + color: #000000; +}