Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
fix v6 (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored and RasPhilCo committed Apr 25, 2017
1 parent f17080c commit cf9c177
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tmp
/node_modules
8 changes: 4 additions & 4 deletions commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ function * run (context) {
process.exit(-1)
}

process.argv = ['', 'heroku local:run', 'run']
let execArgv = ['run']

if (context.flags.env) process.argv.push('--env', context.flags.env)
if (context.flags.port) process.argv.push('--port', context.flags.port)

process.argv.push('--') // disable node-foreman flag parsing
process.argv.push(...context.args)
execArgv.push('--') // disable node-foreman flag parsing
execArgv.push(...context.args)

require('foreman/nf.js')
yield require('../lib/fork_foreman')(execArgv)
}

module.exports = {
Expand Down
15 changes: 7 additions & 8 deletions commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ function * run (context) {
if (context.flags.restart) throw new Error('--restart is no longer available\nUse forego instead: https://github.com/ddollar/forego')
if (context.flags.concurrency) throw new Error('--concurrency is no longer available\nUse forego instead: https://github.com/ddollar/forego')

process.argv = ['', 'heroku local', 'start']
let execArgv = ['start']

if (context.flags.procfile) process.argv.push('--procfile', context.flags.procfile)
if (context.flags.env) process.argv.push('--env', context.flags.env)
if (context.flags.port) process.argv.push('--port', context.flags.port)
if (context.flags.procfile) execArgv.push('--procfile', context.flags.procfile)
if (context.flags.env) execArgv.push('--env', context.flags.env)
if (context.flags.port) execArgv.push('--port', context.flags.port)
if (context.args.processname) {
process.argv.push(context.args.processname)
execArgv.push(context.args.processname)
} else {
let procfile = context.flags.procfile || 'Procfile'
let procHash = require('foreman/lib/procfile.js').loadProc(procfile)
let processes = Object.keys(procHash).filter((x) => x !== 'release')
process.argv.push(processes.join(','))
execArgv.push(processes.join(','))
}

require('foreman/nf.js')
yield require('../lib/fork_foreman')(execArgv)
}

const cmd = {
Expand Down
4 changes: 2 additions & 2 deletions commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const co = require('co')
const cli = require('heroku-cli-util')

function * run () {
process.argv = ['', 'heroku local', '--version']
require('foreman/nf.js')
let execArgv = ['--version']
yield require('../lib/fork_foreman')(execArgv)
}

module.exports = {
Expand Down
15 changes: 15 additions & 0 deletions lib/fork_foreman.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const {fork} = require('child_process')
const path = require('path')

module.exports = function (argv) {
let script = path.join(__dirname, 'run_foreman.js')
let nf = fork(script, argv, {stdio: 'inherit'})
return new Promise((resolve, reject) => {
nf.on('exit', function (code) {
if (code !== 0) process.exit(code)
resolve()
})
})
}
1 change: 1 addition & 0 deletions lib/run_foreman.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('foreman/nf.js')
17 changes: 17 additions & 0 deletions test/run.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bats

setup() {
run heroku plugins:link .
}

@test "run" {
run heroku local:run echo 'it works!'
echo $output
[ "$status" -eq 0 ]
[[ "$output" =~ "it works!" ]]
}

@test "run propagates exit 1" {
run heroku local:run exit 1
[ "$status" -eq 1 ]
}
12 changes: 12 additions & 0 deletions test/version.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bats

setup() {
run heroku plugins:link .
}

@test "version" {
run heroku local:version
echo $output
[ "$status" -eq 0 ]
[[ "$output" =~ "2.0.0" ]]
}

0 comments on commit cf9c177

Please sign in to comment.