How to use the gulp-changed.compareContents function in gulp-changed

To help you get started, we’ve selected a few gulp-changed examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mangalam-research / wed / gulptasks / gulpfile.js View on Github external
gulp.task("config", () => {
  const dest = "build/config";
  // In effect, anything in localConfigPath overrides the same file in
  // config.
  const configPath = "config";
  const localConfigPath = "local_config";
  return gulp.src(path.join(configPath, "**"), { nodir: true })
    .pipe(es.map((file, callback) =>
                 vinylFile.read(
                   path.join(localConfigPath, file.relative),
                   { base: localConfigPath })
                 .then(override => callback(null, override),
                       () => callback(null, file))))
  // We do not use newer here as it would sometimes have
  // unexpected effects.
    .pipe(changed(dest, { hasChanged: changed.compareContents }))
    .pipe(gulp.dest(dest));
});
github colinrotherham / core / tasks / copy.js View on Github external
const pathsCopy = [

		// Copy all files
		`${config.paths.src}/**/*.*`,

		// Skip templates
		`!${config.paths.src}/templates`,
		`!${config.paths.src}/templates/**`,

		// Skip assets
		`!${config.paths.src}/assets`,
		`!${config.paths.src}/assets/**`
	];

	const options = {
		hasChanged: changed.compareContents
	};

	return () => stream.merge(

		gulp.src(pathsCopy, { dot: true })
			.pipe(changed(config.paths.build, options))
			.pipe(gulp.dest(config.paths.build))
			.pipe(preservetime()),

		gulp.src(`${config.paths.srcAssets}/**`, { dot: true })
			.pipe(changed(config.paths.build, options))
			.pipe(gulp.dest(config.paths.buildAssets))
			.pipe(preservetime())
	);
};
github colinrotherham / core / src / tasks / copy.js View on Github external
export default (config, gulp) => {

  const options = config.options || {
    hasChanged: changed.compareContents,
  };

  return () => gulp.src(config.src, { dot: true })
    .pipe(changed(config.dest, options))
    .pipe(gulp.dest(config.dest))
    .pipe(preservetime());
};
github gdh1995 / vimium-c / Gulpfile.js View on Github external
function compareContentAndTouch(stream, sourceFile, targetPath) {
  if (sourceFile.isNull()) {
    return gulpChanged.compareContents.apply(this, arguments);
  }
  var isSame = false, equals = sourceFile.contents.equals,
  newEquals = sourceFile.contents.equals = function(targetData) {
    var curIsSame = equals.apply(this, arguments);
    isSame || (isSame = curIsSame);
    return curIsSame;
  };
  return gulpChanged.compareContents.apply(this, arguments
  ).then(function() {
    sourceFile.contents.equals === newEquals && (sourceFile.contents.equals = equals);
    if (!isSame) { return; }
    var sourcePath = sourceFile.history && sourceFile.history[0] || targetPath;
    if (targetPath.slice(-3) === ".js") {
      let sourcePath2 = sourcePath.slice(-3) === ".js" ? sourcePath.slice(0, -3) + ".ts" : sourcePath;
      if (fs.existsSync(sourcePath2)) { sourcePath = sourcePath2; }
    }
    if (touchFileIfNeeded(targetPath, sourcePath)) {
      var fileName = sourceFile.relative;
      print("Touch an unchanged file:", fileName.indexOf(":\\") > 0 ? fileName : fileName.replace(/\\/g, "/"));
    }
  }).catch(function(e) {
    sourceFile.contents.equals === newEquals && (sourceFile.contents.equals = equals);
    throw e;
  });

gulp-changed

Only pass through changed files

MIT
Latest version published 10 months ago

Package Health Score

66 / 100
Full package analysis