Skip to content

Commit

Permalink
Merge pull request #1 from heroku/run
Browse files Browse the repository at this point in the history
added run command
  • Loading branch information
jdx committed Jun 19, 2018
1 parent f15cdff commit 333b2b8
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 50 deletions.
3 changes: 2 additions & 1 deletion packages/heroku-local/Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
web: echo "it works!"
web: echo "it works (web)!"
worker: echo "it works (worker)!"
2 changes: 2 additions & 0 deletions packages/heroku-local/Procfile.alternate
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: echo "it works (web) (alternate)!"
worker: echo "it works (worker) (alternate)!"
29 changes: 29 additions & 0 deletions packages/heroku-local/commands/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

let Forego = require('../lib/forego');
let cli = require('heroku-cli-util');

function* run (context) {
if (context.args.length < 1) {
cli.error('Usage: heroku local:run [COMMAND]\nMust specify command to run');
process.exit(-1);
}
let forego = new Forego(context.herokuDir);
yield forego.ensureSetup();
forego.run(context.args, {flags: context.flags});
}

module.exports = {
topic: 'local',
command: 'run',
description: 'run a one-off command',
help: `Example:
heroku local:run bin/migrate`,
variableArgs: true,
flags: [
{name: 'env', char: 'e', hasValue: true},
{name: 'port', char: 'p', hasValue: true}
],
run: cli.command(run)
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
'use strict';
let Forego = require('../forego');
let h = require('heroku-cli-util');

let Forego = require('../lib/forego');
let cli = require('heroku-cli-util');

function* run (context) {
let forego = new Forego(context.herokuDir);
yield forego.ensureSetup();
forego.start({args: context.args, flags: context.flags});
}

module.exports = {
topic: 'local',
command: 'start',
description: 'run heroku app locally',
default: true,
help: `Start the application specified by a Procfile (defaults to ./Procfile)
Examples:
Expand All @@ -20,9 +29,5 @@ Examples:
{name: 'port', char: 'p', hasValue: true},
{name: 'r', char: 'r', hasValue: false}
],
run: h.command(function* (ctx) {
let forego = new Forego(ctx.herokuDir);
yield forego.ensureSetup();
forego.start({args: ctx.args, flags: ctx.flags});
})
run: cli.command(run)
};
18 changes: 18 additions & 0 deletions packages/heroku-local/commands/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

let Forego = require('../lib/forego');
let cli = require('heroku-cli-util');

function* run (context) {
let forego = new Forego(context.herokuDir);
yield forego.ensureSetup();
forego.version();
}

module.exports = {
topic: 'local',
command: 'version',
description: 'display forego version',
help: 'Display forego version',
run: cli.command(run)
};
9 changes: 5 additions & 4 deletions packages/heroku-local/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
exports.topics = [{
exports.topic = {
name: 'local',
description: 'run heroku app locally'
}];
};

exports.commands = [
require('./lib/commands/local'),
require('./lib/commands/version')
require('./commands/start'),
require('./commands/run'),
require('./commands/version')
];
15 changes: 0 additions & 15 deletions packages/heroku-local/lib/commands/version.js

This file was deleted.

37 changes: 15 additions & 22 deletions packages/heroku-local/lib/forego.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,25 @@ function Forego(dir) {

Forego.prototype = {
version: function () {
spawn(this.path, ['version'], { stdio: [0, 1, 2] });
spawn(this.path, ['version'], { stdio: 'inherit' });
},

start: function (opts) {
let args = ['start'];
if (opts.args.processname) {
args.push(opts.args.processname);
}
if (opts.flags.procfile) {
args.push('-f', opts.flags.procfile);
}
if (opts.flags.env) {
args.push('-e', opts.flags.env);
}
if (opts.flags.concurrency) {
args.push('-c', opts.flags.concurrency);
}
if (opts.flags.port) {
args.push('-p', opts.flags.port);
}
if (opts.flags.r) {
args.push('-r');
}
spawn(this.path, args, {
stdio: [0, 1, 2]
});
if (opts.flags.procfile) args.push('-f', opts.flags.procfile);
if (opts.flags.env) args.push('-e', opts.flags.env);
if (opts.flags.concurrency) args.push('-c', opts.flags.concurrency);
if (opts.flags.port) args.push('-p', opts.flags.port);
if (opts.flags.r) args.push('-r');
if (opts.args.processname) args.push(opts.args.processname);
spawn(this.path, args, {stdio: 'inherit'});
},

run: function (args, opts) {
if (opts.flags.env) args.unshift('-e', opts.flags.env);
if (opts.flags.port) args.unshift('-p', opts.flags.port);
args.unshift('run');
spawn(this.path, args, {stdio: 'inherit'});
},

ensureSetup: function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/heroku-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"license": "ISC",
"dependencies": {
"heroku-cli-util": "^1.10.3",
"heroku-cli-util": "^5.3.0",
"request": "^2.53.0"
}
}

0 comments on commit 333b2b8

Please sign in to comment.