Skip to content

Instantly share code, notes, and snippets.

@evanhalley
Created March 24, 2020 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanhalley/611f4d30acc69fbab7ad4fc47d6a3999 to your computer and use it in GitHub Desktop.
Save evanhalley/611f4d30acc69fbab7ad4fc47d6a3999 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