【问题标题】:How do you pass a parameter into a grunt task?如何将参数传递给 grunt 任务?
【发布时间】:2014-02-16 03:35:02
【问题描述】:

作为我的 grunt:build 命令的一部分,我运行一个 shell 任务来构建我的 jekyll 站点、提交项目并将其推送到 github。唯一的问题是提交消息。我希望能够调用 grunt:build 并传入一个字符串,该字符串将成为我的提交消息。但我不太确定如何做到这一点。有什么想法吗?

这是我的 Gruntfile 的相关部分:

module.exports = function(grunt) {
        grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

            shell: {

                dev: {
                    command: 'jekyll build'
                },

                build: {
                    command: [
                    'jekyll build',
                    'git commit -am "test commit"',
                    'git push origin master'
                    ].join('&&')
                }

                }

    grunt.loadNpmTasks('grunt-shell');

    grunt.registerTask('build', ['jshint','concat', 'uglify','sass', 'autoprefixer','shell:build']);

};

【问题讨论】:

标签: javascript git gruntjs


【解决方案1】:

试试grunt.option() (http://gruntjs.com/api/grunt.option):

'git commit -am "' + grunt.option('commit-msg') + '"',

并运行:grunt build --commit-msg="test commit"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 2018-10-19
    • 2015-04-16
    • 1970-01-01
    • 2011-07-02
    相关资源
    最近更新 更多