// ## Dependencies.

var 
   nconf = require('nconf')
   , path = require('path')
   , fs = require('fs')
;

var configFile = process.cwd() + '/config.json';

var addDefaultConfig = function() {
	
	var defaultConfig = {
		"development": { "url": "http://localhost:3000", "port": 3000, "redis": { "port": 6379, "address": "localhost" } },
		"live": { "url": "http://localhost", "port": 80, "redis": { "port": 6379, "address": "localhost" } }
	}
	
	defaultConfig = JSON.stringify(defaultConfig, null, '\t');
	
	fs.writeFileSync(configFile, defaultConfig);
}

var addSampleBundle = function() {
	var bundlesFolder =  process.cwd());
	if (fs.existsSync(bundlesFolder + '/bundles')) {
		bundlesFolder += '/bundles';
	}
	var sampleFile = bundlesFolder + '/sample.js';
	var sample = "var spashttp = require(\"spas-http\");\n\nexports.sample = {\n\t\"searchTweets\": {\n\t\t\"resource\": spashttp.request,\n\t\t\"params\": {\n\t\t\t\"url\": \"http://search.twitter.com/search.json\",\n\t\t\t\"q\": \"dtex\",\n\t\t\t\"lang\": \"en\",\n\t\t\t\"count\": 100 \n\t\t},\n\t\t\"cacheduration\": 3600,\n\t\t\"timeout\": 500,\n\t\t\"filter\": {\n\t\t\t\"results\": [{\n\t\t\t\t\"from_user\": true,\n\t\t\t\t\"text\": true }]\n\t\t}\n\t},\n\t\"searchMoreTweets\": {\n\t\t\"resource\": spashttp.request,\n\t\t\"params\": {\n\t\t\t\"url\": \"http://search.twitter.com/search.json\",\n\t\t\t\"q\":\"spas\",\n\t\t\t\"lang\": \"en\" \n\t\t},\n\t\t\"cacheduration\": 3600\n\t}\n}";
	fs.writeFileSync(sampleFile, sample);
}

var addPackageJson = function() {
	var packageFile = process.cwd() + '/package.json';
	var myPackage = "{\n\t\"description\": \"spas instance\",\n\t\"version\": \"0.0.0\",\n\t\"private\": true, \n\t\"dependencies\": {\n\t\t\"spas-youtube\": \"0.1.x\",\n\t\t\"spas-flickr\": \"0.1.x\",\n\t\t\"spas-smugmug\": \"0.1.x\",\n\t\t\"spas-http\": \"0.1.x\",\n\t\t\"underscore\": \"1.x.x\"\n\t}\n}";
	fs.writeFileSync(packageFile, myPackage);
}

// Find our config file and make sure it exists
if ( fs.existsSync(configFile) === false ) addDefaultConfig();

// Use nconf to grab commandline params and read config.json
nconf.argv().file({ file: configFile });

// If --create was passed in the commandline, create sample.js and package.json
if ( nconf.get ('create')) {
	addSampleBundle();
	addPackageJson();
}

// If --dev is passed use the development config section
exports.config = (nconf.get('dev') ? nconf.get('development') : nconf.get('live'));

exports.nconf = nconf;


@@ -554,949 +554,8 @@
 %0A%7D%0A%0A
-var addSampleBundle = function() %7B%0A%09var bundlesFolder =  process.cwd());%0A%09if (fs.existsSync(bundlesFolder + '/bundles')) %7B%0A%09%09bundlesFolder += '/bundles';%0A%09%7D%0A%09var sampleFile = bundlesFolder + '/sample.js';%0A%09var sample = %22var spashttp = require(%5C%22spas-http%5C%22);%5Cn%5Cnexports.sample = %7B%5Cn%5Ct%5C%22searchTweets%5C%22: %7B%5Cn%5Ct%5Ct%5C%22resource%5C%22: spashttp.request,%5Cn%5Ct%5Ct%5C%22params%5C%22: %7B%5Cn%5Ct%5Ct%5Ct%5C%22url%5C%22: %5C%22http://search.twitter.com/search.json%5C%22,%5Cn%5Ct%5Ct%5Ct%5C%22q%5C%22: %5C%22dtex%5C%22,%5Cn%5Ct%5Ct%5Ct%5C%22lang%5C%22: %5C%22en%5C%22,%5Cn%5Ct%5Ct%5Ct%5C%22count%5C%22: 100 %5Cn%5Ct%5Ct%7D,%5Cn%5Ct%5Ct%5C%22cacheduration%5C%22: 3600,%5Cn%5Ct%5Ct%5C%22timeout%5C%22: 500,%5Cn%5Ct%5Ct%5C%22filter%5C%22: %7B%5Cn%5Ct%5Ct%5Ct%5C%22results%5C%22: %5B%7B%5Cn%5Ct%5Ct%5Ct%5Ct%5C%22from_user%5C%22: true,%5Cn%5Ct%5Ct%5Ct%5Ct%5C%22text%5C%22: true %7D%5D%5Cn%5Ct%5Ct%7D%5Cn%5Ct%7D,%5Cn%5Ct%5C%22searchMoreTweets%5C%22: %7B%5Cn%5Ct%5Ct%5C%22resource%5C%22: spashttp.request,%5Cn%5Ct%5Ct%5C%22params%5C%22: %7B%5Cn%5Ct%5Ct%5Ct%5C%22url%5C%22: %5C%22http://search.twitter.com/search.json%5C%22,%5Cn%5Ct%5Ct%5Ct%5C%22q%5C%22:%5C%22spas%5C%22,%5Cn%5Ct%5Ct%5Ct%5C%22lang%5C%22: %5C%22en%5C%22 %5Cn%5Ct%5Ct%7D,%5Cn%5Ct%5Ct%5C%22cacheduration%5C%22: 3600%5Cn%5Ct%7D%5Cn%7D%22;%0A%09fs.writeFileSync(sampleFile, sample);%0A%7D
 %0A%0Ava
@@ -1317,28 +1317,8 @@
 ) %7B%0A
-%09addSampleBundle();%0A
 %09add

Move addSampleBundle to bundle manager