Example #1
0
Fingerprint.prototype.processFile = function(srcDir, destDir, relativePath) {
  if (this.keepOriginal) {
    helpers.copyPreserveSync(srcDir + '/' + relativePath, destDir + '/' + relativePath);
  }

  return Filter.prototype.processFile.apply(this, arguments);
};
Example #2
0
GzipFilter.prototype.processFile = function(srcDir, destDir, relativePath) {
  if (this.keepUncompressed) {
    helpers.copyPreserveSync(srcDir + '/' + relativePath, destDir + '/' + relativePath);
  }

  return Filter.prototype.processFile.apply(this, arguments);
};
Example #3
0
    return mapSeries(paths, function(relativePath) {
        if (/\/$/.test(relativePath)) {
            mkdirp.sync(destDir + '/' + relativePath)
        } else {
            helpers.copyPreserveSync(
                path.join(srcDir, relativePath),
                path.join(destDir, relativePath)
            )

            if (/\.css$/.test(relativePath)) {
                var srcPath  = path.join(srcDir, relativePath);
                var destPath = path.join(destDir, relativePath);
                var rawcss   = fs.readFileSync(srcPath, { encoding: 'utf8' });
                var pages    = self.split(rawcss, MAX_SELECTORS);

                for (var i=1; i<pages.length; i++) {
                    var finalDestPath = destPath.replace(/\.css$/, '.' + i + '.css');
                    fs.writeFileSync(finalDestPath, css.stringify(pages[i]), { encoding: 'utf8'});
                }

            }

        }

    });
    cacheEntry.outputFiles.forEach(function (outputFile) {
        var cachePath = path.join(cacheDir, outputFile),
            destPath  = path.join(destDir, outputFile);

        // TODO: switch to `symlinkOrCopySync()` after:
        // https://github.com/broccolijs/broccoli/issues/179
        mkdirp.sync(path.dirname(destPath));
        helpers.copyPreserveSync(cachePath, destPath);
    });
Example #5
0
    acceptedFiles.forEach(function (file) {
      var srcFile = path.join(srcDir, file);
      var destFile = path.join(destDir, outputDir, file);
      var stat = fs.lstatSync(srcFile);

      if (stat.isFile() || stat.isSymbolicLink()) {
        mkdirp.sync(path.dirname(destFile));
        helpers.copyPreserveSync(srcFile, destFile, stat);
      }
    });
Example #6
0
 function copyFromCache (cacheEntry) {
   for (var i = 0; i < cacheEntry.outputFiles.length; i++) {
     var dest = destDir + '/' + cacheEntry.outputFiles[i]
     mkdirp.sync(path.dirname(dest))
     // We may be able to link as an optimization here, because we control
     // the cache directory; we need to be 100% sure though that we don't try
     // to hardlink symlinks, as that can lead to directory hardlinks on OS X
     helpers.copyPreserveSync(
       self.getCacheDir() + '/' + cacheEntry.cacheFiles[i], dest)
   }
 }
 return mapSeries(paths, function (relativePath) {
   if (relativePath.slice(-1) === '/') {
     mkdirp.sync(destDir + '/' + relativePath);
   } else {
     if (self.canProcessFile(relativePath)) {
       return self.processAndCacheFile(srcDir, destDir, relativePath);
     } else {
       helpers.copyPreserveSync(srcDir + '/' + relativePath, destDir + '/' + relativePath);
     }
   }
 }).then(function () {
Example #8
0
 return mapSeries(paths, function (relativePath) {
   if (relativePath.slice(-1) === '/') {
     mkdirp.sync(self.outputPath + '/' + relativePath)
   } else {
     if (self.canProcessFile(relativePath)) {
       return self.processAndCacheFile(self.inputPath, self.outputPath, relativePath)
     } else {
       helpers.copyPreserveSync(
         self.inputPath + '/' + relativePath, self.outputPath + '/' + relativePath)
     }
   }
 })
Example #9
0
  return mapSeries(this.inputTrees, readTree).then(function (treePaths) {
    for (var i = treePaths.length - 1; i >= 0; i--) {
      var treeContents = walkSync(treePaths[i])
      treeContents = treeContents.map(toLowerCase)

      var fileIndex
      for (var j = 0; j < treeContents.length; j++) {
        var relativePath = treeContents[j]
        var destPath = destDir + '/' + relativePath
        if (relativePath.slice(-1) === '/') { // is directory
          relativePath = relativePath.slice(0, -1) // chomp "/"
          fileIndex = files[relativePath]
          if (fileIndex != null) {
            throwFileAndDirectoryCollision(relativePath, fileIndex, i)
          }
          if (directories[relativePath] == null) {
            fs.mkdirSync(destPath)
            directories[relativePath] = i
          }
        } else { // is file
          var directoryIndex = directories[relativePath]
          if (directoryIndex != null) {
            throwFileAndDirectoryCollision(relativePath, i, directoryIndex)
          }
          fileIndex = files[relativePath]
          if (fileIndex != null) {
            if (!self.options.overwrite) {
              throw new Error('Merge error: ' +
                'file "' + relativePath + '" exists in ' +
                treePaths[i] + ' and ' + treePaths[fileIndex] + ' - ' +
                'pass option { overwrite: true } to mergeTrees in order ' +
                'to have the latter file win')
            }
            // Else, ignore this file. It is "overwritten" by a file we copied
            // earlier, thanks to reverse iteration over trees
          } else {
            helpers.copyPreserveSync(
              treePaths[i] + '/' + relativePath, destPath)
            files[relativePath] = i
          }
        }
      }
    }

    function throwFileAndDirectoryCollision (relativePath, fileIndex, directoryIndex) {
      throw new Error('Merge error: "' + relativePath +
        '" exists as a file in ' + treePaths[fileIndex] +
        ' but as a directory in ' + treePaths[directoryIndex])
    }
  })
Example #10
0
 function copyToCache (cacheInfo) {
   var cacheEntry = {
     inputFiles: (cacheInfo || {}).inputFiles || [relativePath],
     outputFiles: (cacheInfo || {}).outputFiles || [self.getDestFilePath(relativePath)],
     cacheFiles: []
   }
   for (var i = 0; i < cacheEntry.outputFiles.length; i++) {
     var cacheFile = (self._cacheIndex++) + ''
     cacheEntry.cacheFiles.push(cacheFile)
     helpers.copyPreserveSync(
       destDir + '/' + cacheEntry.outputFiles[i],
       self.getCacheDir() + '/' + cacheFile)
   }
   cacheEntry.hash = hash(cacheEntry.inputFiles)
   self._cache[relativePath] = cacheEntry
 }
Example #11
0
MainFilePicker.prototype.write = function (readTree, destDir) {
  for (var i = 0; i < this.mainFiles.length; i++) {
    var mainFile = this.mainFiles[i]
    try {
      if (mainFile.indexOf('*') !== -1 || mainFile.indexOf('?') !== -1) {
        throw new Error('In ' + this.dir + ': Glob (wildcard) patterns in bower\'s `main` property are not allowed: ' + mainFile)
      }
      helpers.copyPreserveSync(
        path.join(this.dir, mainFile),
        path.join(destDir, path.basename(mainFile)))
    } catch (err) {
      if (err.code !== 'ENOENT') throw err
      throw new Error('In bower directory ' + this.dir + ': Cannot find file specified in bower `main` property: ' + mainFile)
    }
  }
}
  return readTree(self.inputTree).then(function(srcDir) {
    var baseDir = path.join(srcDir, self.options.srcDir || "");
    var files = helpers.multiGlob(["**/*.js"], {
      cwd: baseDir,
      root: baseDir,
      nomount: false
    });
    console.log(files);

    for (var i = 0; i < files.length; i++) {
      mkdirp.sync(path.join(destDir, self.options.destDir || "", path.dirname(files[i])))
      helpers.copyPreserveSync(
        path.join(srcDir, self.options.srcDir || "", files[i]),
        path.join(destDir, self.options.destDir || "", path.basename(files[i]))
      )
    }
  });
Example #13
0
 return readTree(this.inputTree).then(function (srcDir) {
   if (self.options.files == null) {
     helpers.copyRecursivelySync(
       path.join(srcDir, self.options.srcDir),
       path.join(destDir, self.options.destDir))
   } else {
     var baseDir = path.join(srcDir, self.options.srcDir)
     var files = helpers.multiGlob(self.options.files, {
       cwd: baseDir,
       root: baseDir,
       nomount: false
     })
     for (var i = 0; i < files.length; i++) {
       mkdirp.sync(path.join(destDir, self.options.destDir, path.dirname(files[i])))
       helpers.copyPreserveSync(
         path.join(srcDir, self.options.srcDir, files[i]),
         path.join(destDir, self.options.destDir, files[i]))
     }
   }
 })
Example #14
0
        jsFiles.forEach(function (relPath) {
            var cacheEntry = cache[relPath],
                srcPath    = path.join(srcDir, relPath),
                statsHash  = helpers.hashTree(srcPath),
                type;

            if (cacheEntry && cacheEntry.statsHash === statsHash) {
                type = cacheEntry.type;
            } else {
                type = moduleFormat(fs.readFileSync(srcPath, 'utf8'));

                cache[relPath] = {
                    type: type,
                    statsHash: statsHash
                };
            }

            if (type === expectedType) {
                mkdirp.sync(path.join(destDir, path.dirname(relPath)));
                helpers.copyPreserveSync(srcPath, path.join(destDir, relPath));
            }
        });
        walkSync(srcDir).forEach(function (relPath) {
            // Keep track of all the JavaScript modules.
            if (path.extname(relPath) === '.js') {
                modules.push(relPath);
                return;
            }

            // Skip doing anything with dir entries. When outputting a bundle
            // format some dirs may go away. For non-JavaScript files, their
            // containing dir will be created before they are copied over.
            if (relPath.charAt(relPath.length - 1) === '/') {
                return;
            }

            var srcPath  = path.join(srcDir, relPath),
                destPath = path.join(destDir, relPath);

            // Copy over non-JavaScript files to the `destDir`.
            //
            // TODO: switch to `symlinkOrCopySync()` after:
            // https://github.com/broccolijs/broccoli/issues/179
            mkdirp.sync(path.dirname(destPath));
            helpers.copyPreserveSync(srcPath, destPath);
        });
Example #16
0
    inputFiles.forEach(function (inputFile) {
      var originalInputFile = inputFile;
      var srcFile = path.join(srcDir, inputFile);
      var srcStat = fs.lstatSync(srcFile);

      var hash;
      if (srcStat.isFile()) {
        hash = makeHash(fs.readFileSync(srcFile));
      } else if (srcStat.isSymbolicLink()) {
        hash = makeHash(fs.readlinkSync(srcFile));
      } else {
        return;
      }

      // Append "-hash" to the file name, just before the extension.
      inputFile = addSuffixBeforeExt(inputFile, '-' + hash.substring(0, hashLength));

      var destFile = path.join(destDir, inputFile);

      mkdirp.sync(path.dirname(destFile));
      helpers.copyPreserveSync(srcFile, destFile, srcStat);

      manifestMap[originalInputFile] = inputFile;
    });