{"size": 873, "ext": "js", "max_stars_repo_path": "cli/cmds/enableAPIs.js", "max_stars_repo_name": "mac2000/cloudflare-gcp", "max_stars_repo_stars_event_min_datetime": "2019-03-20T00:48:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T02:01:41.000Z", "max_issues_repo_path": "cli/cmds/enableAPIs.js", "max_issues_repo_name": "mac2000/cloudflare-gcp", "max_issues_repo_issues_event_min_datetime": "2019-04-15T11:53:25.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T09:17:34.000Z", "max_forks_repo_path": "cli/cmds/enableAPIs.js", "max_forks_repo_name": "mac2000/cloudflare-gcp", "max_forks_repo_forks_event_min_datetime": "2019-03-20T02:28:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-31T18:54:16.000Z"}
{"max_stars_count": 43, "max_issues_count": 60, "max_forks_count": 30, "avg_line_length": 21.825, "max_line_length": 64, "alphanum_fraction": 0.5796105384}
const shP = require('exec-sh').promise
const yaml = {
  read: require('read-yaml')
}

exports.command = 'enableAPIs'

exports.describe = 'Enable APIs'

exports.builder = {
  dir: {
    default: '.'
  }
}

exports.handler = async function enableAPIs () {
  const { info, success, err } = require('../utils/logger')
  const { baseDir } = require('../utils/paths')
  let cmds = yaml.read.sync(`${baseDir}/confs/enableAPIs.yml`)
  cmds = Object.values(cmds.apis)
  let i = 1
  const runCmds = cmds.map(async cmd => {
    let out
    try {
      out = await shP(`${cmd}`, false)
    } catch (e) {
      if (e instanceof TypeError) err(e)
    }
    return out
  })

  for (const cmd of runCmds) {
    await cmd
    success(`${i++}/${cmds.length} .. ${cmds[i - 2]} succeeded`)
    if (i === runCmds.length) {
      setTimeout(() => { info('\nClick Next -->') }, 2000)
    }
  }
}
