Skip to content

Allow config file to be arbitrarily named #66

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

Merged
merged 1 commit into from
Nov 30, 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
9 changes: 8 additions & 1 deletion bin/suitcss
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ program.parse(process.argv);
* Settings.
*/

function requireOrParse(configFile) {
var configPath = resolve(configFile);
var ext = path.extname(configPath);
var readFn = /js|json/.test(ext) ? require : fs.readJsonSync;
return readFn(configPath);
}

var input = program.args[0] ? resolve(program.args[0]) : null;
var output = program.args[1] ? resolve(program.args[1]) : null;
var config = program.config ? require(resolve(program.config)) : null;
var config = program.config ? requireOrParse(program.config) : {};
var verbose = program.verbose;
var regen = program.watch && input && output;

Expand Down
12 changes: 11 additions & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('cli', function() {
});
});

it('should allow a config file to be passed', function(done) {
it('should allow a config module to be passed', function(done) {
exec('node bin/suitcss -i test/fixtures -c test/config/test.js test/fixtures/config.css test/fixtures/cli/output.css', function(err) {
if (err) return done(err);
var res = util.read('fixtures/cli/output');
Expand All @@ -86,6 +86,16 @@ describe('cli', function() {
});
});

it('should allow an arbitrarily named json config file to be passed', function(done) {
exec('node bin/suitcss -i test/fixtures -c test/config/test.config test/fixtures/config.css test/fixtures/cli/output.css', function(err) {
if (err) return done(err);
var res = util.read('fixtures/cli/output');
var expected = util.read('fixtures/config.out');
expect(res).to.equal(expected);
done();
});
});

it('should allow to override config options via cli flags', function(done) {
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);
Expand Down
11 changes: 11 additions & 0 deletions test/config/test.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"lint": true,
"minify": false,
"use": [
"postcss-property-lookup"
],
"autoprefixer": {
"add": false,
"remove": false
}
}