UNPKG

@swift-ws/gulp-kit

Version:

A starter kit for automating frontend development using Gulp.js.

18 lines (16 loc) 776 B
import {relative, join} from 'path'; import {gulpIf, gulpReplace} from '../plugins.js'; export const applyReplacements = (config, stream) => { if (config.replacements && Array.isArray(config.replacements) && config.replacements.length > 0) { config.replacements.forEach(replacement => { stream = stream.pipe(gulpIf(file => { const relativeFilePath = relative(process.cwd(), file.path); return replacement.files.some(filePattern => { const normalizedPattern = join(...filePattern.split(/[\/\\]/)); return relativeFilePath.includes(normalizedPattern); }); }, gulpReplace(replacement.find, replacement.replace))); }); } return stream; };