Skip to content

Instantly share code, notes, and snippets.

@yocontra
Last active April 3, 2017 02:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yocontra/5924386 to your computer and use it in GitHub Desktop.
Save yocontra/5924386 to your computer and use it in GitHub Desktop.
Ideal build system
gulp = require 'gulp'
clean = require 'gulp-clean'
jade = require 'gulp-jade'
coffee = require 'gulp-coffee'
minify = require 'gulp-minify'
###
quick syntax ideas:
gulp.files() takes a glob and is an array of file streams
gulp.folder() is like gulp.files("./folder/**/*") but it maintains directory structure
you can pipe a .folder() or a .files() to another .folder()
.files() and .folder() both take an options argument:
"ignore" is an array which should follow the same syntax and behaviour as a .gitignore file
###
# wipe the public folder
gulp.folder("./public").pipe(clean)
# compile, minify, and copy templates
gulp.folder("./client/templates")
.pipe(jade)
.pipe(minify)
.pipe(gulp.folder("./public/templates"))
# compile, minify, and copy all coffee-script
gulp.folder("./client/js", {ignore:["vendor"]})
.pipe(coffee)
.pipe(minify)
.pipe(gulp.folder("./public/js"))
# minify and copy all vendor files
gulp.folder("./client/js/vendor")
.pipe(minify)
.pipe(gulp.folder("./public/js/vendor"))
# copy static files
gulp.folder("./client/img")
.pipe(gulp.folder("./public/img"))
gulp.folder("./client/css")
.pipe(gulp.folder("./public/css"))
gulp.files("./client/*.html")
.pipe(gulp.folder("./public"))
gulp.files("./client/*.ico")
.pipe(gulp.folder("./public"))
@terinjokes
Copy link

Looks great.

Was thinking it would be great if the modules implemented pipe, so you could do:

groan.folder('./client/js', {ignore:['vendor']})
     .coffee({bare: true})
     .minify({preserveComments: false})
     .folder('./public/js');

That way we limit the amount of visual noise we add to the configuration file. On the other hand, I could see how this deviates, a little, from standard node.

The only other thing I can think of wanted to add is a way to export these so the can be invoked from the command line. Perhaps something like:

module.exports.burntcoffee = groan.folder('./client/js', {ignore:["vendor"]})
                                  .coffee({bare: true})
                                  .folder('./public/js');

Or maybe event a terminating function such as .named('burntcoffee')? I like the latter idea, but would be open to the former or others

@funkytek
Copy link

funkytek commented Jul 4, 2013

+1 I really like the idea of modules implementing pipes, but also have some concern for staying idiomatic

@yocontra
Copy link
Author

yocontra commented Jul 4, 2013

@terinjokes - I'm not sure removing the pipe is a good idea... I do like the idea of a simplified task system. It should just be as easy as assigning a function to a name. Grunt's task system is insanely over-complex. Having a simple task system also lets you break up your code like this

# executed when running `groan buildmyshit` or if another task chooses to run it
groan.task('buildmyshit', function(){
  # do stuff
  groan.folder("./client/js", {ignore:["vendor"]})
    .pipe(coffee)
    .pipe(minify)
    .pipe(groan.folder("./public/js"))
});

# executed when running `groan moveshit or if another task chooses to run it
groan.task('moveshit', function(){
  # do stuff
  groan.folder("./client/img")
    .pipe(groan.folder("./public/img"))

  groan.folder("./client/css")
    .pipe(groan.folder("./public/css"))

  groan.files("./client/*.html")
    .pipe(groan.folder("./public"))

  groan.files("./client/*.ico")
    .pipe(groan.folder("./public"))
});

# executed when just running `groan`
groan.task('default', function(){
  groan.run('buildmyshit', 'moveshit');
});

Any task should be able to .run() other tasks which lets you do some interesting things and maintain a clean build file

@nrn
Copy link

nrn commented Jul 4, 2013

I really like this dude. It's a build system that I wouldn't feel bad using at run time in production.

Though i'm pretty sure

# wipe the public folder
groan.folder("./public").pipe(clean)

should be

# wipe the public folder
clean.pipe(groan.folder("./public"))

@yocontra
Copy link
Author

yocontra commented Jul 4, 2013

@nrn - That might be a case where you wouldn't even need groan - just rimraf("./public")

FYI the name has been changed to gulp since groan is taken. It gulps up your files... i know.

@nrn
Copy link

nrn commented Jul 4, 2013

Good point.

lol, nice....

@yocontra
Copy link
Author

yocontra commented Jul 4, 2013

Repo created https://github.com/wearefractal/gulp

Move all further discussion to gulpjs/gulp#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment