Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial folder support #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions bin/colorguard
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'));
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/simple2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.classname2 {
background-image: -webkit-linear-gradient(rgba(0,0,0,1), #020202);
color: #000000;
}