Comparing version 0.0.1 to 0.0.2
var fs = require('fs'), | ||
util = require('util'); | ||
util = require('util'), | ||
colors = require('colors'); | ||
@@ -84,2 +85,59 @@ | ||
} | ||
} | ||
module.exports.showEconfContent = function(cb) { | ||
var path = process.cwd() + '/.econf.js'; | ||
fs.stat(path, function(err) { | ||
if (err) { | ||
console.log('File .econf.js not found'.red); | ||
console.log('To create .econf.js execute:'.yellow, 'econf init'); | ||
return; | ||
} | ||
var objects = require(path); | ||
objects = processHierarchy(objects); | ||
for(property in objects) { | ||
var object = objects[property]; | ||
var _extend = ''; | ||
if (object._extend) { | ||
_extend = [].concat(object._extend); | ||
_extend = _extend.join(', '); | ||
_extend = '{' + _extend + '}'; | ||
} | ||
console.log(''); | ||
console.log(property.green, _extend.yellow); | ||
delete object._name; | ||
delete object._extend; | ||
console.log(' ', JSON.stringify(object, null, ' ').replace(/\n/g, '\n ').grey); | ||
} | ||
if (cb) { | ||
cb(); | ||
} | ||
}) | ||
} | ||
module.exports.createEconfFile = function() { | ||
var file = fs.readFileSync(__dirname + '/../.econf.js'); | ||
fs.writeFileSync(process.cwd() + '/.econf.js', file); | ||
module.exports.showEconfContent(function() { | ||
console.log(''); | ||
console.log('###########################################'.yellow); | ||
console.log('### Do not forget to install econf lib ###'.yellow); | ||
console.log('### ###'.yellow); | ||
console.log('###'.yellow, 'npm install econf --save ', '###'.yellow); | ||
console.log('### ###'.yellow); | ||
console.log('### Do not forget to include econf lib ###'.yellow); | ||
console.log('### into your project at the first line ###'.yellow); | ||
console.log('### ###'.yellow); | ||
console.log('###'.yellow, 'require("econf")() ', '###'.yellow); | ||
console.log('### ###'.yellow); | ||
console.log('###########################################'.yellow); | ||
}); | ||
} |
{ | ||
"name": "econf", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Load configs from hierarchical objects to process.env", | ||
@@ -11,3 +11,11 @@ "scripts": { | ||
"license": "MIT", | ||
"main" : "./lib/index.js" | ||
"main": "./lib/index.js", | ||
"bin": { | ||
"econf": "bin/econf.js" | ||
}, | ||
"preferGlobal": "false", | ||
"dependencies": { | ||
"commander": "~2.1.0", | ||
"colors": "~0.6.2" | ||
} | ||
} |
@@ -24,2 +24,59 @@ econf | ||
require('econf')('config.js'); | ||
``` | ||
``` | ||
#.econf.js example | ||
```javascript | ||
module.exports = [ | ||
{ | ||
_name: 'newrelic', | ||
NEW_RELIC_KEY: 'key' | ||
}, | ||
{ | ||
_name: 'production', | ||
NAME: 'Production Base', | ||
AWS_SECRET: 'aws-secret', | ||
AWS_KEY: 'aws-key', | ||
EMAIL_DELAY: 1000 | ||
}, | ||
{ | ||
_name: 'production.001', | ||
_extend: ['production', 'newrelic'], | ||
NAME: 'Production 001', | ||
EMAIL_DELAY: 0 | ||
} | ||
] | ||
``` | ||
The config above will inject the code below into process.env | ||
```javascript | ||
{ | ||
"_name": "production.001", | ||
"_extend": [ | ||
"production", | ||
"newrelic" | ||
], | ||
"NAME": "Production 001", | ||
"EMAIL_DELAY": 0, | ||
"AWS_SECRET": "aws-secret", | ||
"AWS_KEY": "aws-key", | ||
"NEW_RELIC_KEY": "key" | ||
} | ||
``` | ||
#Global Usage | ||
```javascript | ||
npm install econf -g | ||
``` | ||
With global version you can view your config parsed, just execute econf into your project directory | ||
```javascript | ||
econf | ||
``` | ||
![econf](img/econf.png) | ||
To create a example .econf.js file into your project just execute econf init into your project directory | ||
```javascript | ||
econf init | ||
``` | ||
![econf](img/econf-init.png) |
process.env.NODE_ENV = 'production.001'; | ||
var env = require('../lib/index')(); | ||
console.log(JSON.stringify(process.env, null, ' ')); | ||
console.log(JSON.stringify(env, null, ' ')); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
98629
13
220
81
2
+ Addedcolors@~0.6.2
+ Addedcommander@~2.1.0
+ Addedcolors@0.6.2(transitive)
+ Addedcommander@2.1.0(transitive)