@modyo/widget
Version:
is a widget boilerplater
56 lines (53 loc) • 1.57 kB
JavaScript
import inquirer from 'inquirer'
import path from 'path'
import widgetCategories from './widgetCategories'
import widgetList from './widgetList'
import { exists } from './fs-helpers'
const askCategory = (options) => [
{
type: 'list',
name: 'widgetCategory',
message: 'Please Select a Widget Category',
choices: widgetCategories(options),
initial: 0,
when () {
return !options.widgetCategory || !exists(path.resolve('financial-widgets', options.widgetCategory))
}
}
]
const askWidgetName = (options) => [
{
type: 'list',
name: 'widgetName',
message: 'Please Select a Widget',
choices () {
return widgetList(options)
},
when () {
return !options.widgetName || !exists(path.resolve('financial-widgets', options.widgetCategory, options.widgetName))
}
}
]
const promptForMissingOptions = async (options) => {
if (!options.widgetCategory || !exists(
path.resolve(options.tempGitPath, options.widgetCategory)
)) {
const response1 = await inquirer.prompt(askCategory(options))
// eslint-disable-next-line no-param-reassign
options = Object.assign(options, response1)
}
if (!options.widgetName || !exists(
path.resolve(options.tempGitPath, options.widgetCategory, options.widgetName)
)) {
const response2 = await inquirer.prompt(askWidgetName(options))
const newOptions = Object.assign(options, response2)
return {
...newOptions
}
}
return {
...options
}
}
export { promptForMissingOptions }
export default promptForMissingOptions