UNPKG

@tangelo/tangelo-configuration-toolkit

Version:

Tangelo Configuration Toolkit is a command-line toolkit which offers support for developing a Tangelo configuration.

20 lines (16 loc) 722 B
// based on gulp-batch-replace const es = require('event-stream'), minimatch = require('minimatch'), istextorbinary = require('istextorbinary'); const execReplace = (c, s, r) => Buffer.from(s instanceof RegExp ? String(c).replace(s, r) : String(c).split(s).join(r)); module.exports = arr => { return es.map((file, callback) => { if(file.contents instanceof Buffer) { for (const e of arr) { // exec if no glob is passed or if glob matches, and it's a text file if ((!e[2] || minimatch(file.path, e[2])) && istextorbinary.isText(file.path, file)) { file.contents = execReplace(file.contents, e[0], e[1]); } } } callback(null, file); }); };