Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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));
});
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())
);
};
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());
};
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;
});