Grunt - 命令行参数,不起作用 [英] Grunt - Command Line Arguments, not working
问题描述
我在我的grunt脚本中使用命令行选项: http://kurst.co.uk /transfer/Gruntfile.js
然而,命令 grunt --vers:0.0.1
总是当我尝试获取选项时返回'undefined':
var version = grunt.option('vers')|| ;
您能帮我解决这个问题吗?
我尝试了不同的(CLI)命令:
grunt vers: asd
grunt -vers:asd
grunt vers = asd
以及使用:
grunt.option(' - vers');
grunt.option(' - vers');
到目前为止还没有运气。希望我缺少一些简单的东西。
这是我的package.js文件:
{
name:,
version:0.1.0,
description:Kurst EventDispatcher / Docs Demo,
devDependencies:{
grunt:〜0.4.1,
grunt-contrib-yuidoc:*,
grunt-typescript:〜0.1。 3,
uglify-js:〜2.3.5,
grunt-lib-contrib:〜0.6.0,
grunt-contrib-uglify :*
}
}
在Grunt中指定命令行参数的正确语法是:
grunt --option1 = myValue
然后,在grunt文件您可以访问该值并像这样打印:
console.log(grunt.option(option1));
另外,您可能还有其他原因与 - vers
相关的问题是因为它已经是一个可以返回版本的咕噜声选项:
★grunt -vers
grunt-cli v0.1.7
grunt v0.4.1
因此,切换到不同的选项名称可能是个好主意。
I am using command line options in my grunt script: http://kurst.co.uk/transfer/Gruntfile.js
However the command grunt --vers:0.0.1
always returns 'undefined' when I try to get the option:
var version = grunt.option('vers') || '';
Can you help me get this working ?
I tried different (CLI) commands:
grunt vers:asd
grunt -vers:asd
grunt vers=asd
as well as using :
grunt.option('-vers');
grunt.option('--vers');
But no luck so far. Hopefully I am missing something simple.
This is my package.js file:
{
"name": "",
"version": "0.1.0",
"description": "Kurst EventDispatcher / Docs Demo ",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-yuidoc": "*",
"grunt-typescript": "~0.1.3",
"uglify-js": "~2.3.5",
"grunt-lib-contrib": "~0.6.0",
"grunt-contrib-uglify":"*"
}
}
The proper syntax for specifying a command line argument in Grunt is:
grunt --option1=myValue
Then, in the grunt file you can access the value and print it like this:
console.log( grunt.option( "option1" ) );
Also, another reason you are probably having issues with --vers
is because its already a grunt option that returns the version:
★ grunt --vers
grunt-cli v0.1.7
grunt v0.4.1
So it would probably be a good idea to switch to a different option name.
这篇关于Grunt - 命令行参数,不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!