Skip to content

Instantly share code, notes, and snippets.

@evanhalley
Created March 24, 2020 18:20
Show Gist options
  • Save evanhalley/153d46be1cd98c7dfbfa7de5d05e93ef to your computer and use it in GitHub Desktop.
Save evanhalley/153d46be1cd98c7dfbfa7de5d05e93ef to your computer and use it in GitHub Desktop.
Small example of using the very basics of gulp.
const { series, src, dest } = require('gulp');
const tap = require('gulp-tap');
function helloWorld(cb) {
console.log('hello world');
cb();
}
function helloWorldPromise() {
return new Promise((resolve, reject) => {
console.log('hello world promise');
resolve();
});
}
function reverseTextFiles() {
return src('*.txt')
.pipe(tap(file => reverseText(file)))
.pipe(dest('output/'));
}
function reverseText(file) {
let reversed = file.contents.toString()
.split("")
.reverse()
.join("");
file.contents = Buffer.from(reversed);
}
exports.default = helloWorld;
exports.helloWorld = helloWorld;
exports.helloWorldPromise = helloWorldPromise;
exports.promiseFirst = series(helloWorldPromise, helloWorld);
exports.reverse = reverseTextFiles;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment