复制所有文件,但在.gitignore中忽略

时间:2015-09-01 11:36:42

标签: javascript build gruntjs build-automation

我想将所有文件复制到另一个目录(使用grunt-contrib-copy),但.gitignore中列出的文件除外。 这是我目前的设置: 的.gitignore:

/vendor
/node_modules

的package.json:

{
  "name": "grunt-cpy",
  "version": "1.0.0",
  "description": "",
  "main": "Gruntfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "gitignore-globs": "^0.1.1",
    "grunt": "^0.4.5",
    "grunt-cli": "~0.1.11",
    "grunt-contrib-copy": "^0.7.0",
    "grunt-contrib-clean": "^0.6.0"
  }
}

Gruntfile.js

module.exports = function (grunt) {

    var parse = require('gitignore-globs');
    var globs = parse('.gitignore', { negate: true } );
    grunt.log.ok( globs );

    // Project configuration.
    grunt.initConfig({
        pkg     : grunt.file.readJSON( 'package.json' ),
        clean: {
            pre_build: [
                'build/'
            ]
        },
        copy: {
            build: {
                options : {
                    mode :true
                },
                src: [
                    '**',
                    globs
                ],
                dest: 'build/'
            }
        }
    });

    grunt.loadNpmTasks( 'grunt-contrib-clean' );
    grunt.loadNpmTasks( 'grunt-contrib-copy' );

    grunt.registerTask( 'default', [ 'clean:pre_build', 'copy'] );
};

globs的调试输出:

!/vendor,!/vendor/**,!/node_modules,!/node_modules/**

但它不会这样。它只是复制一切。我也试过'gitignore-to-glob'和'grunt-copy-to'这个包。有人可以帮忙存档吗? 我在Windows上。

0 个答案:

没有答案
相关问题