我想在 actions 属性中使用 async/await 但是,它给了我[ERROR] Handler has no actions。我试过了.then()
,还是失败了。
这是我到目前为止所尝试的。我正在尝试做的是通过在操作中执行它然后使用await
但失败来做一个反应性提示(我不知道),所以我转向了.then
同样失败的语法。
const fs = require('fs')
const inquirer = require('inquirer')
const chalk = require('chalk')
const directories = (dir) => fs.readdirSync(dir, {
withFileTypes: true
}).reduce((a, c) => {
c.isDirectory() && a.push(c.name)
return a
}, [])
const folders = directories('./src/views')
module.exports = function (plop) {
plop.setGenerator('Handler', {
description: 'Application translations generator',
prompts: [
{
type: 'input',
name: 'filename',
message: 'Filename (ex. file name):'
},
{
type: 'list',
name: 'folder',
message: 'Select folder location: ',
choices: folders
}
],
actions: (data) => {
const subfolders = directories(`./src/views/${data.folder}`)
const actions = []
inquirer.prompt({
type: 'list',
name: 'subfolder',
message: 'Select subfolder location: ',
choices: subfolders
}).then(x => {
actions.push({
type: 'add',
path: './asdfasdf.vue',
templateFile: './generators/templates/vue.hbs',
skipIfExists: true
})
return actions
})
}
})
}