Skip to content

Commit 411089d

Browse files
casiogiuseppeg
authored andcommitted
Allow config file to be arbitrarily named (#66)
1 parent e465938 commit 411089d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

bin/suitcss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,16 @@ program.parse(process.argv);
6363
* Settings.
6464
*/
6565

66+
function requireOrParse(configFile) {
67+
var configPath = resolve(configFile);
68+
var ext = path.extname(configPath);
69+
var readFn = /js|json/.test(ext) ? require : fs.readJsonSync;
70+
return readFn(configPath);
71+
}
72+
6673
var input = program.args[0] ? resolve(program.args[0]) : null;
6774
var output = program.args[1] ? resolve(program.args[1]) : null;
68-
var config = program.config ? require(resolve(program.config)) : null;
75+
var config = program.config ? requireOrParse(program.config) : {};
6976
var verbose = program.verbose;
7077
var regen = program.watch && input && output;
7178

test/cli.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('cli', function() {
7676
});
7777
});
7878

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

89+
it('should allow an arbitrarily named json config file to be passed', function(done) {
90+
exec('node bin/suitcss -i test/fixtures -c test/config/test.config test/fixtures/config.css test/fixtures/cli/output.css', function(err) {
91+
if (err) return done(err);
92+
var res = util.read('fixtures/cli/output');
93+
var expected = util.read('fixtures/config.out');
94+
expect(res).to.equal(expected);
95+
done();
96+
});
97+
});
98+
8999
it('should allow to override config options via cli flags', function(done) {
90100
exec('node bin/suitcss -m -c test/config/test.js test/fixtures/import.css test/fixtures/cli/output.css', function(err) {
91101
if (err) return done(err);

test/config/test.config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"lint": true,
3+
"minify": false,
4+
"use": [
5+
"postcss-property-lookup"
6+
],
7+
"autoprefixer": {
8+
"add": false,
9+
"remove": false
10+
}
11+
}

0 commit comments

Comments
 (0)