Permalink
Browse files

New approach

  • Loading branch information...
1 parent 643085b commit c415896d3ec6c3b27f35e78be11ea58433586bdb @bengourley committed Nov 23, 2011
Showing with 178 additions and 46 deletions.
  1. +14 −0 .gitignore
  2. +5 −0 index.js
  3. +58 −0 lib/action.js
  4. +101 −45 lib/index.js
  5. +0 −1 package.json
View
@@ -0,0 +1,14 @@
+node_modules/*
+.DS_STORE
+*.swp
+*.monitor
+nodemon-ignore
+site/public/stylesheets/*.css
+.*.sw[a-z]
+*.un~i
+.DS_Store
+Icon?
+._*
+.Spotlight-V100
+.Trashes
+*.minj.js
View
@@ -0,0 +1,5 @@
+module.exports = function (share) {
+ namespace('launch', function () {
+ require('./lib')(share);
+ });
+};
View
@@ -0,0 +1,58 @@
+var spawn = require('child_process').spawn;
+
+require('./colors');
+
+exports.error = function (message) {
+ console.log('Error:'.red + ' ' + message);
+};
+
+exports.printItem = function (prefix, item) {
+ console.log(prefix);
+ Object.keys(item).forEach(function (key) {
+ console.log('|-- ' + key + ': ' + item[key]);
+ });
+};
+
+exports.remote = function (host, cmd, callback) {
+ var ssh = spawn('ssh', [host, cmd]);
+
+ process.stdout.write(('\n $ ssh ' + host + ' ' + cmd + '\n ').blue);
+
+ ssh.stdout.on('data', function (data) {
+ process.stdout.write(('' + data).replace('\n', '\n ').grey);
+ });
+
+ ssh.stderr.on('data', function (data) {
+ process.stdout.write(('' + data).replace('\n', '\n ').red);
+ });
+
+ ssh.on('exit', function (code) {
+ callback(code);
+ });
+
+ ssh.stdin.end();
+};
+
+
+exports.local = function (cmd, callback) {
+ cmd = cmd.split(' ');
+ var pname = cmd.shift(),
+ proc = spawn(pname, cmd);
+
+ console.log(('\n $ ' + pname + ' ' + cmd.join(' ')).blue);
+ process.stdout.write('\n ');
+
+ proc.stdout.on('data', function (data) {
+ process.stdout.write(('' + data).replace(/\n/g, '\n ').grey);
+ });
+
+ proc.stderr.on('data', function (data) {
+ process.stdout.write(('' + data).replace(/\n/g, '\n ').red);
+ });
+
+ proc.on('exit', function (code) {
+ callback(code);
+ });
+
+ proc.stdin.end();
+};
View
@@ -1,52 +1,108 @@
-var colors = require('./colors'),
- spawn = require('child_process').spawn,
- fs = require('fs');
+module.exports = function (share) {
+
+ var spawn = require('child_process').spawn,
+ fs = require('fs'),
+ action = require('./action');
-function error(message) {
- console.log('Error:'.red + ' ' + message);
-}
+ /*
+ action.local('git --work-tree="' + tmpdir + '" checkout -f', function (exitcode) {
+ if (exitcode === 0) {
+ //local('rsync -ar /tmp/ rubble:' + launchconf.directory + launchconf.name);
+ console.log('Git work tree checkout out, then do this:');
+ console.log('rsync -ar /tmp/ rubble:' + launchconf.directory + launchconf.name);
+*/
+
+
+ desc('Parse relevant information from `package.json`');
+ task('info', function () {
+
+ fs.readFile('./package.json', function (err, data) {
+
+ if (err) {
+ action.error('Make sure a `package.json` file exists in the root of the project');
+ return;
+ }
+
+ var pkg = JSON.parse(data);
+
+ if (!pkg.launchconf) {
+ action.error('launch requires `launchconf` to be set in `package.json`');
+ return;
+ }
+
+ if (!pkg.launchconf.remote || !pkg.launchconf.remotepath) {
+ action.error('launch requires certain `launchconf` properties to be set in `package.json`');
+ return;
+ }
+
+ share.info = {
+ name : pkg.name,
+ v : pkg.version || '?.?.?',
+ remote : pkg.launchconf.remote,
+ remotepath : pkg.launchconf.remotepath
+ };
+
+ complete();
-function setup(callback) {
-
- fs.readFile('./package.json', function (err, data) {
-
- if (err) {
- error('Make sure a `package.json` file exists in the root of the project');
- return;
- }
-
- var pkg = JSON.parse(data);
-
- if (!pkg.launchconf) {
- error('launch requires `launchconf` to be set in `package.json`');
- return;
- }
-
- if (!pkg.launchconf.remote || !pkg.launchconf.directory) {
- error('launch requires certain `launchconf` properties to be set in `package.json`');
- return;
- }
-
- callback({
- v : pkg.version || '?.?.?',
- remote : pkg.launchconf.remote,
- directory : pkg.launchconf.directory
});
- });
-}
+ }, true);
-function printItem(prefix, item) {
- console.log(prefix);
- Object.keys(item).forEach(function (key) {
- console.log('|-- ' + key + ': ' + item[key]);
- });
-}
+ desc('Put contents of repository to remote server');
+ task('putremote', ['launch:checkout'], function () {
+ action.local('rsync -arv ' + share.tempdir + ' rubble:'
+ + share.info.remotepath + share.info.name, function (exitcode) {
+ if (exitcode === 0) {
+ jake.Task['launch:removeoldtempdir'].execute();
+ complete();
+ } else {
+ action.error('Could not put repo to remote');
+ fail();
+ }
+ });
+ }, true);
+
+
+ desc('Checkout a copy of the repository to a temporary directory');
+ task('checkout', ['launch:createtempdir'], function () {
+ action.local('git --work-tree=' +
+ share.tempdir + ' checkout -f', function (exitcode) {
+
+ if (exitcode === 0) {
+ complete();
+ } else {
+ console.log(exitcode);
+ action.error('Could not checkout a copy of the repo');
+ fail();
+ }
+
+ });
+ }, true);
+
+ desc('Creates a temporary directory');
+ task('createtempdir', ['launch:removeoldtempdir'], function () {
+ action.local('mkdir ' + share.tempdir, function (exitcode) {
+ if (exitcode === 0) {
+ complete();
+ } else {
+ action.error('Could not create temporary directory');
+ fail();
+ }
+ });
+ }, true);
+
+ desc('Removes old temporary directories');
+ task('removeoldtempdir', ['launch:info'], function () {
+ share.tempdir = '/tmp/' + share.info.name + '-launch';
+ action.local('rm -rf ' + share.tempdir, function (exitcode) {
+ if (exitcode === 0) {
+ complete();
+ } else {
+ action.error('Could not remove old temporary directory');
+ fail();
+ }
+ });
+ }, true);
-setup(function (launchconf) {
-
- exports.print = function () {
- printItem('Launch details:', launchconf);
- };
-});
+};
View
@@ -6,6 +6,5 @@
"bin": { "launch" : "./bin/launch" },
"engines" : { "node" : "*" },
"dependencies" : {
- "commander" : ">=0"
}
}

0 comments on commit c415896

Please sign in to comment.