Skip to content

Instantly share code, notes, and snippets.

@ushu
Created February 14, 2019 11:57
Show Gist options
  • Save ushu/129b3340c51a205157c1e2daa1da55fa to your computer and use it in GitHub Desktop.
Save ushu/129b3340c51a205157c1e2daa1da55fa to your computer and use it in GitHub Desktop.
Generate a new app.json file for the current project
#!/usr/bin/env ruby
require 'json'
# Grab info from the heroku cli
info = JSON.load(`heroku info --json`)
env_variables = JSON.load(`heroku config --json`)
buildpacks = `heroku buildpacks`.lines[1..].map{ |l| { 'url' => l[3..].chop }}
addons = JSON.load(`heroku addons --json`).inject(Hash.new{ |h, k| h[k] = [] }) { |h, e|
name = e['addon_service']['name']
plan = e['plan']['name']
as = e['attachments'][0]['name']
h[name] << { 'plan' => plan, 'as' => as }
h
}
formation = info['dynos'].inject({}) { |h, ps|
type = ps['type']
quantity = h[type] ? h[type]['quantity'] + 1 : 1
size = ps['size']
h[type] = { 'quantity' => quantity, 'size' => size }
h
}
name = info['app']['name']
website = info['app']['web_url']
repository = info['app']['git_url']
keywords = []
scripts = {}
if File.file?('config/application.rb')
# Rails app detected
scripts['postdeploy'] = 'bundle exec rake db:migrate'
keywords << 'Rails'
end
app_json = {
'name' => name,
'description' => '',
'keywords' => keywords,
'website' => website,
'repository' => repository,
'buildpacks' => buildpacks,
'formation' => formation,
'addons' => addons,
'env' => env_variables,
'scripts' => scripts
}
print JSON.pretty_generate(app_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment