Skip to content

Commit

Permalink
Merge pull request katiefenn#10 from swelham/feature-load-by-dir
Browse files Browse the repository at this point in the history
added load stylesheets by directory feature
  • Loading branch information
katiefenn committed Mar 2, 2014
2 parents 403c0ba + 825230f commit 16ab7c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dependencies": {
"underscore": "*",
"cli-color": "*",
"minimist": "0.0.7"
"minimist": "0.0.7",
"async": "~0.2.10"
},
"devDependencies": {
"chai": "*",
Expand Down
41 changes: 29 additions & 12 deletions parker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,47 @@ var _ = require('underscore'),
metrics = require('./metrics/All.js'),
clc = require('cli-color'),
argv = require('minimist')(process.argv.slice(2)),
fs = require('fs');
fs = require('fs'),
async = require('async'),
path = require('path');

console.log(clc.red('PA') + clc.yellow('RK') + clc.green('ER') + '-JS');

var parker = new Parker(metrics);

if (argv._.length > 0) {
var stylesheets = [];
_.each(argv._, function (filename) {

async.each(argv._, function (filename, done) {
var onComplete = function (err, data) {
stylesheets.push(data);
if (stylesheets.length === argv._.length) {
onAllComplete();
}
};

var onAllComplete = function () {
var results = parker.run(stylesheets);
_.each(metrics, function(metric) {
console.log(metric.name + ': ' + results[metric.id]);
});
};
if (filename.indexOf('.css') === -1) {
fs.readdir(filename, function (err, files) {
async.each(files, function (file, fileDone) {
if (file.indexOf('.css') === -1) {
return fileDone();
}

fs.readFile(filename, {encoding: 'utf8'}, onComplete);
fs.readFile(path.join(filename, file), {encoding: 'utf8'}, function (err, fileData) {
onComplete(err, fileData);
fileDone();
});
}, done);
});
}
else {
fs.readFile(filename, {encoding: 'utf8'}, function (err, fileData) {
onComplete(err, fileData);
done();
});
}
}, function (err) {
var results = parker.run(stylesheets);
_.each(metrics, function(metric) {
console.log(metric.name + ': ' + results[metric.id]);
});
});
}
else {
Expand Down

0 comments on commit 16ab7c7

Please sign in to comment.