Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #187 from Financial-Times/tidy
Browse files Browse the repository at this point in the history
Add logs (by default) to nbt destroy command; start to ween this module off of haikro and onto the heroku cli
  • Loading branch information
matthew-andrews committed Aug 22, 2015
2 parents 0090a17 + 556de17 commit 75b5228
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
nightwatch [options] [test] runs nightwatch with some sensible defaults
deploy-hashed-assets deploys hashed asset files to S3 (if AWS keys set correctly)
build [options] build javascript and css
destroy [app] deletes the app from heroku
destroy [options] [app] deletes the app from heroku
purge [options] [url] purges the given url from the Fastly cache. Requires a FASTLY_KEY environment variable set to your fastly api key
deploy-vcl [options] [folder] Deploys VCL in [folder] to the specified fastly service. Requires FASTLY_KEY env var
run [options] Runs the local app through the router
Expand Down
8 changes: 6 additions & 2 deletions bin/next-build-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,14 @@ program

program
.command('destroy [app]')
.option('--skip-logs', 'skips trying to output the logs before destroying the app')
.description('deletes the app from heroku')
.action(function(app) {
.action(function(app, options) {
if (app) {
destroy(app).catch(exit);
destroy({
app: app,
verbose: !options.skipLogs
}).catch(exit);
} else {
exit("Please provide an app name");
}
Expand Down
36 changes: 36 additions & 0 deletions lib/spawn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var spawn = require('child_process').spawn;

module.exports = function(processToRun, options) {
if (options.verbose) {
console.log("About to spawn " + processToRun.join(' '));
}
return new Promise(function(resolve, reject) {
var command = processToRun.shift();
var local = spawn.call(null, command, processToRun);

function toStdErr(data) {
console.warn(command + " error: " + data.toString());
}
function toStdOut(data) {
console.log(command + " output: " + data.toString());
}

if (options.verbose) {
local.stdout.on('data', toStdOut);
local.stderr.on('data', toStdErr);
}
local.on('error', reject);
local.on('close', function(code) {
if (code === 0) {
resolve();
} else {
if (options.verbose) {
toStdErr(processToRun.join(' ') + ' exited with exit code ' + code);
}
reject();
}
});
});
};
22 changes: 12 additions & 10 deletions tasks/destroy.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"use strict";

var destroy = require('haikro/lib/destroy');
var herokuAuthToken = require('../lib/heroku-auth-token');
var logger = require('haikro/lib/logger');
var spawn = require('../lib/spawn');

module.exports = function(app) {
logger.setLevel('debug');
return herokuAuthToken()
.then(function(token) {
return destroy({
app: app,
token: token
module.exports = function(options) {
var app = options.app;
var verbose = options.verbose;
var promise = Promise.resolve();
if (verbose) {
promise = promise.then(function() {
return spawn(['heroku', 'logs', '-a', app], { verbose: true });
});
}
promise = promise.then(function() {
return spawn(['heroku', 'destroy', '-a', app, '--confirm', app], { verbose: true });
});
return promise;
};
2 changes: 1 addition & 1 deletion tasks/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function toStdErr(data) {
process.stderr.write(data.toString());
}

function configureAndSpawn (opts, func) {
function configureAndSpawn(opts, func) {
return keys()
.then(function(env) {
// Overwrite any key specified locally
Expand Down

0 comments on commit 75b5228

Please sign in to comment.