Last active
September 19, 2024 18:16
-
-
Save Raynos/8313682 to your computer and use it in GitHub Desktop.
Revisions
-
Raynos renamed this gist
Jan 8, 2014 . 1 changed file with 37 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,62 @@ var uglifyJS = require('uglify-js'); var glob = require('glob-stream').create; var watch = require('glob-watcher'); var through = require('through'); var fs = require('fs'); var path = require('path'); // uglify -.- wtf. make stream kind of. // gulp-uglify should be like this instead! function uglify() { var stream = through() // mikeal style pipe hack because uglify -.- stream.on('pipe', function (src) { var fileName = src.fileName fs.readFile(fileName, function (err, file) { if (err) { return stream.emit('error', err) } var payload try { payload = uglifyJS.minify(String(file), { fromString: true }).code } catch (err) { return stream.emit('error', err) } stream.end(payload) }) }) return stream } // gulp.src should be like this! function src(patterns) { return glob(patterns) .pipe(through(function (file) { var stream = fs.createReadStream(file.path) stream.fileName = file.path return stream })) } // gulp.dest should be like this! function dest(baseDir) { return through(function (fileStream) { fileStream.pipe(fs.createWriteStream( path.join(baseDir, path.filename(fileStream.fileName)) )) }) } // gulp.task is not needed, just use functions! var tasks = { 'scripts': function () { src(['client/js/**/*.js', '!client/js/vendor/**']) .pipe(through(function (fileStream) { return fileStream.pipe(uglify()); })) .pipe(dest('build/js')) @@ -58,5 +88,8 @@ var tasks = { } } // you don't need a special gulp command // just node taskFile.js scripts to run scripts. // or `alias gulp = node taskFile.js` var cmd = process.argv[3] || 'default'; tasks[cmd](); -
Raynos revised this gist
Jan 8, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ function src(patterns) { return glob(patterns) .pipe(through(function (file) { var stream = fs.createReadStream(file.path) stream.fileName = path.filename(file.path) return stream })) } -
Raynos revised this gist
Jan 8, 2014 . 1 changed file with 0 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,3 @@ var uglify = require('uglify'); var glob = require('glob-stream').create; var watch = require('glob-watcher'); -
Raynos revised this gist
Jan 8, 2014 . 1 changed file with 6 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,12 +6,9 @@ var uglify = require('uglify'); var glob = require('glob-stream').create; var watch = require('glob-watcher'); var through = require('through'); var fs = require('fs'); var path = require('path'); function src(patterns) { return glob(patterns) @@ -34,6 +31,7 @@ var tasks = { 'scripts': function () { src(['client/js/**/*.js', '!client/js/vendor/**']) .pipe(through(function (fileStream) { // assume uglify has a clean streaming interface -.- return fileStream.pipe(uglify()); })) .pipe(dest('build/js')) @@ -65,4 +63,5 @@ var tasks = { } } var cmd = process.argv[3] || 'default'; tasks[cmd](); -
Raynos revised this gist
Jan 8, 2014 . 1 changed file with 31 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,28 @@ /* This is an EXAMPLE gulpfile.js You'll want to change it to match your project. Find plugins at https://npmjs.org/browse/keyword/gulpplugin */ var uglify = require('uglify'); var glob = require('glob-stream').create; var watch = require('glob-watcher'); var argv = require('optimist').argv var through = require('through') var cmd = argv._[0] || 'default'; var concat = require('some-concat-stream') var fs = require('fs') var path = require('path') function src(patterns) { return glob(patterns) .pipe(through(function (file) { var stream = fs.createReadStream(file.path) stream.fileName = file.path return stream })) } function dest(baseDir) { return through(function (fileStream) { fileStream.pipe(fs.createWriteStream( path.join(baseDir, fileStream.fileName) @@ -17,39 +32,37 @@ function sinkFileStream(baseDir) { var tasks = { 'scripts': function () { src(['client/js/**/*.js', '!client/js/vendor/**']) .pipe(through(function (fileStream) { return fileStream.pipe(uglify()); })) .pipe(dest('build/js')) src('client/js/vendor/**') .pipe(dest('build/js/vendor')) }, 'copy': function () { src('client/img/**') .pipe(dest('build/img')) src('client/css/**') .pipe(dest('build/css')) src('client/*.html') .pipe(dest('build')) }, 'default': function () { tasks.scripts() tasks.copy() watch('client/js/**', tasks.scripts) watch([ 'client/img/**', 'client/css/**', 'client/*.html' ], tasks.copy) } } tasks[cmd]() -
Raynos revised this gist
Jan 8, 2014 . 1 changed file with 2 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,8 @@ var uglify = require('uglify'); var glob = require('some-glob'); var globWatch = require('glob-watch-thing'); var through = require('through') var concat = require('some-concat-stream') var fs = require('fs') var path = require('path') @@ -57,4 +51,5 @@ var tasks = { } } var cmd = process.argv[2] || 'default'; tasks[cmd]() -
Raynos created this gist
Jan 8, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ /* This is an EXAMPLE gulpfile.js You'll want to change it to match your project. Find plugins at https://npmjs.org/browse/keyword/gulpplugin */ var gulp = require('gulp'); var uglify = require('gulp-uglify'); gulp.task('scripts', function() { // Minify and copy all JavaScript (except vendor scripts) gulp.src(['client/js/**/*.js', '!client/js/vendor/**']) .pipe(uglify()) .pipe(gulp.dest('build/js')); // Copy vendor files gulp.src('client/js/vendor/**') .pipe(gulp.dest('build/js/vendor')); }); // Copy all static assets gulp.task('copy', function() { gulp.src('client/img/**') .pipe(gulp.dest('build/img')); gulp.src('client/css/**') .pipe(gulp.dest('build/css')); gulp.src('client/*.html') .pipe(gulp.dest('build')); }); // The default task (called when you run `gulp`) gulp.task('default', function() { gulp.run('scripts', 'copy'); // Watch files and run tasks if they change gulp.watch('client/js/**', function(event) { gulp.run('scripts'); }); gulp.watch([ 'client/img/**', 'client/css/**', 'client/*.html' ], function(event) { gulp.run('copy'); }); }); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ /* This is an EXAMPLE gulpfile.js You'll want to change it to match your project. Find plugins at https://npmjs.org/browse/keyword/gulpplugin */ var uglify = require('uglify'); var glob = require('some-glob'); var globWatch = require('glob-watch-thing'); var argv = require('optimist').argv var through = require('through') var cmd = argv._[0] || 'default'; var concat = require('some-concat-stream') var fs = require('fs') var path = require('path') function sinkFileStream(baseDir) { return through(function (fileStream) { fileStream.pipe(fs.createWriteStream( path.join(baseDir, fileStream.fileName) )) }) } var tasks = { 'scripts': function () { glob(['client/js/**/*.js', '!client/js/vendor/**']) .pipe(through(function (fileStream) { return fileStream.pipe(uglify()); })) .pipe(concat()) .pipe(fs.createWriteStream('build/js')) glob('client/js/vendor/**') .pipe(sinkFileStream('build/js/vendor')) }, 'copy': function () { glob('client/img/**') .pipe(sinkFileStream('build/img')) glob('client/css/**') .pipe(sinkFileStream('build/css')) glob('client/*.html') .pipe(sinkFileStream('build')) }, 'default': function () { tasks.scripts() tasks.copy() globWatch('client/js/**', tasks.scripts) globWatch([ 'client/img/**', 'client/css/**', 'client/*.html' ], tasks.copy) } } tasks[cmd]()