Permalink
Browse files

[feature] more in linke with npm configs

  • Loading branch information...
1 parent f2902da commit 25b2810131fd1f76caf2f7a9b8e6ec1161f06b08 @bmeck committed Mar 21, 2013
Showing with 50 additions and 9 deletions.
  1. +2 −1 Readme.md
  2. +17 −2 bin/nam
  3. +26 −0 integrations/config.js
  4. +0 −1 integrations/run.js
  5. +4 −4 integrations/security.js
  6. +1 −1 lib/nam.js
View
3 Readme.md
@@ -9,7 +9,8 @@
## CONFIG
-TODO
+--userconfig
+--globalconfig
## ENV SCAFFOLDING
View
19 bin/nam
@@ -18,8 +18,23 @@ var path = require('path');
var NodeApplicationManager = require('../').NodeApplicationManager;
var scaffold = new NodeApplicationManager();
-scaffold.config = require('nconf').argv().env();
-scaffold.config.file(scaffold.config.get('config') || scaffold.config.get('c') || 'config.json');
+scaffold.config = require('nconf').use('memory').argv().defaults({
+ userconfig: path.join(process.env.HOME, '.namconf'),
+ globalconfig: path.join(process.config.variables.node_prefix, '/etc/namconf'),
+ task: {
+ run: {
+ user: 'nobody'
+ }
+ }
+});
+Object.keys(process.env).forEach(function (key) {
+ var conf_pattern = /^nam_config_/;
+ if (conf_pattern.test(key)) {
+ scaffold.config.set(key.replace(conf_pattern, '').replace(/[^0-9A-Za-z]/,':'), process.env[key]);
+ }
+});
+scaffold.config.add('userconfig', {type: 'file', file: scaffold.config.get('userconfig')});
+scaffold.config.add('globalconfig', {type: 'file', file: scaffold.config.get('globalconfig')});
var chdir = scaffold.config.get('cwd') || scaffold.config.get('C');
if (scaffold.config.get('cwd')) {
View
26 integrations/config.js
@@ -0,0 +1,26 @@
+//
+// Add `grunt` task with basic options
+// Should npm install first due to peerDeps possibilities
+//
+exports.name = 'grunt';
+exports.tasks = {
+ config: function (args, options, cb) {
+ if (!args) {
+ cb(new Error('config operation required'));
+ }
+ var operation = args.shift();
+ var key = null;
+ var value;
+ switch (operation) {
+ case 'get':
+ key = args.shift();
+ case 'list':
+ console.dir(this.config.get(key));
+ break;
+ default:
+ cb(new Error('unknown config operation '+JSON.stringify(operation)))
+ return;
+ }
+ cb(null);
+ }
+}
View
1 integrations/run.js
@@ -6,7 +6,6 @@ var path = require('path');
exports.name = 'run';
exports.tasks = {
run: function (args, options, cb) {
- console.log(arguments)
var scaffold = this;
var cmd = args.shift();
var env = options.env || {};
View
8 integrations/security.js
@@ -35,8 +35,8 @@ exports.actions = {
next(null, scaffold, options);
return;
}
- var uid = options.config.get('uid') || process.getuid();
- var gid = options.config.get('gid') || process.getgid();
+ var uid = options.config.get('user') || process.getuid();
+ var gid = options.config.get('group') || process.getgid();
uidNumber(uid, gid, function (err, uid, gid) {
if (err) {
next(err);
@@ -57,8 +57,8 @@ exports.actions = {
return;
}
var scaffold = this;
- var uid = options.config.get('uid');
- var gid = options.config.get('gid');
+ var uid = options.config.get('user');
+ var gid = options.config.get('group');
function setids(err, uid, gid) {
if (err) {
next(err);
View
2 lib/nam.js
@@ -19,7 +19,7 @@ function NodeApplicationManager(options) {
tmpdir: './tmp'
});
this.tasks = {};
- options.builtins = options.builtins || [require('../integrations/run')];
+ options.builtins = options.builtins || [require('../integrations/security'),require('../integrations/config'),require('../integrations/run')];
options.builtins.forEach(this.integrate.bind(this))
return this;
}

0 comments on commit 25b2810

Please sign in to comment.