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

Support .cjs files #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@ load-grunt-config is a Grunt library that allows you to break up your Gruntfile
- Support for YAML files.
- Support for CSON files.
- Support for returning a function.
- [Easily register task aliases](#aliases) with `aliases.(js|json|yaml)`.
- [Easily register task aliases](#aliases) with `aliases.(js|cjs|json|yaml)`.
- [Config overrides](#custom-config)
- [Config grouping](#config-grouping)

Expand Down
2 changes: 1 addition & 1 deletion lib/readconfigdir.js
Expand Up @@ -11,7 +11,7 @@ module.exports = function(dir, grunt, options) {
return base;
};

var files = glob.sync('*.{js,json,yml,yaml,cson,ls}', { cwd: dir });
var files = glob.sync('*.{js,cjs,json,yml,yaml,cson,ls}', { cwd: dir });

var merge = options && options.mergeFunction || _.merge;

Expand Down
10 changes: 10 additions & 0 deletions test/config/cjsfun.cjs
@@ -0,0 +1,10 @@
module.exports = function (grunt, options) {
return {
cjsFunFile: {
options: {
filename: 'cjsfun.cjs',
test: options.test
}
}
};
};
8 changes: 8 additions & 0 deletions test/config/cjsobj.cjs
@@ -0,0 +1,8 @@
module.exports = {
cjsobjFile: {
options: {
filename: 'cjsobj.cjs',
debug: true
}
}
};
18 changes: 17 additions & 1 deletion test/fixtures/output.js
Expand Up @@ -27,6 +27,22 @@ module.exports = {
}
}
},
cjsfun: {
cjsFunFile: {
options: {
filename: 'cjsfun.cjs',
test: 1
}
}
},
cjsobj: {
cjsobjFile: {
options: {
filename: 'cjsobj.cjs',
debug: true
}
}
},
jsonfile: {
jsonFile: {
options: {
Expand All @@ -41,7 +57,7 @@ module.exports = {
filename: 'read.cson'
}
}
},
},
yamlfile: {
yamlFile: {
options: {
Expand Down
2 changes: 1 addition & 1 deletion test/gruntconfig.test.js
Expand Up @@ -231,7 +231,7 @@ suite('gruntConfig', function() {
]
};
gruntConfig(grunt, options);
assert.equal(spy.callCount, 8);
assert.equal(spy.callCount, 10);
});

});
2 changes: 1 addition & 1 deletion test/readconfigdir.test.js
Expand Up @@ -25,7 +25,7 @@ suite('readConfigDir', function() {
};

readConfigDir(__dirname+'/config', grunt, options);
assert.equal(spy.callCount, 7);
assert.equal(spy.callCount, 9);
});

test('multiconfig', function() {
Expand Down
14 changes: 14 additions & 0 deletions test/readfile.test.js
Expand Up @@ -48,6 +48,20 @@ suite('readfile', function() {
assert.equal(obj.jsFunFile.options.test, 1);
});

test('read cjs object file', function() {
var json = readfile(__dirname+'/config/cjsobj.cjs');
assert.equal(json.cjsobjFile.options.filename, 'cjsobj.cjs');
});

test('read cjs file with function, returns function', function() {
var fn = readfile(__dirname+'/config/cjsfun.cjs');
assert.equal(typeof fn, 'function');
//fn takes two args, grunt and options
var obj = fn({}, { test: 1 });
assert.equal(obj.cjsFunFile.options.filename, 'cjsfun.cjs');
assert.equal(obj.cjsFunFile.options.test, 1);
});

test('read unsupported file', function() {
assert.throws(function() {
readfile(__dirname+'/config/htmlfile.html');
Expand Down