Example #1
0
function transformFilename(file, par) {
	// save the old path for later
	file.revOrigPath = file.path;
	file.revOrigBase = file.base;

    // replace revHash with our custom string 
    if (par) {
        if (par.customRev) {
            file.revHash = par.customRev;
        }
    }

    if (!file.revHash) {
    	file.revHash = revHash(file.contents);
    }

	file.path = modifyFilename(file.path, function (filename, extension) {
		var extIndex = filename.indexOf('.');

		filename = extIndex === -1 ?
			revPath(filename, file.revHash) :
			revPath(filename.slice(0, extIndex), file.revHash) + filename.slice(extIndex);

		return filename + extension;
	});
}
Example #2
0
function transformFilename(file) {
	// save the old path for later
	file.revOrigPath = file.path;
	file.revOrigBase = file.base;
	file.revHash = revHash(file.contents);
	file.path = revPath(file.path, file.revHash);
}
Example #3
0
	return pify(readFile)(file).then(buffer => {
		const hashed = revHash(buffer);
		const revved = revPath(file, hashed);
		return {
			original: file,
			hash: hashed,
			revved: revved
		};
	});
Example #4
0
const generateRevisionedAsset = (filename, content) => {
  const hash = revHash(content);
  const revisionedFilename = revPath(filename, hash);

  // Updates the internal revision map so it can be referenced later.
  addAsset(filename, revisionedFilename);

  fs.outputFileSync(
      path.join(config.publicStaticDir, revisionedFilename), content);
};
Example #5
0
 return through.obj(function(file, enc, cb) {
   file.orgPath = file.path;
   file.orgRelative = file.relative;
   file.revHash = revHash(file.contents);
   file.path = modifyFilename(file.path, function(filename, extension) {
     var extIndex = filename.indexOf('.');
     filename =
       extIndex === -1
         ? revPath(filename, file.revHash)
         : revPath(filename.slice(0, extIndex), file.revHash) +
           filename.slice(extIndex);
     return filename + extension;
   });
   cb(null, file);
 });
Example #6
0
function transformFilename(file) {
	// save the old path for later
	file.revOrigPath = file.path;
	file.revOrigBase = file.base;
	file.revHash = revHash(file.contents);

	file.path = modifyFilename(file.path, function (filename, extension) {
		var extIndex = filename.indexOf('.');

		filename = extIndex === -1 ?
			revPath(filename, file.revHash) :
			revPath(filename.slice(0, extIndex), file.revHash) + filename.slice(extIndex);

		return filename + extension;
	});
}
Example #7
0
function transformFilename(file, opts) {
  var hash = revHash(file.contents);
  var ret_path = "";
  file.path = modifyFilename(file.path, function(filename, ext) {
    if (opts.showName == true) {
      ret_path += filename;
    }
    if (opts.showSize == true) {
      var info = imageinfo(file.contents);
      var size = parseInt(file.contents.length / 1024, 10);
      ret_path += "_" + info.width + "x" + info.height + "_" + size;
    }
    if (opts.showHash == true) {
      ret_path += "_" + hash;
    }
    if (ret_path.length === 0) {
      ret_path = filename;
    }
    return ret_path + ext;
  });
}
Example #8
0
function isNeedNewVersion(currentFile, lastVersionFile) {
  return lastVersionFile == null || revHash(currentFile.contents) != revHash(lastVersionFile.contents);
}
Example #9
0
export function getOutFileName(source, fileName, rev) {
  return rev ? revPath(fileName, revHash(new Buffer(source, 'utf-8'))) : fileName;
}