尝试在grunt中获得git commit ID [英] Trying to get the git commit ID in grunt

查看:138
本文介绍了尝试在grunt中获得git commit ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要将git提交ID作为我创建的zip文件的一部分。我试图使用 grunt-git-rev-parse 但我没有运气。我的zip文件是 name-.zip 不是 name-3A5BC3.zip

I would like to have to git commit ID be part of the zip file I create. I'm trying to use grunt-git-rev-parse but am having no luck. My zip file is name-.zip not name-3A5BC3.zip. How do I go about getting the git commit ID into my filename?

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    "git-rev-parse": {
      options: {
        prop: 'git-revision',
        number: 6
      }
    },

    jshint: { 
      options: {
        curly: true,
        eqeqeq: true,
        eqnull: true,
        browser: true,
        globals: {
          jQuery: true
        },
      },
      all: ['gruntfile.js', 'public/javascripts/**/*.js'],
    },

    bower: {
      install: {
        options: {
          install: true,
          copy: false
        }
      }
    },

    jade: {
      compile: {
        options: {
          data: {
            debug: false
          }
        },
        files: {
          "build/html/index.html": ["src/jade/index.jade"],
          "build/html/login.html": ["src/jade/login.jade"]
        }
      }
    },

    stylus: {
      compile: {
        options: {
          urlfunc: 'embedurl'
        },
        files: {
          'build/css/site.css': ['src/stylus/site.styl']
        }
      }
    },

    uglify: {
      options: {
        mangle: false,
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
      },
      dist: {
        files: {
          'build/js/<%= pkg.name %>.min.js': ['public/javascripts/**/*.js',
            'bower_components/angulartics/src/angulartics.js',
            'bower_components/angulartics/src/angulartics-google-analytics.js']
        }
      }
    },

    compress: {
      main: {
        options: {
          archive: "<%= pkg.name %>-<%= grunt.config.get('git-revision') %>.zip",
          mode: 'zip',
          pretty: true
        },
        files: [
          {expand: true, cwd: 'build/', src: ['**/*']}
        ]
      }
    }
  });


  grunt.loadNpmTasks('grunt-bower-task');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jade');
  grunt.loadNpmTasks('grunt-contrib-stylus');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-git-rev-parse');


  grunt.registerTask('test',  ['jshint']);
  grunt.registerTask('build', ['bower', 'jade', 'stylus', 'uglify']);
  grunt.registerTask('pkg', ['git-rev-parse', 'compress:main']);
};


推荐答案

$ c> grunt-git-rev-parse 任务,所以它从未运行。 : - )

You missed off the multitask target for your grunt-git-rev-parse task, so it was never run. :-)

"git-rev-parse": {
  build: {
    options: {
      prop: 'git-revision',
      number: 6
    }
  }
}

不是你的错,因为这个特定插件的文档不清楚,但总是确保你可以得到一个输出而不指定多任务目标。如果你不能,添加一个通常会解决问题(你总是可以检查源代码,以确保它是一个多任务或一个任务)。

Not your fault because the documentation for this particular plugin is unclear on this, but always make sure you can get an output without specifying a multitask target. If you can't, adding one will usually solve the problem (you can always check the source code to make sure that it is a multi task or a single task).

这篇关于尝试在grunt中获得git commit ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆