Created
March 24, 2020 18:20
-
-
Save evanhalley/153d46be1cd98c7dfbfa7de5d05e93ef to your computer and use it in GitHub Desktop.
Small example of using the very basics of gulp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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