目前,模板文件名是硬编码的,但我更希望 grunt 扫描正确的文件夹并动态提供文件名。
我尝试过使用 grunt.file.expand,但我无法让它工作。是否有可能扫描文件夹并以 grunt-prompt 要求的格式返回文件名数组(或对象,不确定应该称之为什么)?
// -------------------------------------
// Grunt prompt
// -------------------------------------
module.exports = {
// ----- Initialization prompt ----- //
init: {
options: {
questions: [{
// Set the authors name
config: 'init.author.name',
type: 'input',
message: 'What is your name?'
}, {
// Set the name of the project
config: 'init.project.name',
type: 'input',
message: 'What is the name of your project?'
}, {
// Select templates to be used
config: 'init.php.templates',
type: 'checkbox',
message: 'Which templates do you want to use?',
choices: [{
name: '404.php',
checked: false
}, {
name: 'archive.php',
checked: false
}, {
name: 'comments.php',
checked: false
}]
}]
}
}
};
顺便提一下,我找到了这个答案:https://stackoverflow.com/a/22270703/1694077,它与这个问题有关。但它没有详细说明如何具体解决这个问题。此外,我需要比文件名数组更具体的语法:
[{
name: '404.php'
}, {
name: 'archive.php'
}]
fs.readdir
? - Vinz243