Permalink
Browse files

Merge branch 'starters' of github.com:nodejitsu/jitsu into starters

  • Loading branch information...
2 parents 1e4183e + d34a1fc commit b9520c285a0c79e979e1e2bb2aeeb912cceb7175 @jfhbrook jfhbrook committed Oct 31, 2011
Showing with 214 additions and 94 deletions.
  1. +2 −1 lib/jitsu.js
  2. +1 −1 lib/jitsu/commands.js
  3. +0 −91 lib/jitsu/commands/init.js
  4. +196 −0 lib/jitsu/commands/install.js
  5. +14 −1 lib/jitsu/properties.js
  6. +1 −0 package.json
View
@@ -226,7 +226,8 @@ jitsu.auth = function (callback) {
// and saves the resulting configuration to disk.
//
jitsu.setupUser = function (callback) {
- winston.warn('No user has been setup on this machine');
+ winston.warn('You will need to login to continue');
+ winston.info('To login, you will need an activated nodejitsu account')
jitsu.setupUserNoWarn(callback);
};
View
@@ -19,7 +19,7 @@ fs.readdirSync(path.join(__dirname, 'commands')).forEach(function (cmd) {
});
});
-var requireAuth = ['apps', 'databases', 'env', 'logs', 'snapshots', 'init', 'knockout'];
+var requireAuth = ['apps', 'databases', 'env', 'logs', 'snapshots', 'knockout'];
commands.requiresAuth = function (resource) {
return requireAuth.indexOf(resource) !== -1;
View
@@ -1,91 +0,0 @@
-
-
-var jitsu = require('../../jitsu'),
- winston = require('winston'),
- ncp = require('ncp'),
- rimraf = require('rimraf'),
- path = require('path'),
- fs = require('fs'),
- npmModule = require('npm'),
- thisPath = process.cwd();
-
-var starters = {
- helloworld: 'helloworld',
- static: 'simple-static'
-}
-
-var init = module.exports = function (starterName, callback) {
- npmModule.load({exit:false}, function (err) {
- if (err) {
- return callback(err);
- }
- if(typeof callback === 'undefined') {
- callback = starterName;
- }
- if (typeof starterName === 'string') {
- return createStarter({starter: starterName}, callback);
- }
- promptforStarterName(callback);
- });
-
- function installStarter(starterName, cb) {
- npmModule.install(starterName, function(err, result){
- if (err) {
- return cb(err);
- }
- winston.info('Using starter: ' + starterName.magenta);
- ncp.ncp(thisPath + '/node_modules/' + starterName, thisPath, function (err) {
- if (err) {
- return cb(err);
- }
- rimraf(thisPath + '/node_modules', function (err) {
- cb(err, result);
- });
- });
- });
- }
-
- function promptforStarterName(cb) {
-
- winston.info('Please choose one of our starter apps so we can get you started.');
- winston.info('Available starter apps:');
- Object.keys(starters).forEach(function (starter) {
- winston.info(starter.cyan.bold);
- });
-
- jitsu.prompt.get(['starter'], function (err, results) {
- if (err) {
- return cb(err);
- }
- createStarter({ starter: results['starter'] }, callback);
- });
- }
-
- function createStarter(results, cb){
-
- if (Object.keys(starters).indexOf(results['starter']) === -1) {
- winston.error('Sorry, that\'s not a starter app.');
- return init(callback);
- }
- installStarter(starters[results['starter']], function (err, res) {
- if (err) {
- console.log(arguments)
- return cb(err);
- }
- winston.info('Jitsu will now help you create your package.json.');
- return jitsu.package.create(process.cwd(), function (err, result) {
- if (err) {
- return cb(err);
- }
- winston.info('Your app has been created successfully. Deploying!');
- winston.info('You can run additional deployments using `jitsu deploy`');
- return jitsu.commands.run(['deploy'], callback);
- });
- });
- }
-};
-
-init.usage = [
- 'jitsu init - helps you create a new server.js to use on Nodejitsu.',
- 'jitsu init [starter name] - specifies the starter app you want to use.'
-];
@@ -0,0 +1,196 @@
+
+
+var jitsu = require('../../jitsu'),
+ winston = require('winston'),
+ ncp = require('ncp'),
+ rimraf = require('rimraf'),
+ path = require('path'),
+ fs = require('fs'),
+ npmModule = require('npm'),
+ mkdirp = require('mkdirp'),
+ thisPath = process.cwd();
+
+
+//
+// "nodeapps" is a hash of aliases and npm packages,
+// this mapping allows us to give short names to all node apps
+//
+var nodeapps = {
+ "helloworld" : {
+ "package" : "nodeapps-helloworld",
+ "description" : "demo `hello world` http server"
+ },
+ "http-server" : {
+ "package" : "http-server",
+ "description" : "a robust and customizable http server"
+ },
+ "express" : {
+ "package" : "nodeapps-express",
+ "description" : "express.js boilerplate"
+ },
+ "socket.io" : {
+ "package" : "nodeapps-socket.io",
+ "description" : "socket.io boilerplate"
+ },
+ "dnode" : {
+ "package" : "nodeapps-dnode",
+ "description" : "dnode boilerplate"
+ },
+ "web-http-client" : {
+ "package" : "web-http-client",
+ "description" : "web based http-client ( with server-side proxy )"
+ },
+ "custom-vimeo-site" : {
+ "package" : "cu stom-vimeo-site",
+ "description" : "custom homepage for your vimeo videos"
+ },
+ "my-nodeapps" : {
+ "package" : "nodeapps-my-apps",
+ "description" : "simple site to display your node apps"
+ }
+};
+
+var install = module.exports = function (starterName, callback) {
+
+ npmModule.load({exit:false}, function (err) {
+ if (err) {
+ return callback(err);
+ }
+ if(typeof callback === 'undefined') {
+ callback = starterName;
+ starterName = null;
+ }
+ if (fs.readdirSync(thisPath).length !== 0) {
+ return warnOverwrite(starterName, callback);
+ }
+ if (typeof starterName === 'string') {
+ return createApp({starter: starterName}, callback);
+ }
+ promptforAppName(callback);
+ });
+
+ function installApp(starterName, cb) {
+ npmModule.install(nodeapps[starterName].package, function(err, result){
+ if (err) {
+ return cb(err);
+ }
+ winston.info('Installing ' + starterName.magenta + ' locally.');
+ ncp.ncp(thisPath + '/node_modules/' + nodeapps[starterName].package, thisPath, function (err) {
+ if (err) {
+ return cb(err);
+ }
+ cb(err, result);
+ });
+ });
+ }
+
+ function warnOverwrite(starterName, cb) {
+ winston.warn(process.cwd().grey + ' is not empty.');
+ winston.warn('Creating a node app in this directory may overwrite existing files.');
+ jitsu.prompt.get(['proceed'], function (err, results) {
+ if (err) {
+ return cb(err);
+ }
+ if (results['proceed'] !== 'yes') {
+ winston.info('Try switching to an empty directory to continue.');
+ return cb(null);
+ }
+ return starterName ? createApp({ starter: starterName }, cb) : promptforAppName(cb);
+ });
+ }
+
+ function promptforAppName(cb) {
+ winston.info('Please choose a node app so we can get you started.');
+ winston.info('Available node apps:');
+ Object.keys(nodeapps).forEach(function (starter) {
+ winston.info(starter.magenta + ' ' + nodeapps[starter].description);
+ });
+
+ jitsu.prompt.get(['starter'], function (err, results) {
+ if (err) {
+ return cb(err);
+ }
+ createApp({ starter: results['starter'] }, callback);
+ });
+ }
+
+ function createApp(results, cb) {
+ if (Object.keys(nodeapps).indexOf(results['starter']) === -1) {
+ winston.error('Sorry, ' + results['starter'].magenta + ' is not a starter app.');
+ return cb('err');
+ }
+ installApp(results['starter'], function (err, res) {
+ if (err) {
+ return cb(err);
+ }
+ return postInstall(results['starter'], cb);
+ });
+ }
+
+ function postInstall(starterName, cb) {
+
+ winston.info(starterName.magenta + ' installed.')
+ //winston.help('You can now use ' + 'jitsu deploy'.magenta + ' this application')
+
+ jitsu.prompt.get(['start_local'], function(err, results){
+ if (results['start_local'] !== 'yes') {
+ return cb(null);
+ }
+ return startApp('local', cb);
+ //return deployApp(cb);
+ });
+
+ }
+
+ function configApp(cb) {
+ // TODO
+ }
+
+
+ function startApp(dest, cb) {
+
+ var spawn = require('child_process').spawn,
+ app;
+
+ if (dest === "local") {
+ //
+ // Remark: It would be nice to use:
+ //
+ // npmModule.start(starterName, cb);
+ //
+ // but there is a conflict in package.json formats of `npm` versus `haibu`
+ // in the scripts.start property containing the word "node" in it
+ //
+ var pkg = JSON.parse(fs.readFileSync(process.cwd() + '/package.json').toString());
+ app = spawn('node', [pkg.scripts.start]);
+ app.stdout.on('data', function (data) {
+ winston.data(data);
+ });
+ app.stderr.on('data', function (data) {
+ winston.error(data);
+ });
+ app.on('exit', function (code) {
+ winston.data('Application exited ', code);
+ });
+ }
+
+ }
+
+ function deployApp(cb) {
+ winston.info('Jitsu will now help you create your package.json.');
+ return jitsu.package.create(process.cwd(), function (err, result) {
+ if (err) {
+ return cb(err);
+ }
+ winston.info('Your app has been created successfully. Deploying!');
+ winston.info('You can run additional deployments using `jitsu deploy`');
+ return jitsu.commands.run(['deploy'], callback);
+ });
+ }
+
+};
+
+install.usage = [
+ 'jitsu install - helps you create a new server.js to use on Nodejitsu.',
+ 'jitsu install [node app name] - specifies the starter app you want to use.'
+];
View
@@ -51,6 +51,12 @@ properties.properties = {
message: 'Which starter app would you like to use?',
default: 'helloworld'
},
+ proceed: {
+ name: 'proceed',
+ message: 'Proceed anyway?',
+ default: 'no',
+ validator: /^y[es]*|n[o]?$/
+ },
username: {
name: 'username',
validator: /^[\w|\-]+$/,
@@ -67,5 +73,12 @@ properties.properties = {
validator: /y[es]?|n[o]?/,
warning: 'Must respond yes or no',
default: 'no'
+ },
+ "start_local": {
+ name: 'start_local',
+ message: 'Would you like to start this application locally?',
+ validator: /y[es]?|n[o]?/,
+ warning: 'Must respond yes or no',
+ default: 'yes'
}
-};
+};
View
@@ -19,6 +19,7 @@
"cliff": "0.1.x",
"colors": "0.x.x",
"eyes": "0.1.x",
+ "mkdirp": "0.0.x",
"nconf": "0.2.x",
"npm": ">= 1.0.100 < 1.1.0",
"ncp": "0.1.x",

0 comments on commit b9520c2

Please sign in to comment.