Example #1
0
exports.sync = function(srcPattern, destPattern, options) {
  if (!options) options = {};

  // extract src vars
  var result = resolve.sync(srcPattern, destPattern, options);

  var srcPaths = result.src.paths;
  var destPaths = result.dest.paths;

  srcPaths.forEach(function(src, i) {
    var dest = destPaths[i];

    var stat = fs.statSync(src);
    var isDir = stat.isDirectory();

    if (options.force) rimraf.sync(dest);

    if (isDir) {
      var readdir = (options.recursive) ? _recursiveReaddirSync : _readFilesSync;
      var srcFiles = readdir(src);

      srcFiles.forEach(function(_src) {
        var _dest = _destFile(src, _src, dest);
        cp.sync(_src, _dest, options);
      })

    } else {
      cp.sync(src, dest, options);
    }

  });

};
Example #2
0
exports.sync = function(srcPattern, destPattern, options) {
  if (!options) options = {};

  // extract src vars
  var result = resolve.sync(srcPattern, destPattern, options);

  var srcPaths = result.src.paths;
  var destPaths = result.dest.paths;

  srcPaths.forEach(function(src, i) {
    src = path.resolve(src);
    var dest = path.resolve(destPaths[i]);


    // make sure the dest directory exists
    var destPath = (dest.charAt(dest.length - 1) == '/') ? dest.slice(0, -1) : dest;
    var dir = path.dirname(destPath);
    mkdirp.sync(dir, options);

    // check src type
    var stat = fs.statSync(src);
    var type = stat.isDirectory() ? 'dir' : 'file';

    if (!options.force) {
      try {
        // try unlink first
        fs.unlinkSync(dest);
      } catch (err) {
        // most likely link didn't exist, which is o.k.
      } finally {
        fs.symlinkSync(src, dest, type);
      }
    } else {
      rimraf.sync(dest);
      fs.symlinkSync(src, dest, type);
    }

  });

};