2013-11-20 38 views
0

我想要將git commit ID作爲我創建的zip文件的一部分。我試圖使用grunt-git-rev-parse,但我沒有運氣。我的zip文件是name-.zip而不是name-3A5BC3.zip。我如何去獲取git commit ID到我的文件名?試圖在grunt中獲取git commit ID

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']); 
}; 

回答

3

您錯過了您的grunt-git-rev-parse任務的多任務目標,因此它從未運行。 :-)

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

不是你的錯,因爲這個特別的插件文件是對這個不清楚,但始終確保你可以得到一個輸出,無需指定多任務目標。如果不能,添加一個通常會解決問題(您可以始終檢查源代碼以確保它是多任務或單個任務)。