UNPKG

741 BJavaScriptView Raw
1'use strict'
2
3const co = require('co')
4const cli = require('heroku-cli-util')
5
6module.exports = function * (context, api, addon, interval) {
7 const wait = require('co-wait')
8 const app = addon.app.name
9 const addonName = addon.name
10
11 yield cli.action(`Creating ${cli.color.addon(addon.name)}`, co(function * () {
12 while (addon.state === 'provisioning') {
13 yield wait(interval * 1000)
14
15 addon = yield api.request({
16 method: 'GET',
17 path: `/apps/${app}/addons/${addonName}`,
18 headers: {'Accept-Expansion': 'addon_service,plan'}
19 })
20 }
21 if (addon.state === 'deprovisioned') {
22 throw new Error(`The add-on was unable to be created, with status ${addon.state}`)
23 }
24 }))
25
26 return addon
27}