grunt-contrib-copy
Advanced tools
Comparing version 0.3.2 to 0.4.0-rc7
{ | ||
"name": "grunt-contrib-copy", | ||
"description": "Copy files and folders.", | ||
"version": "0.3.2", | ||
"version": "0.4.0rc7", | ||
"homepage": "https://github.com/gruntjs/grunt-contrib-copy", | ||
@@ -31,7 +31,10 @@ "author": { | ||
"dependencies": { | ||
"grunt-lib-contrib": "~0.3.0" | ||
"grunt-lib-contrib": "~0.4.0" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.3.15", | ||
"grunt-contrib-clean": "~0.3.0" | ||
"grunt-contrib-jshint": "0.1.1rc6", | ||
"grunt-contrib-nodeunit": "0.1.2rc6", | ||
"grunt-contrib-clean": "0.4.0rc6", | ||
"grunt-contrib-internal": "~0.1.1", | ||
"grunt": "0.4.0rc7" | ||
}, | ||
@@ -38,0 +41,0 @@ "keywords": [ |
@@ -5,45 +5,46 @@ # grunt-contrib-copy [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-copy.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-copy) | ||
### Recent Confusion | ||
Many expect this task to work like `cp` on *nix systems but it was designed to use grunt conventions including the use of minimatch regex. We are working hard to make this and other tasks suitable for advanced users but there are no current plans to emulate `cp`. | ||
## 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][Getting Started] as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command: | ||
### Configuration | ||
```shell | ||
npm install grunt-contrib-copy --save-dev | ||
``` | ||
Inside your `grunt.js` file add a section named `copy`. This section specifies the files to copy. | ||
[grunt]: http://gruntjs.com/ | ||
[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md | ||
#### Parameters | ||
##### files ```object``` | ||
## Copy task | ||
_Run this task with the `grunt copy` command._ | ||
This defines what files this task will copy and should contain key:value pairs. | ||
_This task is a [multi task][] so any targets, files and options should be specified according to the [multi task][] documentation._ | ||
[multi task]: https://github.com/gruntjs/grunt/wiki/Configuring-tasks | ||
The key (destination) should be an unique path (supports [grunt.template](https://github.com/gruntjs/grunt/blob/master/docs/api_template.md)) and the value (source) should be a filepath or an array of filepaths (supports [minimatch](https://github.com/isaacs/minimatch)). | ||
As of v0.3.0, when copying to a directory you must add a trailing slash to the destination due to added support of single file copy. | ||
_Version `0.4.x` of this plugin is compatible with Grunt `0.4.x`. Version `0.3.x` of this plugin is compatible with Grunt `0.3.x`._ | ||
##### options ```object``` | ||
### Options | ||
This controls how this task operates and should contain key:value pairs, see options below. | ||
#### processContent | ||
Type: `Function` | ||
#### Options | ||
This option is passed to `grunt.file.copy` as an advanced way to control the file contents that are copied. | ||
##### basePath ```string``` | ||
#### processContentExclude | ||
Type: `String` | ||
This option adjusts the folder structure when copied to the destination directory. When not explicitly set, best effort is made to locate the basePath by comparing all source filepaths left to right for a common pattern. | ||
This option is passed to `grunt.file.copy` as an advanced way to control which file contents are processed. | ||
##### flatten ```boolean``` | ||
### Usage Examples | ||
This option performs a flat copy that dumps all the files into the root of the destination directory, overwriting files if they exist. | ||
##### processName ```function``` | ||
This option accepts a function that adjusts the filename of the copied file. Function is passed filename and should return a string. | ||
``` javascript | ||
options: { | ||
processName: function(filename) { | ||
if (filename == "test.jpg") { | ||
filename = "newname.jpg"; | ||
} | ||
return filename; | ||
```js | ||
copy: { | ||
main: { | ||
files: [ | ||
{src: ['path/*'], dest: 'dest/', filter: 'isFile'}, // includes files in path | ||
{src: ['path/**'], dest: 'dest/'}, // includes files in path and its subdirs | ||
{expand: true, cwd: 'path/', src: ['**'], dest: 'dest/'}, // makes all src relative to cwd | ||
{expand: true, flatten: true, src: ['path/**'], dest: 'dest/', filter: 'isFile'} // flattens results to a single level | ||
] | ||
} | ||
@@ -53,32 +54,19 @@ } | ||
##### processContent ```function``` | ||
This option is passed to `grunt.file.copy` as an advanced way to control the file contents that are copied. | ||
## Release History | ||
##### processContentExclude ```string``` | ||
* 2013-01-22 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-13 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-17 v0.3.2 Pass copyOptions on single file copy. | ||
* 2012-10-11 v0.3.1 Rename grunt-contrib-lib dep to grunt-lib-contrib. | ||
* 2012-09-23 v0.3.0 General cleanup and consolidation. Global options depreciated. | ||
* 2012-09-17 v0.2.4 No valid source check. | ||
* 2012-09-16 v0.2.3 Path.sep fallback for node <= 0.7.9. | ||
* 2012-09-16 v0.2.2 Single file copy support. Test refactoring. | ||
* 2012-09-06 v0.2.0 Refactored from grunt-contrib into individual repo. | ||
This option is passed to `grunt.file.copy` as an advanced way to control which file contents are processed. | ||
--- | ||
##### minimatch ```object``` | ||
Task submitted by [Chris Talkington](http://christalkington.com/) | ||
These options will be forwarded on to expandFiles, as referenced in the [minimatch options section](https://github.com/isaacs/minimatch/#options) | ||
#### Config Example | ||
``` javascript | ||
copy: { | ||
dist: { | ||
files: { | ||
"path/to/directory/": "path/to/source/*", // includes files in dir | ||
"path/to/directory/": "path/to/source/**", // includes files in dir and subdirs | ||
"path/to/project-<%= pkg.version %>/": "path/to/source/**", // variables in destination | ||
"path/to/directory/": ["path/to/sources/*.js", "path/to/more/*.js"], // include JS files in two diff dirs | ||
"path/to/filename.ext": "path/to/source.ext" | ||
} | ||
} | ||
} | ||
``` | ||
-- | ||
*Task submitted by [Chris Talkington](https://github.com/ctalkington).* | ||
*This file was generated on Wed Jan 23 2013 10:40:27.* |
@@ -13,10 +13,4 @@ /* | ||
// TODO: ditch this when grunt v0.4 is released | ||
grunt.util = grunt.util || grunt.utils; | ||
var path = require('path'); | ||
// TODO: remove if/when we officially drop node <= 0.7.9 | ||
path.sep = path.sep || path.normalize('/'); | ||
grunt.registerMultiTask('copy', 'Copy files.', function() { | ||
@@ -27,13 +21,6 @@ var kindOf = grunt.util.kindOf; | ||
var options = helpers.options(this, { | ||
basePath: false, | ||
flatten: false, | ||
processName: false, | ||
processContent: false, | ||
processContentExclude: [], | ||
minimatch: {} | ||
processContentExclude: [] | ||
}); | ||
// TODO: ditch this when grunt v0.4 is released | ||
this.files = this.files || helpers.normalizeMultiTaskFiles(this.data, this.target); | ||
var copyOptions = { | ||
@@ -46,63 +33,23 @@ process: options.processContent, | ||
var srcFiles; | ||
var destType; | ||
var dest; | ||
var isExpandedPair; | ||
var basePath; | ||
var filename; | ||
var relative; | ||
var destFile; | ||
var srcFile; | ||
this.files.forEach(function(filePair) { | ||
isExpandedPair = filePair.orig.expand || false; | ||
this.files.forEach(function(file) { | ||
file.dest = path.normalize(file.dest); | ||
srcFiles = grunt.file.expandFiles(options.minimatch, file.src); | ||
filePair.src.forEach(function(src) { | ||
if (detectDestType(filePair.dest) === 'directory') { | ||
dest = (isExpandedPair) ? filePair.dest : unixifyPath(path.join(filePair.dest, src)); | ||
} else { | ||
dest = filePair.dest; | ||
} | ||
if (srcFiles.length === 0) { | ||
grunt.fail.warn('Unable to copy; no valid source files were found.'); | ||
} | ||
destType = detectDestType(file.dest); | ||
if (destType === 'file') { | ||
if (srcFiles.length === 1) { | ||
srcFile = path.normalize(srcFiles[0]); | ||
grunt.verbose.or.write('Copying file' + ' to ' + file.dest.cyan + '...'); | ||
grunt.file.copy(srcFile, file.dest, copyOptions); | ||
grunt.verbose.or.ok(); | ||
if (grunt.file.isDir(src)) { | ||
grunt.log.writeln('Creating ' + dest.cyan); | ||
grunt.file.mkdir(dest); | ||
} else { | ||
grunt.fail.warn('Unable to copy multiple files to the same destination filename, did you forget a trailing slash?'); | ||
grunt.log.writeln('Copying ' + src.cyan + ' -> ' + dest.cyan); | ||
grunt.file.copy(src, dest, copyOptions); | ||
} | ||
} else if (destType === 'directory') { | ||
basePath = helpers.findBasePath(srcFiles, options.basePath); | ||
grunt.verbose.writeln('Base Path: ' + basePath.cyan); | ||
grunt.verbose.or.write('Copying files' + ' to ' + file.dest.cyan + '...'); | ||
srcFiles.forEach(function(srcFile) { | ||
srcFile = path.normalize(srcFile); | ||
filename = path.basename(srcFile); | ||
relative = path.dirname(srcFile); | ||
if (options.flatten) { | ||
relative = ''; | ||
} else if (basePath && basePath.length >= 1) { | ||
relative = grunt.util._(relative).strRight(basePath).trim(path.sep); | ||
} | ||
if (options.processName && kindOf(options.processName) === 'function') { | ||
filename = options.processName(filename); | ||
} | ||
// make paths outside grunts working dir relative | ||
relative = relative.replace(/\.\.(\/|\\)/g, ''); | ||
destFile = path.join(file.dest, relative, filename); | ||
grunt.file.copy(srcFile, destFile, copyOptions); | ||
}); | ||
grunt.verbose.or.ok(); | ||
} | ||
}); | ||
}); | ||
@@ -112,3 +59,3 @@ }); | ||
var detectDestType = function(dest) { | ||
if (grunt.util._.endsWith(dest, path.sep)) { | ||
if (grunt.util._.endsWith(dest, '/')) { | ||
return 'directory'; | ||
@@ -119,2 +66,10 @@ } else { | ||
}; | ||
var unixifyPath = function(filepath) { | ||
if (process.platform === 'win32') { | ||
return filepath.replace(/\\/g, '/'); | ||
} else { | ||
return filepath; | ||
} | ||
}; | ||
}; |
@@ -5,6 +5,6 @@ var grunt = require('grunt'); | ||
exports.copy = { | ||
test: function(test) { | ||
main: function(test) { | ||
'use strict'; | ||
test.expect(2); | ||
test.expect(3); | ||
@@ -15,8 +15,13 @@ var actual = fs.readdirSync('tmp/copy_test_files').sort(); | ||
actual = fs.readdirSync('tmp/copy_test_mix').sort(); | ||
expected = fs.readdirSync('test/expected/copy_test_mix').sort(); | ||
test.deepEqual(expected, actual, 'should copy a mix of folders and files'); | ||
actual = fs.readdirSync('tmp/copy_test_v0.1.0').sort(); | ||
expected = fs.readdirSync('test/expected/copy_test_v0.1.0').sort(); | ||
test.deepEqual(expected, actual, 'should copy several folders and files (with template support)'); | ||
test.deepEqual(expected, actual, 'should parse both dest and src templates'); | ||
test.done(); | ||
}, | ||
flatten: function(test) { | ||
@@ -33,13 +38,3 @@ 'use strict'; | ||
}, | ||
minimatch: function(test) { | ||
'use strict'; | ||
test.expect(1); | ||
var actual = fs.readdirSync('tmp/copy_minimatch').sort(); | ||
var expected = fs.readdirSync('test/expected/copy_minimatch').sort(); | ||
test.deepEqual(expected, actual, 'should allow for minimatch dot option'); | ||
test.done(); | ||
}, | ||
single: function(test) { | ||
@@ -46,0 +41,0 @@ 'use strict'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
32
13524
5
160
71
2
+ Addedgrunt-lib-contrib@0.4.0(transitive)
- Removedgrunt-lib-contrib@0.3.1(transitive)
Updatedgrunt-lib-contrib@~0.4.0