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

File Formats will be supported coffee-script #8

Closed
wants to merge 1 commit into from
Closed
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 config/default.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports =
AnotherModule: parm3: "value3"
Customers:
dbName: "from_default_coffee"
11 changes: 9 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var Sys = require('sys'),
File = require('fs'),
Yaml = require('yaml'),
Coffee = require('coffee-script'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this format. The pull request looks good.

In order to merge the request and publish a new branch it will need to be accompanied with a test. If you would like to write it, then I'll publish as soon as it's ready. Otherwise I can write it, but it'll be a week or two before I can get to it.

It's actually very easy. Create a .coffee configuration and test it in test/2-config-test.js. You can see how other formats are tested in there.

The current branch is v0.4.9. I will create it in github so you can attach the pull request to that branch.

Thanks,
-Loren

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

I want to try writing configuration and test in few days.
and work at current branch.

my English is not good.

FileSystem = require('fs');

// Static members
Expand Down Expand Up @@ -514,7 +515,8 @@ Config.prototype._persistConfigsOnChange = function(objectToWatch) {
* </pre>
*
* <p>
* EXT can be yaml, json, or js signifying the file type. yaml is in YAML format,
* EXT can be yaml, coffee, json, or js signifying the file type.
* yaml is in YAML format, coffee is a coffee-script,
* json is in strict JSON format, and js is a javascript executable file that is
* require()'d with module.exports being the config object.
* </p>
Expand Down Expand Up @@ -562,7 +564,7 @@ Config.prototype._loadFileConfigs = function() {

// Read each file in turn
var baseNames = ['default', hostName, deployment, hostName + '-' + deployment];
var extNames = ['js', 'json', 'yaml'];
var extNames = ['js', 'json', 'coffee', 'yaml'];
baseNames.forEach(function(baseName) {
extNames.forEach(function(extName) {
// Try merging the config object into this object
Expand Down Expand Up @@ -598,6 +600,7 @@ Config.prototype._loadFileConfigs = function() {
*
* .js = File to run that has a module.exports containing the config object
* .json = File is parsed using JSON.parse()
* .coffee = File to run that has a module.exports with coffee-script containing the config object
* .yaml = Parsed with a YAML parser
*
* If the file doesn't exist, a null will be returned.
Expand Down Expand Up @@ -654,6 +657,10 @@ Config.prototype._parseFile = function(fullFilename) {
// Use the built-in parser for .js files
configObject = require(fullFilename);
}
else if (extension == 'coffee') {
// Use the built-in parser for .coffee files with coffee-script
configObject = require(fullFilename);
}
}
catch (e3) {
throw new Error("Cannot parse config file: '" + fullFilename + "': " + e3);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"directories": {"lib": "./lib", "config": "./config", "test": "./test"},
"dependencies": {
"yaml" : "0.2.x",
"vows" : "0.5.x"
"vows" : "0.5.x",
"coffee-script" : ">=1.2.0"
},
"engines": {"node": ">0.4.x"},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions test/2-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ exports.ConfigTest = vows.describe('Test suite for node-config').addBatch({
assert.equal(CONFIG.AnotherModule.parm2, 'value2');
},

'Loading configurations from a Coffee-Script file is correct': function() {
assert.equal(CONFIG.AnotherModule.parm3, 'value3');
},

'Loading prior runtime.json configurations is correct': function() {
assert.equal(CONFIG.Customers.dbName, 'override_from_runtime_json');
}
Expand Down