Skip to content

Commit

Permalink
general cleanup and consolidation.
Browse files Browse the repository at this point in the history
findBasePath has been moved to contrib-lib.
  • Loading branch information
ctalkington committed Sep 23, 2012
1 parent 8e38f27 commit e29ea0b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -78,7 +78,8 @@ copy: {

## Release History

* 2012/09/24 - v0.2.5 - general cleanup and consolidation.
* 2012/09/18 - v0.2.4 - no valid source check.
* 2012/09/17 - v0.2.3 - path.sep fallback for node <= 0.7.9.
* 2012/09/17 - v0.2.2 - single file copy support. test refactoring.
* 2012/08/10 - v0.2.0 - Refactored from grunt-contrib into individual repo.
* 2012/09/07 - v0.2.0 - Refactored from grunt-contrib into individual repo.
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "grunt-contrib-copy",
"description": "Copy files and folders.",
"version": "0.2.4",
"version": "0.2.5-alpha",
"homepage": "https://github.com/gruntjs/grunt-contrib-copy",
"author": {
"name": "Chris Talkington",
Expand Down
34 changes: 6 additions & 28 deletions tasks/copy.js
Expand Up @@ -14,7 +14,6 @@ module.exports = function(grunt) {
grunt.util = grunt.util || grunt.utils;

var path = require('path');
var _ = grunt.util._;

// TODO: remove if/when we officially drop node <= 0.7.9
path.sep = path.sep || path.normalize('/');
Expand All @@ -40,11 +39,6 @@ module.exports = function(grunt) {
noProcess: options.processContentExclude
};

if (options.basePath) {
options.basePath = path.normalize(options.basePath);
options.basePath = _(options.basePath).trim(path.sep);
}

grunt.verbose.writeflags(options, 'Options');

var srcFiles;
Expand Down Expand Up @@ -77,8 +71,8 @@ module.exports = function(grunt) {
} else {
grunt.fail.warn('Unable to copy multiple files to the same destination filename, did you forget a trailing slash?');
}
} else if (destType === 'dir') {
basePath = options.basePath || findBasePath(srcFiles);
} 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 + '...');
Expand All @@ -90,8 +84,8 @@ module.exports = function(grunt) {

if (options.flatten) {
relative = '';
} else if (basePath && basePath.length > 1) {
relative = _(relative).chain().strRight(basePath).trim(path.sep).value();
} else if (basePath && basePath.length >= 1) {
relative = grunt.util._(relative).strRight(basePath).trim(path.sep);
}

if (options.processName && kindOf(options.processName) === 'function') {
Expand All @@ -111,25 +105,9 @@ module.exports = function(grunt) {
});
});

var findBasePath = function(srcFiles) {
var basePaths = [];
var dirName;

srcFiles.forEach(function(srcFile) {
dirName = path.dirname(srcFile);
dirName = path.normalize(dirName);

basePaths.push(dirName.split(path.sep));
});

basePaths = _.intersection.apply([], basePaths);

return path.join.apply(path, basePaths);
};

var detectDestType = function(dest) {
if (_.endsWith(dest, path.sep)) {
return 'dir';
if (grunt.util._.endsWith(dest, path.sep)) {
return 'directory';
} else {
return 'file';
}
Expand Down

0 comments on commit e29ea0b

Please sign in to comment.