我正在构建一个grunt模块,以帮助我初始化,创建默认文件夹/文件并构建一些WebProject。我创建了一个包括一些自定义任务的自定义Grunt模块。
所以我的模块是oshell.grunt
,在这个模块中,我有一个任务InitializeLibrary
。 InitializeLibrary
是一个自定义任务,在创建文件/文件夹结构之前,要求用户提供一些输入。我为此使用grunt-prompt
。
我的问题是当我在主项目中运行自定义模块时,找不到任务prompt
。能否请您分享一下您的经验,因为我想有些开发人员也面临同样的问题
自定义模块结构
在主项目中安装自定义模块后
似乎还可以。
InitializeLibrary.js
module.exports = function(
grunt
){
"use strict";
grunt.initConfig({
"prompt": {
"libraryInfo": {
options: {
questions: [
{
config: "InitializeOpenShellLibrary.version",
type: "input",
message: "Initial version of the library",
default: "0.1.0"
}
]
}
}
}
});
require("load-grunt-subtasks")(grunt);
grunt.registerTask(
"InitializeLibrary",
[
"prompt:libraryInfo"
]
);
}
主Web项目咕unt声文件
module.exports = function(
grunt
){
"use strict";
grunt.loadNpmTasks("oshell.grunt");
grunt.registerTask("default", ["InitializeLibrary"]);
};
当我在主项目中运行此grunt
时,将得到此结果。
Warning: Task "prompt:libraryInfo" not found. Use --force to continue.
我希望任务prompt
在自定义模块中运行,以提示输入库信息。
非常感谢您的回答。
请安装https://www.npmjs.com/package/grunt-prompt并将此代码添加到grunt配置文件中:
grunt.loadNpmTasks('grunt-prompt');