This commit is contained in:
Niels Nübel
2020-12-04 11:11:35 +01:00
commit 3d59b14405
114 changed files with 72924 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
/*
* @title Error Handler
*/
import notifier from "node-notifier";
function errorHandler(error) {
notifier.notify({
title: 'Gulp Error',
message: error.message,
timeout: 3
});
console.error('\x1b[31m', error.message ,'\x1b[0m');
this.emit('end');
}
export default errorHandler;
+47
View File
@@ -0,0 +1,47 @@
'use strict';
var through2 = require('through2');
var gutil = require('gulp-util');
var PLUGIN_NAME = 'gulp-replace-task';
// plugin
module.exports = function (opts) {
return through2.obj(function (file, enc, cb) {
if (file.isNull()) {
this.push(file);
return cb();
}
if (file.isStream()) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME,
'Streaming not supported'));
return cb();
}
var options = opts || {};
var contents = file.contents.toString();
for (const [key, value] of Object.entries(opts)) {
key = key.replace('[','\\[');
key = key.replace(']','\\]');
var re = new RegExp(key, 'g');
contents = contents.replace(re, value);
}
var result = contents;
if (result !== false) {
file.contents = new Buffer.from(result);
} else {
// preserve original file
}
this.push(file);
cb();
});
};