Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
试图在grunt中获取git提交ID_Git_Gruntjs - Fatal编程技术网

试图在grunt中获取git提交ID

试图在grunt中获取git提交ID,git,gruntjs,Git,Gruntjs,我希望git commit ID必须是我创建的zip文件的一部分。我正在尝试使用grunt git rev parse,但运气不好。我的zip文件是name-.zip而不是name-3A5BC3.zip。如何将git提交ID放入文件名中 module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), "git-rev-parse": {

我希望git commit ID必须是我创建的zip文件的一部分。我正在尝试使用
grunt git rev parse
,但运气不好。我的zip文件是
name-.zip
而不是
name-3A5BC3.zip
。如何将git提交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']);
};
module.exports=函数(grunt){
grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
“git版本解析”:{
选项:{
道具:“git修订版”,
电话:6
}
},
jshint:{
选项:{
柯莉:是的,
Eqeq:是的,
eqnull:true,
浏览器:是的,
全球:{
jQuery:true
},
},
全部:['gruntfile.js','public/javascripts/***.js'],
},
鲍尔:{
安装:{
选项:{
安装:正确,
副本:假
}
}
},
杰德:{
汇编:{
选项:{
数据:{
调试:false
}
},
档案:{
“build/html/index.html”:[“src/jade/index.jade”],
“build/html/login.html”:[“src/jade/login.jade”]
}
}
},
触笔:{
汇编:{
选项:{
urlfunc:“嵌入URL”
},
档案:{
'build/css/site.css':['src/stylus/site.styl']
}
}
},
丑陋的:{
选项:{
mangle:错,
横幅:'/*!*/\n'
},
地区:{
档案:{
'build/js/.min.js':['public/javascripts/***.js',
'bower_components/angulartics/src/angulartics.js',
'bower_components/angulartics/src/angulartics google analytics.js']
}
}
},
压缩:{
主要内容:{
选项:{
档案:“-.zip”,
模式:“zip”,
真的吗
},
档案:[
{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');
registerTask('test',['jshint']);
grunt.registerTask('build',['bower','jade','stylus','uglify']);
registerTask('pkg',['git-rev-parse','compress:main']);
};

您错过了
grunt git rev parse
任务的多任务目标,因此它从未运行过。:-)

这不是你的错,因为这个特定插件的文档对此并不清楚,但是一定要确保你可以在不指定多任务目标的情况下获得输出。如果不能,添加一个任务通常可以解决问题(您可以随时检查源代码以确保它是多任务还是单个任务)

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