Permalink
Browse files

Issue #115 Sort out the mess that is recursion in PackageTask

  • Loading branch information...
mde
mde committed Jun 10, 2012
1 parent 7f93f2f commit df6b38c45422a4d158daa7c88be32f8d0e23d7c3
Showing with 35 additions and 37 deletions.
  1. +3 −3 Jakefile
  2. +3 −9 lib/file_list.js
  3. +16 −19 lib/package_task.js
  4. +13 −6 lib/utils/file.js
View
@@ -46,9 +46,9 @@ var p = new jake.NpmPublishTask('jake', [
, 'Jakefile'
, 'README.md'
, 'package.json'
-, 'lib/*'
-, 'bin/*'
-, 'tests/*'
+, 'lib/**'
+, 'bin/**'
+, 'tests/**'
]);
jake.Task['npm:definePackage'].invoke();
View
@@ -22,16 +22,10 @@ var fs = require('fs')
glob.globSync = function (pat) {
var dirname = path.dirname(pat)
- , files = fs.readdirSync(dirname)
- , filePat = path.basename(pat)
+ , files = jake.readdirR(dirname)
, matches;
- matches = minimatch.match(files, filePat, {'null': true});
- if (matches && matches.length) {
- for (var i = 0, ii = matches.length; i < ii; i++) {
- matches[i] = dirname + '/' + matches[i];
- }
- }
- return matches
+ matches = minimatch.match(files, pat, {'null': true});
+ return matches;
};
// Constants
View
@@ -290,34 +290,31 @@ PackageTask.prototype = new (function () {
self.packageFiles.forEach(function (name) {
var f = path.join(self.packageDirPath(), name)
, fDir = path.dirname(f)
- , fDirArr = fDir.split('/')
- , baseDir = ''
, stats;
+ jake.mkdirP(fDir, {silent: true});
- // Make any necessary container directories
- fDirArr.forEach(function (dir) {
- baseDir += baseDir ? '/' + dir : dir;
- if (!path.existsSync(baseDir)) {
- fs.mkdirSync(baseDir, 0755);
- }
- });
-
- // Add both files and directories, will be copied with -R
+ // Add both files and directories
fileList.push({
- to: name
- , from: f
+ from: name
+ , to: f
});
});
var _copyFile = function () {
var cmd
- , file = fileList.pop();
+ , file = fileList.pop()
+ , stat;
if (file) {
- // Do recursive copy of files and directories
- cmd = 'cp -R ' + file.to + ' ' + file.from;
- exec(cmd, function (err, stdout, stderr) {
- if (err) { throw err; }
+ stat = fs.statSync(file.from);
+ // Target is a directory, just create it
+ if (stat.isDirectory()) {
+ jake.mkdirP(file.to, {silent: true});
_copyFile();
- });
+ }
+ // Otherwise copy the file
+ else {
+ jake.cpR(file.from, file.to, {silent: true});
+ _copyFile();
+ }
}
else {
complete();
View
@@ -114,16 +114,20 @@ var fileUtils = new (function () {
fs.rmdirSync(dir);
};
- this.cpR = function (fromPath, toPath) {
+ this.cpR = function (fromPath, toPath, options) {
var from = path.normalize(fromPath)
, to = path.normalize(toPath)
, toStat
, doesNotExistErr
, paths
, filename
- , opts = {};
+ , opts = options || {};
- logger.log('cp -r ' + fromPath + ' ' + toPath);
+ if (!opts.silent) {
+ logger.log('cp -r ' + fromPath + ' ' + toPath);
+ }
+
+ opts = {}; // Reset
if (from == to) {
throw new Error('Cannot copy ' + from + ' to itself.');
@@ -201,9 +205,12 @@ var fileUtils = new (function () {
return format == 'string' ? ret.join('\n') : ret;
};
- this.rmRf = function (p) {
- var stat;
- logger.log('rm -rf ' + p);
+ this.rmRf = function (p, options) {
+ var stat
+ , opts = options || {};
+ if (!opts.silent) {
+ logger.log('rm -rf ' + p);
+ }
try {
stat = fs.statSync(p);
if (stat.isDirectory()) {

0 comments on commit df6b38c

Please sign in to comment.