Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[minor] Added support for custom installation hooks and added the gho…
…st app
  • Loading branch information
3rd-Eden committed Oct 29, 2013
1 parent f2a9412 commit 321ee95
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions lib/jitsu/commands/install.js
Expand Up @@ -36,28 +36,13 @@ var nodeapps = {
"http-server": {
"package": "http-server",
"description": " a robust and customizable http server"
},
"ghost": {
"package": "persistent-ghost",
"description": " the ghost blogging platform with MongoDB persistence"
}
};


/*
"web-http-client": {
"package": "web-http-client",
"description": "web based http-client ( with server-side proxy )"
},
"custom-vimeo-site": {
"package": "custom-vimeo-site",
"description": "custom homepage for your vimeo videos"
},
"my-nodeapps": {
"package": "nodeapps-my-nodeapps",
"description": "simple site to display your node apps"
}
*/

module.exports = function (requestedApp, callback) {
//
// Allows arbitrary amount of arguments
Expand Down Expand Up @@ -90,17 +75,17 @@ module.exports = function (requestedApp, callback) {
});

function createApp(results, cb) {
if (Object.keys(nodeapps).indexOf(results['starter']) === -1) {
jitsu.log.error('Sorry, ' + results['starter'].magenta + ' is not a node app');
if (Object.keys(nodeapps).indexOf(results.starter) === -1) {
jitsu.log.error('Sorry, ' + results.starter.magenta + ' is not a node app');
return cb('err');
}
installApp(results['starter'], function (err, res) {
return err ? cb(err) : postInstall(results['starter'], cb);

installApp(results.starter, function (err, res) {
return err ? cb(err) : postInstall(results.starter, cb);
});
}

function installApp(appName, cb) {

var thisPath = process.cwd();

jitsu.log.info('Installing ' + appName.magenta + ' locally');
Expand All @@ -111,19 +96,21 @@ module.exports = function (requestedApp, callback) {
}

cpr(path.join(thisPath + '/' + appName, 'node_modules', nodeapps[appName].package), thisPath + '/' + appName, function (err) {

if (err) {
return cb(err);
}

//
// Read current package.json
//
var pkg = JSON.parse(fs.readFileSync(thisPath + '/' + appName + '/package.json').toString());
var pkg = JSON.parse(fs.readFileSync(thisPath + '/' + appName + '/package.json').toString()),
installhook = pkg['jitsu-install'];

//
// Strip out any un-needed internal ids
// Strip out any un-needed internal ids and our custom `jitsu-install`
// hook.
//
delete pkg['jitsu-install'];
for(var k in pkg) {
if (k.search("_") !== -1) {
delete pkg[k];
Expand All @@ -135,16 +122,23 @@ module.exports = function (requestedApp, callback) {
//
fs.writeFileSync(thisPath + '/' + appName + '/package.json', JSON.stringify(pkg, true, 2));

return cb(err, result);
if (!installhook) return cb(err, result);

//
// We got a custom `jitsu install` hook that needs to be ran.
//
require(thisPath + '/' + appName + '/'+ installhook)(jitsu, function (err) {
cb(err, result);
});
});
});
}

function promptforAppName(cb) {

jitsu.log.help('The ' + 'install'.magenta + ' command downloads pre-built node apps');
jitsu.log.info('Please select a node app to get started');
jitsu.log.info('Available node apps:');

Object.keys(nodeapps).forEach(function (starter) {
jitsu.log.info(starter.magenta + ' ' + nodeapps[starter].description);
});
Expand All @@ -159,7 +153,6 @@ module.exports = function (requestedApp, callback) {
}

function postInstall(appName, cb) {

app.name = appName;

jitsu.log.info(app.name.magenta + ' installed');
Expand All @@ -184,8 +177,7 @@ module.exports = function (requestedApp, callback) {
}

function configureApp (schema, cb) {

jitsu.log.info('Attempting to configure app based on ' + './config/schema.json'.grey )
jitsu.log.info('Attempting to configure app based on ' + './config/schema.json'.grey);
jitsu.log.help('Prompting for ' + app.name.magenta + ' configuration data');
jitsu.log.help('Press ' + '[ENTER]'.grey + ' to specify default values');

Expand Down Expand Up @@ -229,7 +221,7 @@ module.exports = function (requestedApp, callback) {
jitsu.log.warn('Cancelled');
return cb(null, 'Cancelled');
}
return results['start_local'] === 'yes'
return results.start_local === 'yes'
? startApp('local', cb)
: cb(null);
});
Expand All @@ -252,7 +244,7 @@ module.exports = function (requestedApp, callback) {
if (err) {
return cb(err);
}

jitsu.log.info('The app has been created successfully. Deploying!');
jitsu.log.info('Run additional deployments using `jitsu deploy`');
return jitsu.plugins.cli.executeCommand(['deploy'],callback);
Expand Down

0 comments on commit 321ee95

Please sign in to comment.