Skip to content

normalize copy plugin. Fixes #166 #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/plugins/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var join = require('path').join;
var mkdirp = require('mkdirp');
var Batch = require('batch');
var cp = require('cp');
var basename = require('path').basename;

/**
* Ops
Expand Down Expand Up @@ -41,7 +42,7 @@ module.exports = function(type, dest, opts){
build.each(type, function(file, conf){
batch.push(function(done){
var src = conf.path(file);
var base = conf.name.replace('/', '-');
var base = normalize(conf, build.components);
var to = join(dest, base, file);
var dir = dirname(to);
exists(to, function(exist){
Expand All @@ -62,3 +63,19 @@ module.exports = function(type, dest, opts){
batch.end(done);
};
};


/**
* Normalize conf name.
*
* @param {Object} conf
* @param {Array} list
* @return {String}
* @api private
*/

function normalize(conf, list){
return conf == list[0]
? conf.name
: require('path').basename(conf.path());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks weird; why not just use basename defined at L14?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why I did that. Removed L14.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to not require() inside a function, since it's sync ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yields shouldn't matter, as path has been required multiple times areadly in this file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, i know require()'s are cached :) just looks weird IMHO haha

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah looks very weird i agree

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I’ve moved it.
-- 
Aaron Zhang

On March 10, 2014 at 3:28:49 PM, Stephen Mathieson ([email protected]) wrote:

In lib/plugins/copy.js:

@@ -62,3 +63,19 @@ module.exports = function(type, dest, opts){
batch.end(done);
};
};
+
+
+/**

  • * Normalize conf name.
  • * @param {Object} conf
  • * @param {Array} list
  • * @return {String}
  • * @api private
  • */
    +
    +function normalize(conf, list){
  • return conf == list[0]
  • ? conf.name
  • : require('path').basename(conf.path());
    yeah looks very weird i agree


Reply to this email directly or view it on GitHub.

}