Code Monkey home page Code Monkey logo

grunt-contrib-copy's Introduction

grunt-contrib-copy v1.0.0 Build Status: Linux Build Status: Windows

Copy files and folders

Getting Started

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-contrib-copy --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

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

This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.3.2.

Copy task

Run this task with the grunt copy command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Options

process

Type: Function(content, srcpath)

This option is passed to grunt.file.copy as an advanced way to control the file contents that are copied.

processContent has been renamed to process and the option name will be removed in the future.

noProcess

Type: String

This option is passed to grunt.file.copy as an advanced way to control which file contents are processed.

processContentExclude has been renamed to noProcess and the option name will be removed in the future.

encoding

Type: String
Default: grunt.file.defaultEncoding

The file encoding to copy files with.

mode

Type: Boolean or String
Default: false

Whether to copy or set the destination file and directory permissions. Set to true to copy the existing file and directories permissions. Or set to the mode, i.e.: 0644, that copied files will be set to.

timestamp

Type: Boolean
Default: false

Whether to preserve the timestamp attributes(atime and mtime) when copying files. Set to true to preserve files timestamp. But timestamp will not be preserved when the file contents or name are changed during copying.

Usage Examples

copy: {
  main: {
    files: [
      // includes files within path
      {expand: true, src: ['path/*'], dest: 'dest/', filter: 'isFile'},

      // includes files within path and its sub-directories
      {expand: true, src: ['path/**'], dest: 'dest/'},

      // makes all src relative to cwd
      {expand: true, cwd: 'path/', src: ['**'], dest: 'dest/'},

      // flattens results to a single level
      {expand: true, flatten: true, src: ['path/**'], dest: 'dest/', filter: 'isFile'},
    ],
  },
},

This task supports all the file mapping format Grunt supports. Please read Globbing patterns and Building the files object dynamically for additional details.

Here are some additional examples, given the following file tree:

$ tree -I node_modules
.
├── Gruntfile.js
└── src
    ├── a
    └── subdir
        └── b

2 directories, 3 files

Copy a single file tree:

copy: {
  main: {
    expand: true,
    src: 'src/*',
    dest: 'dest/',
  },
},
$ grunt copy
Running "copy:main" (copy) task
Created 1 directories, copied 1 files

Done, without errors.
$ tree -I node_modules
.
├── Gruntfile.js
├── dest
│   └── src
│       ├── a
│       └── subdir
└── src
    ├── a
    └── subdir
        └── b

5 directories, 4 files

Copying without full path:

copy: {
  main: {
    expand: true,
    cwd: 'src',
    src: '**',
    dest: 'dest/',
  },
},
$ grunt copy
Running "copy:main" (copy) task
Created 2 directories, copied 2 files

Done, without errors.
$ tree -I node_modules
.
├── Gruntfile.js
├── dest
│   ├── a
│   └── subdir
│       └── b
└── src
    ├── a
    └── subdir
        └── b

5 directories, 5 files

Flattening the filepath output:

copy: {
  main: {
    expand: true,
    cwd: 'src/',
    src: '**',
    dest: 'dest/',
    flatten: true,
    filter: 'isFile',
  },
},
$ grunt copy
Running "copy:main" (copy) task
Copied 2 files

Done, without errors.
$ tree -I node_modules
.
├── Gruntfile.js
├── dest
│   ├── a
│   └── b
└── src
    ├── a
    └── subdir
        └── b

3 directories, 5 files

Copy and modify a file:

To change the contents of a file as it is copied, set an options.process function as follows:

copy: {
  main: {
    src: 'src/a',
    dest: 'src/a.bak',
    options: {
      process: function (content, srcpath) {
        return content.replace(/[sad ]/g, '_');
      },
    },
  },
},

Here all occurrences of the letters "s", "a" and "d", as well as all spaces, will be changed to underlines in "a.bak". Of course, you are not limited to just using regex replacements.

To process all files in a directory, the process function is used in exactly the same way.

NOTE: If process is not working, be aware it was called processContent in v0.4.1 and earlier.

Troubleshooting

By default, if a file or directory is not found it is quietly ignored. If the file should exist, and non-existence generate an error, then add nonull:true. For instance, this Gruntfile.js entry:

copy: {
  main: {
    nonull: true,
    src: 'not-there',
    dest: 'create-me',
  },
},

gives this output:

$ grunt copy
Running "copy:main" (copy) task
Warning: Unable to read "not-there" file (Error code: ENOENT). Use --force to continue.

Aborted due to warnings.

Release History

  • 2016-03-04   v1.0.0   Bump devDependencies. Add example of using relative path. Point main to task and remove peerDeps.
  • 2015-10-19   v0.8.2   Fix expand-less copies with multiple files.
  • 2015-08-20   v0.8.1   Update chalk dependency.
  • 2015-02-20   v0.8.0   Performance improvements. The mode option now also applies to directories. Fix path issue on Windows.
  • 2014-10-15   v0.7.0   Add timestamp option to disable preserving timestamp when copying.
  • 2014-09-17   v0.6.0   Update chalk dependency and other devDependencies. Preserve file timestamp when copying.
  • 2013-12-23   v0.5.0   If an encoding is specified, overwrite grunt.file.defaultEncoding. Rename processContent/processContentExclude to process/noProcess to match Grunt API. mode option to copy existing or set file permissions.
  • 2013-03-26   v0.4.1   Output summary by default ("Copied N files, created M folders"). Individual transaction output available via --verbose.
  • 2013-02-15   v0.4.0   First official release for Grunt 0.4.0.
  • 2013-01-23   v0.4.0rc7   Updating grunt/gruntplugin dependencies to rc7. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions.
  • 2013-01-14   v0.4.0rc5   Updating to work with grunt v0.4.0rc5. Conversion to grunt v0.4 conventions. Replace basePath with cwd. Empty directory support.
  • 2012-10-18   v0.3.2   Pass copyOptions on single file copy.
  • 2012-10-12   v0.3.1   Rename grunt-contrib-lib dep to grunt-lib-contrib.
  • 2012-09-24   v0.3.0   General cleanup and consolidation. Global options depreciated.
  • 2012-09-18   v0.2.4   No valid source check.
  • 2012-09-17   v0.2.3   path.sep fallback for Node.js <= 0.7.9.
  • 2012-09-17   v0.2.2   Single file copy support. Test refactoring.
  • 2012-09-07   v0.2.0   Refactored from grunt-contrib into individual repo.

Task submitted by Chris Talkington

This file was generated on Thu Apr 07 2016 15:11:09.

grunt-contrib-copy's People

Contributors

also avatar benjamindobler avatar boreplusplus avatar corpulentcoffee avatar cowboy avatar ctalkington avatar darrencook avatar ericclemmons avatar greggman avatar kwyn avatar mgeisler avatar mingzhi22 avatar nalajcie avatar pgilad avatar piperchester avatar pscheit avatar radkodinev avatar relaxatorium avatar richgilbank avatar ricog avatar shama avatar sindresorhus avatar stephanebachelier avatar suguiura avatar tiye avatar vladikoff avatar xavierpriour avatar xhmikosr avatar zhiyelee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-contrib-copy's Issues

Copy files to absolute path

Sorry If I'm missing something, but I'm trying to copy some files inside the project to a subfolder of my home directory.

The configuration in the grunt.js looks like this:

copy: {
        main: {
          files: [
            {
              src: ['temp/plugins/**'],
              dest: '~/Library/Application\ Support/sketch/Plugins/',
            }
          ]
        }
      }

It creates a subfolder ~ and copies the whole thing there.

add summary option

When copying hundreds of files it would sometimes be nice to get a report of all files copied rather than a printed line for each file. Copied 257 files for example.

I can add this feature if it has the green light.

Non-existant source file results in warning about trailing slash

The following configuration:

copy: {
  libs: {
    files: {
      'build/js/libs/jquery.js': '/folder/that/does/not/exist/jquery/index.js'
    }
  }
}

Results in the wrong error message:

<WARN> Unable to copy multiple files to the same destination filename, did you forget a trailing slash? Use --force to continue. </WARN>

Maybe the error message should be something like:

<WARN> Unable to copy; source file /folder/that/does/not/exist/jquery/index.js not found. Use --force to continue. </WARN>

I know there is no convention for this yet, but I personally believe it is helpful to warn when the file does not exist.

Thanks for the hard work and quick turnarounds!

TypeError: Cannot read property 'kindOf' of undefined

From my gruntfile:

copy: {
            main: {
                files: [
                        {src: ['index.html'], dest: '../production/index.html', filter: 'isFile'}, 
                        {src: ['config.xml'], dest: '../production/config.xml', filter: 'isFile'}, 
                        {src: ['img/phonegap/icon/ios/Icon-72.png'], dest: '../production/icon.png', filter: 'isFile'}, 
                        {src: ['img/**'], dest: '../production/img/'}, // includes files in path and its subdirs
                        {src: ['data/*'], dest: '../production/data/'} // includes files in path
                 ]
            }
        },

Running "copy:main" (copy) task

TypeError: Cannot read property 'kindOf' of undefined
    at Object.module.exports.detectDestType (/Users/per/Documents/Aptana Studio 3 Workspace/eeSVN/grete/trunk/node_modules/grunt-contrib-copy/tasks/copy.js:16:28)
    at Object.task.registerMultiTask.thisTask (/usr/local/lib/node_modules/grunt/lib/grunt/task.js:109:15)
    at Object.task.registerTask.thisTask.fn (/usr/local/lib/node_modules/grunt/lib/grunt/task.js:58:16)
    at Task.<anonymous> (/usr/local/lib/node_modules/grunt/lib/util/task.js:341:36)
    at Task.<anonymous> (/usr/local/lib/node_modules/grunt/lib/util/task.js:317:9)
    at Task.<anonymous> (/usr/local/lib/node_modules/grunt/lib/util/task.js:344:11)
    at Task.<anonymous> (/usr/local/lib/node_modules/grunt/lib/util/task.js:317:9)
    at Task.<anonymous> (/usr/local/lib/node_modules/grunt/lib/util/task.js:344:11)
    at Task.<anonymous> (/usr/local/lib/node_modules/grunt/lib/util/task.js:317:9)
    at Task.<anonymous> (/usr/local/lib/node_modules/grunt/lib/util/task.js:344:11)

copy files to different directory

Hello,

I am trying to watch and copy the files to different directory if there's any change to the files. I've tried different combinations/options but still can't get only the files to new directory.

watch directory: src/html/*
new directory: build/html/

The best result I can get is: src/html/build/html/some-files.html

I also tried to give cwd the path (src/html) with the src:"*", but the result is a copy of every files and subdirs of the project root.

I've been googling and going through forums but still can't find an answer to my problem.

Your help is greatly appreciated,

Niusaul

grunt.file object has no method 'expandFiles'

Warning: Object # has no method 'expandFiles'

"devDependencies": {
"grunt-crx": "~0.1.2",
"grunt-contrib-uglify": "~0.1.0",
"grunt-contrib-coffee": "~0.4.0rc7",
"grunt-regarde": "~0.1.1",
"grunt": "~0.4.0rc7",
"grunt-contrib-stylus": "~0.4.0rc7",
"grunt-contrib-copy": "~0.3.2"
},

Installing grunt-contrib-copy always goes on the 0.3.x

Hi,

I've successfully intalled the grunt 0.4.x (see my issue post on the grunt repository).

And i've the same problem with this plugin. The installer always install the 0.3.x version instead of the 0.4.x, sugin the command "npm install grunt-contrib-copy --save-dev"

So i've manually added the good version in the package.json to install the good one : "grunt-contrib-copy": "~0.4.0"

Apply template matching on file contents when copying files

I'm new to Grunt (coming from Ant), so let me know if I'm off base.

As part of a copy task I'd like to apply a template on content inside the files. In other words, if my project included this HTML:

<span>This project is at version: <%= project.version %></span>

in its source and project.version was resolvable inside Grunt, the copied file would contain:

<span>This project is at version: 0.4.2</span>

Here's the task in Ant.

Does it makes sense to have the copy task take care of this? Or is there a more idiomatic way to do this with Grunt?

Banners?

Is it possible to add banners to the copied files? I've tried several different things, but it's looking like this task isn't setup to do banners (probably for good reason, I just thought it could not hurt to ask)?

This does not work:

copy: {

    options: {

        banner: '<%= meta.banner_long %>'

    },

    main: {

        files: [

            {

                src: ['src/jquery.<%= pkg.name %>.js'],
                dest: '../',
                expand: true,
                flatten: true,
                filter: 'isFile'

            }

        ]

    }

},

Thanks!

Unexpected copy behaviour

I have a configuration file that contains a copy section like this:

files: {
  'Resources/': 'Assets/**'
}

Assets/ folder contains this:

Assets/A.png
Assets/B/B.png
Assets/B/C.png

And when grunt is executed it creates a correct copy:

Resources/A.png
Resources/B/B.png
Resources/B/C.png

But when I remove Assets/A.png grunt creates:

Resources/B.png
Resources/C.png

I excepted:

Resources/B/B.png
Resources/B/C.png

¿Bug or feature?

An option to generate symlinks?

What would folks think about adding an option to generate symlinks in the destination rather than perform a copy?

The tasks seem like natural siblings. There are a couple of symlink plugins written by others, but they don't work with the general files option the way grunt-contrib-copy does. I'd be happy to implement this and submit it as a fork request, but I wanted to see if it was even an idea that made sense.

I ask because I started to make my own symlinks plugin and found I was using 99% of the code from this one.

this.files is empty

Hi All,

I am trying to use this plugin and and have noticed that the following line returns an empty array with the following config

this.files = this.files || helpers.normalizeMultiTaskFiles(this.data, this.target);

copy: {
files: {
'/tmp/': '/img/de/topapps.png'
// 'img/de/topapps.png': 'tmp'
}
}

any ideas why this might be happening?

cwd

Since we're already doing custom expansion in this task, how about having source paths be relative to cwd if it is set?

Instead of this:

copy: {
  images: {
    options: {
      cwd: 'assets/img'
    },
    files: {
      'public/' : 'assets/img/**/*' 
    }
  }
}

We'd have this:

copy: {
  images: {
    options: {
      cwd: 'assets/img'
    },
    files: {
      'public/' : '**/*' 
    }
  }
}

Copy files from two separate dirs into one destination dir

Hey guys,

I'm trying to copy images from two separate directories into one destination dir. It never worked with the two syntaxes:

 copy: {
      images: {
        files: {
          "dist/release/core/images/": "assets/core/images/**",
          "dist/release/core/images/": "assets/core/vendor/jquery/images/**"
        }
      }
    }


 copy: {
      images: {
        files: {
          "dist/release/core/images/": [ "assets/core/images/**", "assets/core/vendor/jquery/images/**"]
        }
      }
    }

Is this achievable?

Thanks

Templates in source paths

I was using a slightly older build of Grunt 0.4.0a with copy setup like this: Note that I have a task which attaches the files object to Grunt -- so that I can keep tabs on various file paths, globs, etc in a separate file.

This used to work fine using template syntatx.

copy: {
  lib: {
    files: {
      "<%= files.js.libRoot %>" : '<%= files.js.vendor %>'
    },
    options: {
      flatten: true
    }
  }
}

But it no longer seems to work -- instead, I have to copy the array definitions in explicitly like this. I was also unable to use a template in the destination, as the task barked about copying all files to a single file. I presume it wasn't parsing the template properly. Is this an expected change for 0.4?

copy: {
  lib: {
    files: {
      "generated/lib/" :
      //TODO: unfortunately Bower has no standard around dir layout
      [
        'components/AngularJS/*.js',
        'components/Angular-Auth/*.js',
        'components/bootstrap/docs/assets/js/bootstrap.js',
        'components/jQuery/*.js',
        'components/jquery.Cookie/jquery.cookie.js',
        'components/lawnChair/src/**/*.js',
        'components/modernizr/modernizr.js',
        'components/requirejs/require.js',
        'components/chai/chai.js',
        'components/mocha/mocha.js'
      ]
    },
    options: {
      flatten: true
    }
  }
}

Simple src/dest copies src parent directory into dest

Using this example:

copy: {
  main: {
    files: [
      {src: ['test/**'], dest: 'dist/'}
    ]
  }
}

the src directory is included (along with all the contents of src) in the dest directory. From my understanding, the src directory itself shouldn't be copied into dest, only the contents of src.

Here's the output;

Running "copy:main" (copy) task
Creating dist/test
Creating dist/test/css
Copying test/css/main.css -> dist/test/css/main.css
Creating dist/test/js
Copying test/js/app.js -> dist/test/js/app.js

I'm using

grunt-cli v0.1.6
grunt v0.4.0rc7
grunt-contrib-copy v0.4.0rc7

If I use:

copy: {
  main: {
    files: [
      {expand: true, cwd: 'test/', src: ['**'], dest: 'dest/'}
    ]
  }
}

it works as expected, not including the src folder itself in dest.

Here is the output using the above method:

Running "copy:main" (copy) task
Creating dist/
Creating dist/css
Copying temp/css/main.css -> dist/css/main.css
Creating dist/js
Copying temp/js/app.js -> dist/js/app.js

Error: EMFILE, too many open files

I found error(EMFILE) in copy module when I tried to copy almost 4000 files in 'watch' task.

I guess that this module may open files simultaneously, and it can cause error EMFILE.

It can be my mistake, but please check about situation that copying many file in 'watch' task.

Thank you.

File paths are being doubled

Using

  • Grunt 0.4.0
  • Grunt Contrib 0.4.0

I'm working on a fairly basic copy task and it seems the entire src path is being saved.

Example:

copy: {
  main: {
    files: {
        src: 'css/fonts/**',
        dest: 'dist/css/fonts/'
    }
  }
}

This is generating the following structure: dist/css/fonts/css/fonts/myfile.ttf

Make source check optional

Is it possible to make the source check optional? I would really like to prepare some copy tasks for folders which content does not exist yet, because I prepare a project for my co-workers.

Is there any way to tell the copy task that it should copy files and folders, if they exist but does not fail (and stop copying), if something does not exist?

Files copied to wrong path

I find that the behavior of this plugin is very strange. I have the following task configuration in my grunt file:

        copy:
        {
            bootstrap: {
                files: [
                    {
                        src: ['components/bootstrap/img/*'],
                        dest: 'web/img/bootstrap/'
                    }
                ]
            }
        }

One would expect that components/bootstrap/img/myFile.png is copied to web/img/bootstrap/myFile.png. But it's being copied to web/img/components/bootstrap/img/myFile.png.

Is this the normal behavior, or am I doing something wrong ?

Copy a single file under a different name without using processName

Currently, the following configuration:

copy: {
  libs: {
    options: {
      flatten: true
    },
    files: {
      'build/js/libs/jquery.js': 'components/jquery/index.js',
      'build/js/libs/underscore.js': 'components/underscore/index.js'
    }
  }
}

Results in build/js/libs/jquery.js/index.js and build/js/libs/underscore.js/index.js instead of build/js/libs/jquery.js and build/js/libs/underscore.js.

It is a common use case to copy single file under a different name. As far as I can tell, in order to achieve this, the individual files need to be broken out into their own sub-tasks (since the source filenames are the same) and given a processName function:

  jquery: {
    options: {
      flatten: true,
      processName: function(filename) {
        return 'jquery.js';
      }
    },
    files: {
      'build/js/libs': 'components/jquery/index.js'
    }
  },
  underscore: {
    options: {
      flatten: true,
      processName: function(filename) {
        return 'underscore.js';
      }
    },
    files: {
      'build/js/libs': 'components/underscore/index.js',
    }
  }

The documentation indicates "The key (destination) should be an unique path", so it looks like it's treating index.js as a directory name, not a file name. I'm aware of the fact that this shouldn't behave exactly like cp, but it might sense to detect the lack of a trailing slash on the key and assume it's a file copy operation. Thoughts?

Possible to pass variable as key for associative object properties?

So, I've spent alot of time and I realize that my use case is highly uncommon, however, for a variety of reasons I need to work with a dynamic loop and I'm doing grunt.config inside of a loop of unknown length with unknown key values, so there's no way to point to index without using standard javascript variables.

That background info being established, is there a way to escape variables in the associate-type value pairs like the files : {} one? I need to be able to do something like this:

            grunt.config( 'copy.'+thisTheme._name, {
                files : {
                   '../{{thisTheme._name}}/' : '/child_themes/lib/*' // note that it can't use grunt templating since the loop is dynamic and the index is unknown.  Unless there were a grunt template method for dynamic unkown meta values...
                }
            });

Create dest directory

I have been struggling (but nevertheless looking forward to using the new version) the last days to migrate my main project to Grunt 0.4.0. Right now I'm stuck when trying to use this plugin. I use a copy task like this:
copy: {
jquery: {
files: [
{expand: true, cwd: 'libs/jQuery/ui-lightness/images/', src: ['.'], dest: 'dist/css/img/'}
]
}
}
and would expect the dist/css/images directory to be created as needed.
Do I have wrong expectations, do I use it the wrong way or is this a problem with the plugin ?

Docs for processContent arguments

I hunted it down to the source where file.copy is called passing contents and srcpath as arguments, but this doesn't seem to be documented. It would be useful to know that the signature of the function is processContent(content, srcpath).

Push 0.4.0 to NPM

Hey guys -

I need the cwd option, and it looks like that was first introduced in 0.4.0a. I know rc5 support is also needed, but it'd be a huge help if you could push 0.4.0a to npm in the interim.

Thanks!
Matt

Copy absolute paths

In the 0.3.x, copying /Users/xxx/some/file.js to /Users/xxx/test/ would properly copy file.js to the test/ folder.

In 0.4.x, the complete folder structure will be replicated: /Users/xxx/test/Users/xxx/some/file.js

What's the expected behavior here? Is this intentional or a bug?

copy modified?

Are there plans, or a possiblity of having a "copy modified" instead of all?

How can I copy to multiple destinations?

Here's my current config:

copy: {
      build: {
        files: [
            //Copy the javascript files
            {
              expand: true,     // Enable dynamic expansion.
              cwd: 'scripts/',
              src: ['**/*.js'], // Actual pattern(s) to match.
              dest: '../js/',   // Destination path prefix.
              ext: '.js',   // Dest filepaths will have this extension.
              rename: function(dest, src){
                    return dest + src; //this is actually much more complicated in my code
              }
            },

            //Copy the javascript files -debug
            {
              expand: true,     // Enable dynamic expansion.
              cwd: '../js/',
              src: ['**/*.js'], // Actual pattern(s) to match.
              dest: '../js/',   // Destination path prefix.
              ext: '-debug.js',   // Dest filepaths will have this extension.
            },
        ],
      }
    }

What I want to do is this:

  1. Drop into scripts folder and do some processing and renaming so that the result lives in ../js.
  2. Go into ../js and go through each .js file and for each file, make an exact copy in the exact location with the filename ending in -debug.js.

With my current config, if I run grunt the first time, only the first task (drop into scripts and do the processing/copying)` would run.

I need to run grunt again in order for the second copy (debug) to be generated.

It seems to me that before performing any copy, it actually first check to see if all the copy rules can be executed even though the second copy rule depends on the first one.

Is there anyway to make grunt ignore that and just run the first then second rule sequentially?

Installing grunt-contrib-copy always goes on the 0.3.x

Hi,

I've successfully intalled the grunt 0.4.x (see my issue post on the grunt repository).

And i've the same problem with this plugin. The installer always install the 0.3.x version instead of the 0.4.x, sugin the command "npm install grunt-contrib-copy --save-dev"

So i've manually added the good version in the package.json to install the good one : "grunt-contrib-copy": "~0.4.0"

Omit the parent directory when copying

With the following code:

copy: {
    assets: {
      files: {'dist/': 'src/assets/**'}
    }
 }

It copies and creates directories src and assets in the dist directory. Is there anyway omit the first directory? So the structure is dist/assets/

Thanks!

stupid api

why not follow others, like grunt-contrib-clean

I think this is better

copy: {

    output: {

        html: {
            src: ["path/**", "path/*"],
            dest: "../output",

            options: {

            }
        },

        options: {

            // strip: /^_/
            processName: function(filename) {
                if (/^_/.test(filename) return false;
            }
        }
    },

    release: {
        src: "<%= dirs.release %>",
        dest: "<%= dirs.output %>"
    }

if processName function return false, strip?

ps:

path like "../output", error:

ReferenceError: path is not defined
    at /data/dev/grunt/G/dev/node_modules/grunt-contrib/node_modules/grunt-contrib-copy/tasks/copy.js:95:17
    at Array.forEach (native)
    at module.exports.findBasePath (/data/dev/grunt/G/dev/node_modules/grunt-contrib/node_modules/grunt-contrib-copy/tasks/copy.js:94:14)
    at module.exports.basePaths (/data/dev/grunt/G/dev/node_modules/grunt-contrib/node_modules/grunt-contrib-copy/tasks/copy.js:58:38)
    at Array.forEach (native)
    at Object.module.exports.basePaths (/data/dev/grunt/G/dev/node_modules/grunt-contrib/node_modules/grunt-contrib-copy/tasks/copy.js:54:16)
    at Object.task.registerMultiTask.thisTask (/usr/local/share/npm/lib/node_modules/grunt/lib/grunt/task.js:109:15)
    at Object.task.registerTask.thisTask.fn (/usr/local/share/npm/lib/node_modules/grunt/lib/grunt/task.js:58:16)
    at Task.<anonymous> (/usr/local/share/npm/lib/node_modules/grunt/lib/util/task.js:341:36)
    at Task.<anonymous> (/usr/local/share/npm/lib/node_modules/grunt/lib/util/task.js:317:9)

Cannot call method forEach of undefined...

I'm using grunt-contrib-copy with grunt 0.4, and i get this error every time I try to use it:

Running "copy:publish" (copy) task
Warning: Cannot call method 'forEach' of undefined Use --force to continue.

This is my task, but I don't think it's related to it:

    copy: {
      publish: {
        files: [
          {src: ['tests/**', 'example/**', 'knockout.app.js'], dest: '_site'}
        ]
      }
    },

options consistency

@cowboy @ctalkington

Per #8 can we figure out the best way to handle this? Also, I think passing the filename into the process function as an argument might be handy, that way the process function could be branched based on the filename, if the author desired.

test failure

@ctalkington, any ideas?

>> copy - minimatch
>> AssertionMessage: should allow for minimatch dot option
>> AssertionError [ '.hidden', 'test.js' ] deepEqual [ 'test.js' ]
>>   at Object.assertWrapper [as deepEqual] (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/lib/types.js:83:39)
>>   at Object.exports.copy.minimatch (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/test/copy_test.js:38:10)
>>   at Object.wrapTest (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/lib/core.js:235:16)
>>   at Object.wrapTest (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/lib/core.js:235:16)
>>   at wrapTest (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/lib/core.js:235:16)
>>   at Object.exports.runTest (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/lib/core.js:69:9)
>>   at exports.runSuite (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/lib/core.js:117:25)
>>   at _concat (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/deps/async.js:508:13)
>>   at async.forEachSeries.iterate (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/deps/async.js:118:13)
>>   at async.forEachSeries.iterate (/Users/tkellen/Code/node/grunt/grunt-contrib-copy/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/deps/async.js:129:25)

Corrupted copy

Hi,

I've encountered a strange issue where items that I wish to copy are corrupted upon transfer to the destination directory. They end up having different file sizes and cannot be opened.

The files I am copying are mostly images and fonts.

Sample config below:

        copy: {

            dist: {
                files: {
                    "_build/dist/": [
                        "*.html",
                        "libs/**/*",                
                        "assets/{fonts,images}/**/*",
                        "{src,element}/**/*"
                    ]
                }
            }

        }

Best way to exclude files?

I want to copy client/js/** to public/js and exclude all files that end in .coffee - What's the best way to do this?

Right now I'm trying "./public/js/": ["./client/js/**","!./client/js/*.coffee"]

Update for compatibility with grunt 0.4.0rc5

I need someone to help update this plugin to work with grunt 0.4.0rc5.

I had to revert the whole file src-dest mappings implicit iteration abstraction per gruntjs/grunt#606, and once again, multi tasks have to iterate over this.files manually. In addition, there's a new this.filesSrc array that contains a reduced, uniqued set of all matched src files in case the task is read-only and only cares about source files.

See:

Notes:

  • A user may specify a new option nonull in addition to src to tell grunt to keep patterns or filepaths that don't actually match files. Because of this, the task shouldn't explode if a nonexistent src filepath is encountered. I handle this in the grunt-contrib-concat by warning if not grunt.file.exists but not failing the task.

Guidelines for updating / publishing this plugin:

  • Change this project's version number to one ending in "rc5" so that it's clearer that it works with grunt 0.4.0rc5. If the existing version number doesn't end in an "a" or "rc" increment the patch version. Eg, jshint went from 0.1.0 -> 0.1.1rc5
  • Ensure grunt 0.4.0rc5-compatible plugins are specified in package.json devDependencies like this (grunt-contrib-internal can be "*")
  • Update the CHANGELOG like this
  • Regenerate the README.md file via grunt.
  • Delete node_modules, run npm cache clean and re-run npm install to test.
  • Publish to npm using --tag=master (not latest)

Not copying empty dirs

Hiya,
I'd like my dist dir to have two empty directories, so the future users of my project know that additional files can be placed there. I thought of providing 2 empty dirs in the source dir and copy them to the dist dir, since I couldn't find a "create dir" plugin for gruntjs and I like this copy plugin :)

I get the error: Unable to copy; no valid source files were found. Use --force to continue.
I'm using Windows.

folder structure:

sjaak/
  dist
  src/
    modules (empty dir to be copied)
    utils (empty dir to be copied)
    core/
      (src core files)
    (src files)

Excerpt of grunt.js file:

...
copy: {
  dist: {
    files: {
      'dist/': 'src/modules' // For now just /modules/ to test
    }
  }
}
..

This issue was also addressed in: https://github.com/gruntjs/grunt-contrib/issues/103
There it was noted that this issue was fixed, but to me it seems it's not.

How can I get latest version?

Executing npm install grunt-contrib-copy --save-dev gives me version 0.3.2 instead of 0.4.0. Is this a plugin issue or do I have something malconfigured in my local environment?

copy seems to corrupt image files.

when I run a copy task to send images from one dir to another, the image files aren't readable anymore. The source appears to be missing data from the source file.

Any ideas?

Thanks!

Individual files not run through processContent

Logs all of the files in src/css

files: {
    'dist/less/': 'src/less/**'
},
options: {
    processContent: function(file) {
        console.log(file);
    }
}

Doesn't log anything

files: {
    'dist/less/base.less': 'src/less/base.less'
},
options: {
    processContent: function(file) {
        console.log(file);
    }
}

Intermediate directories skipped

If I have a copy task such as:

copy: {
  build: {
    files: {
      'dest/': 'src/**'
    }
  }
}

and the file structure of src looks like:

src/
└──stuff
    ├── file1.js
    └── file2.js

I would expect the output to be:

dest/
└──stuff
    ├── file1.js
    └── file2.js

but instead, I get:

dest/
├──file1.js
└──file2.js

I imagine the issue is that there are no files at the same level as the intermediate "stuff" directory.

I was using version 0.3.2 of this task.

repeating folder names in src causes the copied file structure to be incorrect

just ran into this one.

I was trying to do the following:

files: {
  'foo/bar/css/themes/': 'hello/world/hello/code/css/themes/**'
}

There are two files in the hello/world/../themes folder, we'll call them style1.css and style2.css. I was expecting the output to be:

foo/
  bar/
    css/
      themes/
        style1.css
        style2.css

Instead I got:

foo/
  bar/
    css/
      themes/
        hello/
          world/
            hello/
              code/
                css/
                  themes/
                    style1.css
                    style2.css

changing the path from hello/world/hello/... to hello/world/something-else/... seems to have fixed the problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.