Permalink
Browse files

Merge

  • Loading branch information...
1 parent cfdbc41 commit 4f1411a6af8434d120255e067a48adcdc5129bc7 @DanBUK DanBUK committed Feb 11, 2011
Showing with 950 additions and 517 deletions.
  1. +81 −516 bin/nodester.js
  2. +237 −0 lib/app.js
  3. +73 −0 lib/appdomain.js
  4. +39 −0 lib/apps.js
  5. +93 −0 lib/config.js
  6. +33 −0 lib/coupon.js
  7. +28 −0 lib/log.js
  8. +125 −0 lib/npm.js
  9. +20 −0 lib/status.js
  10. +218 −0 lib/user.js
  11. +3 −1 package.json
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,237 @@
+var node = require('nodester-api').nodester,
+ config = require('./config'),
+ log = require('./log'),
+ exec = require('child_process').exec,
+ fs = require('fs');
+
+
+module.exports = {
+ usage: function() {
+ log.usage('<appname> is not required if inside an app directory after you call setup');
+ log.usage('app setup <appname> - Configure this app for future app commands');
+ log.usage('app info <appname> - Returns app specific information');
+ log.usage('app logs <appname> - Returns app logs');
+ log.usage('app stop|start|restart <appname> - Controls app status.');
+ log.usage('app create <appname> <startfile> - Creates a new app named <appname>, <startfile> is optional.');
+ log.usage('app init <appname> - Fetches the remote repo and sets it up.');
+ log.usage('app clone <appname> - Fetches the remote repo.');
+ },
+ setup: function(args) {
+ if (!args.length) {
+ log.error('appname required');
+ }
+ config.writeApp(args[0]);
+ },
+ info: function(args) {
+ config.check();
+ var appname = config.appname;
+ if (args.length) {
+ appname = args[0];
+ }
+ log.info('Gathering information about:', appname);
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.app_info(appname, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ var l = 'info', r = data.running;
+ if (data.running == false || data.running.indexOf('error') > -1) {
+ l = 'warn';
+ if (r === false) {
+ r = 'false'
+ }
+ r = r.red;
+ }
+ log[l](appname, 'on port', data.port, 'running:', r.bold);
+ log.info('gitrepo:', data.gitrepo);
+ log.info('appfile:', data.start);
+ });
+ },
+ logs: function(args) {
+ config.check();
+ var appname = config.appname;
+ if (args.length) {
+ appname = args[0];
+ }
+
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.app_logs(appname, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.lines && data.lines.length && data.lines[0] !== '') {
+ data.lines.forEach(function(l) {
+ log.info(l);
+ });
+ } else {
+ log.warn('no log data returned.');
+ }
+ });
+
+ },
+ stop: function(args) {
+ config.check();
+ var appname = config.appname;
+ if (args.length) {
+ appname = args[0];
+ }
+ log.info('Attemping to stop app:', appname);
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.app_stop(appname, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == "success") {
+ log.info('app stopped.');
+ } else {
+ log.warn(data.status);
+ }
+ });
+ },
+ start: function(args) {
+ config.check();
+ var appname = config.appname;
+ if (args.length) {
+ appname = args[0];
+ }
+ log.info('Attemping to start app:', appname);
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.app_start(appname, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == "success") {
+ log.info('app started.'.bold.green);
+ } else {
+ log.warn(data.status);
+ }
+ });
+ },
+ restart: function(args) {
+ config.check();
+ var appname = config.appname;
+ if (args.length) {
+ appname = args[0];
+ }
+ log.info('Attemping to restart app:', appname);
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.app_restart(appname, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == "success") {
+ log.info('app restarted.'.bold.green);
+ } else {
+ log.warn(data.status);
+ }
+ });
+ },
+ create: function(args) {
+ config.check();
+ if (!args.length) {
+ log.error('give this app a name');
+ }
+ var name = args[0];
+ var start = args[1] || 'server.js';
+ log.info('creating app:', name, start);
+
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.app_create(name, start, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == "success") {
+ log.info('successfully created app', name.bold, 'to will run on port', data.port.bold, 'from', start.bold);
+ log.info('run', config.brand, 'app init', name, ' to setup this app.');
+ } else {
+ log.error(data.status);
+ }
+ });
+ },
+ init: function(args) {
+ config.check();
+ if (args.length) {
+ var appname = folder = args[0];
+ if (args[1]) {
+ folder = args[1];
+ }
+ }
+ log.info('initializing git repo for', appname, 'into folder', folder);
+ try {
+ fs.mkdirSync(folder, 0750);
+ } catch (e) {
+ log.error(e.toString());
+ }
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.app_info(appname, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ log.info('cloning the repo', 'git clone ' + data.gitrepo + ' ' + folder);
+ var child = exec('git clone ' + data.gitrepo + ' ' + folder, function (error, stdout, stderr) {
+ var rcfile = config.writeApp(appname, folder);
+ fs.writeFileSync(folder + '/.gitignore', rcfile + "\n");
+
+ fs.writeFileSync(folder + '/' + data.start,
+ "var http = require('http');\n" +
+ "http.createServer(function (req, res) {\n" +
+ " res.writeHead(200, {'Content-Type': 'text/plain'});\n" +
+ " res.end('Hello World\\nApp (" + appname + ") is running..');\n" +
+ "}).listen(" + data.port + ");\n"
+ );
+
+ var child2 = exec('cd ' + folder + '; git add ' + data.start + ' .gitignore; git commit -m "Init via ' + config.brand + '"; git push origin master; ', function (error, stdout, stderr) {
+ nodeapi.app_stop(appname, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == "success") {
+ log.info(appname, "stopped.");
+ } else {
+ log.warn(data.status);
+ }
+ log.info('attemping to start the new app.');
+ nodeapi.app_start(appname, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == "success") {
+ log.info(appname, "started.");
+ } else {
+ log.warn(data.status);
+ }
+ });
+ });
+ });
+ });
+ });
+ },
+ clone: function(args) {
+ config.check();
+ if (args.length) {
+ var appname = folder = args[0];
+ if (args[1]) {
+ folder = args[1];
+ }
+ }
+ log.info('initializing git repo for', appname, 'into folder', folder);
+ try {
+ fs.mkdirSync(folder, 0750);
+ } catch (e) {
+ log.error(e.toString());
+ }
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.app_info(appname, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ log.info('cloning the repo', 'git clone ' + data.gitrepo + ' ' + folder);
+ var child = exec('git clone ' + data.gitrepo + ' ' + folder, function (error, stdout, stderr) {
+ var rcfile = config.writeApp(appname, folder);
+ fs.writeFileSync(folder + '/.gitignore', rcfile + "\n");
+ });
+ });
+
+ }
+}
+
View
@@ -0,0 +1,73 @@
+var node = require('nodester-api').nodester,
+ config = require('./config'),
+ log = require('./log');
+
+
+module.exports = {
+ usage: function() {
+ log.usage('In a configured app dir, <appname> is optional');
+ log.usage('appdomain add <appname> <domainname> - Add a domain router for this app');
+ log.usage('appdomain remove <appname> <domainname> - Remove a domain router from this app');
+ },
+ add: function(args) {
+ config.check();
+ var appname = config.appname,
+ domain;
+ if (args.length) {
+ if (args.length === 2) {
+ domain = args[1];
+ appname = args[0];
+ } else {
+ domain = args[0];
+ }
+ }
+ if (!domain) {
+ log.error('<domainname> required');
+ } else if (!appname) {
+ log.error('<appname> name required');
+ }
+ log.info('adding domain', domain, 'to', appname);
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.appdomain_add(appname, domain, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == 'success') {
+ log.info(data.message);
+ } else {
+ log.warn(data);
+ }
+ });
+ },
+ delete: function(args) {
+ config.check();
+ var appname = config.appname,
+ domain;
+ if (args.length) {
+ if (args.length === 2) {
+ domain = args[1];
+ appname = args[0];
+ } else {
+ domain = args[0];
+ }
+ }
+ if (!domain) {
+ log.error('<domainname> required');
+ } else if (!appname) {
+ log.error('<appname> name required');
+ }
+ log.info('removing domain', domain, 'from', appname);
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.appdomain_delete(appname, domain, function (err, data) {
+ if (err) {
+ log.error(err.message);
+ }
+ if (data.status == 'success') {
+ log.info(data.message);
+ } else {
+ log.warn(data);
+ }
+ });
+ }
+}
+
View
@@ -0,0 +1,39 @@
+var node = require('nodester-api').nodester,
+ config = require('./config'),
+ log = require('./log');
+
+
+module.exports = {
+ usage: function() {
+ log.usage('apps list - list all your registered apps');
+ },
+ run: function() {
+ //Placeholder for later adding more `cmd apps` commands
+ this.list();
+ },
+ list: function(args) {
+ config.check();
+ var nodeapi = new node(config.username, config.password, config.apihost);
+ nodeapi.apps_list(function (err, data) {
+ if (err) {
+ log.error(err);
+ }
+ if (data.length > 0) {
+ for(var i in data) {
+ var l = 'info', r = data[i].running;
+ if (data[i].running == false || data[i].running == 'false' || data[i].running.indexOf('error') > -1) {
+ l = 'warn';
+ if (r === false || r == 'false') {
+ r = 'false'
+ }
+ r = r.red;
+ }
+ log[l](data[i].name, 'on port', data[i].port, 'running:', r.bold);
+ }
+ } else {
+ log.warn('no apps to report');
+ }
+ });
+ }
+}
+
Oops, something went wrong.

0 comments on commit 4f1411a

Please sign in to comment.