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

Fix undefined cli flags override config #62

Merged
merged 2 commits into from
Nov 15, 2016
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### HEAD

### 3.0.1 (November XX, 2016)

* Fix: `undefined` cli flags don't override config

### 3.0.0 (October 20, 2016)

* Pin core plugins order:
Expand Down
18 changes: 12 additions & 6 deletions bin/suitcss
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ function run() {
read(input, function(err, buffer) {
if (err) logger.throw(err);
var css = buffer.toString();
var opts = assign({}, config, {
minify: program.minify,
root: program.importRoot,
encapsulate: program.encapsulate,
lint: program.lint
});
var flags = [
'minify',
'encapsulate',
'root',
'lint'
].reduce(function (accumulator, flag) {
if (({}).hasOwnProperty.call(program, flag)) {
accumulator[flag] = program[flag];
}
return accumulator;
}, {});
var opts = assign({}, config, flags);

if (program.throwError) {
assign(opts, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"postcss-custom-media": "^5.0.0",
"postcss-custom-properties": "^5.0.0",
"postcss-easy-import": "^1.0.1",
"postcss-reporter": "^1.3.0",
"postcss-reporter": "^2.0.0",
"read-file-stdin": "^0.2.1",
"stylelint": "^7.2.0",
"stylelint-config-suitcss": "^8.0.0"
Expand Down
14 changes: 12 additions & 2 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,21 @@ describe('cli', function() {
});

it('should allow to override config options via cli flags', function(done) {
exec('node bin/suitcss -L -c test/config/test.js test/fixtures/import.css test/fixtures/cli/output.css', function(err) {
exec('node bin/suitcss -m -c test/config/test.js test/fixtures/import.css test/fixtures/cli/output.css', function(err) {
if (err) return done(err);
var res = util.read('fixtures/cli/output');
var commentsPattern = /\/\*[^]*?\*\//g;
expect(res).to.match(commentsPattern);
expect(res).to.not.match(commentsPattern);
done();
});
});

it('should preserve config options when not passing cli flags', function(done) {
exec('node bin/suitcss -c test/config/cli-undefined-flags.js test/fixtures/import.css test/fixtures/cli/output.css', function(err) {
if (err) return done(err);
var res = util.read('fixtures/cli/output');
var commentsPattern = /\/\*[^]*?\*\//g;
expect(res).to.not.match(commentsPattern);
done();
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/config/cli-undefined-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
minify: true
};
1 change: 1 addition & 0 deletions test/config/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
lint: true,
minify: false,
use: [
'postcss-property-lookup'
],
Expand Down