Skip to content

Commit e877d27

Browse files
Fixes #2 - adds glob matching source paths.
Why: * User may want to specify a glob path to match all files in a directory instead of a listing them one by one.
1 parent f1e0d1b commit e877d27

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
==================
33

44
* Bumps clean-css dependency to 4.1.x.
5+
* Fixed issue [#2](https://github.com/jakubpawlowicz/clean-css-cli/issues/2) - glob matching source paths.
56
* Fixed issue [#7](https://github.com/jakubpawlowicz/clean-css-cli/issues/7) - using CLI as a module.
67

78
[4.0.12 / 2017-04-12](https://github.com/jakubpawlowicz/clean-css-cli/compare/v4.0.11...v4.0.12)

index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var path = require('path');
33

44
var CleanCSS = require('clean-css');
55
var commands = require('commander');
6+
var glob = require('glob');
67

78
function cli(process, beforeMinifyCallback) {
89
var packageConfig = fs.readFileSync(path.join(__dirname, 'package.json'));
@@ -155,7 +156,7 @@ function cli(process, beforeMinifyCallback) {
155156

156157
// ... and do the magic!
157158
if (commands.args.length > 0) {
158-
minify(process, beforeMinifyCallback, options, debugMode, commands.args);
159+
minify(process, beforeMinifyCallback, options, debugMode, expandGlobs(commands.args));
159160
} else {
160161
stdin = process.openStdin();
161162
stdin.setEncoding('utf-8');
@@ -197,6 +198,12 @@ function findArgumentTo(option, rawArgs, args) {
197198
return value;
198199
}
199200

201+
function expandGlobs(paths) {
202+
return paths.reduce(function (accumulator, path) {
203+
return accumulator.concat(glob.sync(path, { nodir: true, nonull: true}));
204+
}, []);
205+
}
206+
200207
function minify(process, beforeMinifyCallback, options, debugMode, data) {
201208
var cleanCss = new CleanCSS(options);
202209

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"homepage": "https://github.com/jakubpawlowicz/clean-css-cli#readme",
2929
"dependencies": {
3030
"clean-css": "^4.1.0",
31-
"commander": "2.x"
31+
"commander": "2.x",
32+
"glob": "7.x"
3233
},
3334
"devDependencies": {
3435
"http-proxy": "1.x",

test/binary-test.js

+14
Original file line numberDiff line numberDiff line change
@@ -622,4 +622,18 @@ vows.describe('cleancss')
622622
}
623623
}
624624
})
625+
.addBatch({
626+
'wildcard paths': {
627+
'files': binaryContext('./test/fixtures/partials/on*.css ./test/fixtures/partials/f?ve.css', {
628+
'outputs all matched sources minified': function (error, stdout) {
629+
assert.equal(stdout, '.one{color:red}.five{background:url(data:image/jpeg;base64,/9j/)}');
630+
}
631+
}),
632+
'directories': binaryContext('./test/fixtures/partials/**/*.css', {
633+
'outputs all matched sources minified': function (error, stdout) {
634+
assert.equal(stdout, '.one{color:red}.three{color:#0f0}.two{color:#fff}.four{color:#00f}');
635+
}
636+
})
637+
}
638+
})
625639
.export(module);

0 commit comments

Comments
 (0)