gpt4 book ai didi

javascript - 如何从复制任务中调用 grunt 提示任务?

转载 作者:行者123 更新时间:2023-12-02 15:07:44 25 4
gpt4 key购买 nike

我正在使用 load-grunt-config,并且在我的 Gruntfile.js 中有一个像这样的简单复制任务设置,

grunt.registerTask('copy-css', 'Blah.', ['copy:css'])

然后在我的 copy.js 文件中我有这个(忽略无效代码。复制任务工作正常,我只是设置这个示例)。

'use strict';

module.exports = function(grunt, options) {
if(!grunt.file.exists(foldername)) {
//I NEED TO RUN A PROMPT HERE BUT THIS IS NOT WORKING
grunt.task.run('prompt:directory-exists');
}

return {
'css': {
'files': [{
}]
}
};
};

我的提示任务看起来像这样,

'use strict';

module.exports = {
'directory-exists': {
'options': {
'questions': [{
'type': 'confirm',
'message': 'That folder already exists. Are you sure you want to continue?',
'choices': ['Yes (overwrite my project files)', 'No (do nothing)']
}]
}
}
};

Grunt 没有找到这个任务,我认为这与我如何调用它有关,考虑到我正在使用 load-grunt-config。

最佳答案

如果您注册了一个任务,您将可以访问 grunt 配置中的任务(如提示符)。

以下是您可以在 Gruntfile.js 中创建的任务示例:

grunt.registerTask('myowntask', 'My precious, my own task...', function(){
// init
var runCopy = true;

// You'll need to retrieve or define foldername somewhere before...
if( grunt.file.exists( foldername )) {
// If your file exists, you call the prompt task, with the specific 'directory-exists' configuration you put in your prompt.js file
grunt.task.call('prompt:directory-exists');
}

}

然后,运行grunt myowntask

关于javascript - 如何从复制任务中调用 grunt 提示任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35000133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com