src/lib/status.ts

Summary

Maintainability
A
3 hrs
Test Coverage
let inquirer = require('inquirer')

import Utils from './utils'
import StatusHelper from './StatusHelper'
import Config from './Config'
import getAdrFiles from './helpers/getAdrFiles'

let path = Config.getSavePath()
let i18n = Utils.getI18n()

let getAllFilesName = function (): string[] {
  let outputArray = ['']
  let files = getAdrFiles()
  files.forEach(function (file) {
    let fileName = file.relativePath

    let index = Utils.getIndexByString(fileName)
    if (index) {
      outputArray[index] = fileName
    }
  })

  return outputArray
}

export function status (index): void {
  let fileName = getAllFilesName()[index]
  if (!fileName) {
    console.log(`File with index ${index} does not exist.`)
  }
  let status = StatusHelper.getLatestStatus(path + fileName)
  let statusList = i18n.statusStr.split('/')
  inquirer.prompt([{
    type: 'list',
    name: 'status',
    message: `${fileName}(${status}) new status:`,
    choices: statusList
  }]).then(answer => {
    StatusHelper.setStatus(path + fileName, answer.status)
  })
}