Skip to content
Browse files

Switch to using node-config

  • Loading branch information...
1 parent 1765535 commit 82a1fd0e4d7719d485a030ee18cf172b2992fd32 @guyht committed
Showing with 41 additions and 40 deletions.
  1. +6 −1 README.md
  2. 0 glog_config.sample.json → config/default.sample.json
  3. +19 −24 lib/glog.js
  4. +16 −15 package.json
View
7 README.md
@@ -1,5 +1,8 @@
[![Build Status](https://secure.travis-ci.org/guyht/Glog.png)](http://travis-ci.org/guyht/Glog)
+### Upgrading to version 2x
+As of version 2, Glog is using the [node-config](https://github.com/lorenwest/node-config) module to handle configuration. While this is a step forward for Glog, allowing you to easily fine tune configuration for your environments, it means that the name and location of the config file has changed. See the configuration section below.
+
The Glog Blog
=============
@@ -79,7 +82,9 @@ The entire blog content is parsed and loaded into memory. Whenever a new articl
# Configuration options
-These options should be placed in glog_cofig.json and should be valid JSON
+Glog has recently switched to using [node-config](https://github.com/lorenwest/node-config). This new library makes handling different configuration for different environments a breze. To get you up and running, the following instructions are all you need, but if you would like to setup different configurations for different environments, take a peek at the node-config documentation.
+
+These options should be placed in config/default.json (the default configuration file) and should be valid JSON
blog_repository - The url of the blog repository (e.g. git@github.com:guyht/Guido.git)
author - The default blog author (will be used if author is not specified in an individual post)
View
0 glog_config.sample.json → config/default.sample.json
File renamed without changes.
View
43 lib/glog.js
@@ -7,7 +7,8 @@ var path = require('path'),
jade = require('jade'),
exec = require('child_process').exec,
rss = require('rss'),
- async = require('async');
+ async = require('async'),
+ config = require('config');
/*
@@ -40,35 +41,29 @@ Glog.prototype.load_configs = function(cb) {
fn = this,
key;
- fs.readFile(path.join('glog_config.json'), 'UTF-8', function(err, data) {
- if(err) {
- fn.handle_error('Could not load configuration file. This should be named glog_config.json. Err: ' + err);
- }
-
- var configs = JSON.parse(data);
+ // Check mandatory configs
+ if(!config.port) {
+ fn.handle_error('port is not defined in glog_config.json. This should be set to the port number you wish the blog to run on');
+ process.exit();
+ }
- // Check mandatory configs
- if(!configs.port) {
- fn.handle_error('port is not defined in glog_config.json. This should be set to the port number you wish the blog to run on');
- process.exit();
- }
+ if(!config.blog_repository) {
+ fn.handle_error('blog_repository is not defined in glog_config.json. This should point to the git repository of the blog content');
+ process.exit();
+ }
- if(!configs.blog_repository) {
- fn.handle_error('blog_repository is not defined in glog_config.json. This should point to the git repository of the blog content');
- process.exit();
- }
+ if(!config.author) {
+ fn.handle_error('author is not defined in glog_config.json. This should be the default blog author');
+ process.exit();
+ }
- if(!configs.author) {
- fn.handle_error('author is not defined in glog_config.json. This should be the default blog author');
- process.exit();
- }
+ for(key in config) {
+ options[key] = config[key];
+ }
- for(key in configs) {
- options[key] = configs[key];
- }
+ console.log(JSON.stringify(options));
cb(options);
- });
}
View
31 package.json
@@ -1,17 +1,18 @@
{
- "name" : "Glog",
- "version" : "1.3.0",
- "author" : "Guy Halford-Thompson",
- "repository" : "git://github.com/guyht/Glog",
- "dependencies" : {
- "express":"~2",
- "marked" : ">= 0.1.4",
- "jade" : ">= 0.19.0",
- "mocha": ">= 0.8.2",
- "rss": ">= 0.0.3",
- "async" : ">= 0.1.22"
- },
- "scripts": {
- "test": "make test"
- }
+ "name": "Glog",
+ "version": "2.0.0",
+ "author": "Guy Halford-Thompson",
+ "repository": "git://github.com/guyht/Glog",
+ "dependencies": {
+ "express": "~2",
+ "marked": ">= 0.1.4",
+ "jade": ">= 0.19.0",
+ "mocha": ">= 0.8.2",
+ "rss": ">= 0.0.3",
+ "async": ">= 0.1.22",
+ "config": "~0.4.17"
+ },
+ "scripts": {
+ "test": "make test"
+ }
}

0 comments on commit 82a1fd0

Please sign in to comment.
Something went wrong with that request. Please try again.