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

Commit

Permalink
Revert "convert commands to oclif v7 style (#45)"
Browse files Browse the repository at this point in the history
This reverts commit 7a7a4f6.

This seems to not be working right with `heroku local` and `heroku
local:start`
  • Loading branch information
jdx committed May 31, 2018
1 parent 7a7a4f6 commit c8a8fd8
Show file tree
Hide file tree
Showing 12 changed files with 740 additions and 218 deletions.
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

2 changes: 0 additions & 2 deletions CODEOWNERS

This file was deleted.

36 changes: 0 additions & 36 deletions commands/local/run.js

This file was deleted.

48 changes: 0 additions & 48 deletions commands/local/start.js

This file was deleted.

18 changes: 0 additions & 18 deletions commands/local/version.js

This file was deleted.

37 changes: 37 additions & 0 deletions commands/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'

const co = require('co')
const cli = require('heroku-cli-util')
const {FileCompletion} = require('@heroku-cli/command/lib/completions')

function * run (context) {
if (context.args.length < 1) {
cli.error('Usage: heroku local:run [COMMAND]\nMust specify command to run')
process.exit(-1)
}

let execArgv = ['run']

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

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

yield require('../lib/fork_foreman')(execArgv)
}

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, completion: FileCompletion},
{name: 'port', char: 'p', hasValue: true}
],
run: cli.command(co.wrap(run))
}
52 changes: 52 additions & 0 deletions commands/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict'

const co = require('co')
const cli = require('heroku-cli-util')
const {FileCompletion} = require('@heroku-cli/command/lib/completions')

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')

let execArgv = ['start']

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) {
execArgv.push(context.args.processname)
} else {
let procfile = context.flags.procfile || 'Procfile'
let procHash = require('@heroku/foreman/lib/procfile.js').loadProc(procfile)
let processes = Object.keys(procHash).filter((x) => x !== 'release')
execArgv.push(processes.join(','))
}
yield require('../lib/fork_foreman')(execArgv)
}

const cmd = {
topic: 'local',
description: 'run heroku app locally',
help: `Start the application specified by a Procfile (defaults to ./Procfile)
Examples:
heroku local
heroku local web
heroku local web=2
heroku local web=1,worker=2`,
args: [{name: 'processname', optional: true}],
flags: [
{name: 'procfile', char: 'f', hasValue: true, description: 'use a different Procfile', completion: FileCompletion},
{name: 'env', char: 'e', hasValue: true, description: 'location of env file (defaults to .env)', completion: FileCompletion},
{name: 'port', char: 'p', hasValue: true, description: 'port to listen on'},
{name: 'restart', char: 'r', hasValue: false, hidden: true, description: 'restart process if it dies'},
{name: 'concurrency', char: 'c', hasValue: true, hidden: true, description: 'number of processes to start'}
],
run: cli.command(co.wrap(run))
}

module.exports = [
cmd,
Object.assign({command: 'start'}, cmd)
]
17 changes: 17 additions & 0 deletions commands/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const co = require('co')
const cli = require('heroku-cli-util')

function * run () {
let execArgv = ['--version']
yield require('../lib/fork_foreman')(execArgv)
}

module.exports = {
topic: 'local',
command: 'version',
description: 'display node-foreman version',
help: 'Display node-foreman version',
run: cli.command(co.wrap(run))
}
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

const flatten = require('lodash.flatten')

exports.topic = {
name: 'local',
description: 'run heroku app locally'
}

exports.commands = flatten([
require('./commands/start'),
require('./commands/run'),
require('./commands/version')
])
5 changes: 1 addition & 4 deletions lib/fork_foreman.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable unicorn/no-process-exit */
/* eslint-disable no-process-exit */

'use strict'

const {fork} = require('child_process')
Expand All @@ -9,7 +6,7 @@ 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, _) => {
return new Promise((resolve, reject) => {
nf.on('exit', function (code) {
if (code !== 0) process.exit(code)
resolve()
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
},
"dependencies": {
"@heroku-cli/command": "^8.0.5",
"@heroku/foreman": "^2.0.2"
"@heroku/foreman": "^2.0.2",
"co": "^4.6.0",
"heroku-cli-util": "^8.0.6",
"lodash.flatten": "^4.4.0"
},
"devDependencies": {
"@oclif/dev-cli": "^1.13.1",
"@oclif/plugin-legacy": "^1.0.10",
"eslint": "^4.19.1",
"eslint-config-oclif": "^1.4.0"
"standard": "^11.0.1"
},
"files": [
".oclif.manifest.json",
Expand All @@ -27,24 +29,21 @@
"heroku-plugin"
],
"license": "ISC",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/heroku/heroku-local"
},
"scripts": {
"test": "bats test && eslint .",
"test": "bats test && standard",
"prepublishOnly": "oclif-dev manifest",
"postpublish": "rm .oclif.manifest.json"
},
"oclif": {
"commands": "./commands",
"cli-engine": {
"topics": {
"local": {
"description": "run heroku app locally"
}
}
},
"engines": {
"node": ">=8.0.0"
}
}
Loading

0 comments on commit c8a8fd8

Please sign in to comment.