Giter Site home page Giter Site logo

cake-flour's Introduction

Flour

Flour is a set of simple build tools for your Cakefiles.

image

Usage

npm install flour, don't forget to add it to your package.json. Do require 'flour' at the top of your Cakefile, the tools are added to global scope.

This is what a typical Cakefile could look like:

require 'flour'

task 'lint', 'Check javascript syntax', ->
    lint 'js/feature.js'

task 'build:plugins', ->
    bundle [
        'vendor/underscore.js'
        'vendor/hogan.js'
        'vendor/backbone.js'
    ], 'js/plugins.js'

task 'build:coffee', ->
    compile 'coffee/app.coffee', 'js/app.js'

task 'build:less', ->
    compile 'less/main.less', 'css/main.css'

task 'build', ->
    invoke 'build:plugins'
    invoke 'build:coffee'
    invoke 'build:less

task 'watch', ->
    invoke 'build:less'
    invoke 'build:coffee'

    watch 'less/*.less', -> invoke 'build:less'
    watch 'coffee/app.coffee', -> invoke 'build:coffee'

(if the global pollution hurts your feelings you can remove them with flour.noConflict(). That will bring the global object back to it's previous state)

Each of these functions can accept either a single file path or an array of files. Simple wildcard paths like *.xxx are also accepted. Example using watch with a list of files:

watch [
    'less/main.less'
    'less/reset.less'
    'less/print.less'
], -> invoke 'build:less'

You can also access the resulting output by passing a callback:

compile 'coffee/app.coffee', (output) ->
    # do something with the compiled output
    mail.send subject: 'Project file', to: '[email protected]', body: output

# if you don't trust the CS compiler
compile 'coffee/app.coffee', 'js/app.js', -> lint 'js/app.js'

Reference

Compile

Compiles LESS and CoffeeScript files:

compile(file, [destination], [callback])
Usage
compile 'app.coffee', 'app.js'

compile 'cold.coffee', 'app.js', (output) ->
    console.log 'Done!'

compile 'cold.coffee', (output) ->
    console.log output.transform()

Bundle

Compile, minify and join a set of files (preserving order):

bundle(files, destination)
Usage
bundle [
    'lib/jquery.js'
    'lib/underscore.js'
    'lib/backbone.js'
], 'js/bundle.js'

bundle 'js/*.js', 'js/all.js'

Watch

Watch files for changes:

watch(files, action)
Usage
watch 'src/app.coffee', ->
    compile 'lib/app.js'

# best used with predefined tasks:

task 'build', ->
    bundle '*.coffee', 'app.js'

task 'watch', ->
    watch [
        'modules.coffee'
        'user.coffee'
        'main.coffee'
    ], ->
        invoke 'build'

# or
watch '*.coffee', -> invoke 'build'

Lint

Check file syntax (uses JSHint):

lint(file, [options], [globals]) # see http://www.jshint.com/options/

Usage

task 'lint', ->

    lint 'scripts/*.js'

Minify

Minify files (currently only Javascript using UglifyJS):

minify(file, [destination], [callback])

Extensibility

You can add new minifiers and compilers to flour:

flour.minifiers['.stupid'] = (file, cb) ->
    file.read (code) ->
        cb code.replace(/\s*/, '')

flour.compilers['.odd'] = (file, cb) ->
    odd = require 'odd-lib'
    file.read (code) ->
        cb odd.compile code

Tricks

Disable the JS minifier for development

task 'watch', ->
    # pass code through unchanged
    flour.minifiers['.js'] = (file, cb) -> cb file.buffer

    # see useful line numbers when debugging!
    watch 'scripts/*.coffee', -> invoke 'build'

Pre-compile Hogan templates

flour.compilers['.mustache'] = (file, cb) ->
    hogan = require 'hogan.js'
    file.read (code) ->
        cb "App.templates['#{file.base}']=${hogan.compile code, asString: true};"

task 'build:templates', ->
    bundle 'views/*.mustache', 'resources/views.js'

Why?

While Grunt, brewerjs, H5BP-build-script and other similar projects have the same (and some more advanced) capabilities, they are increasingly complex. The goal of Flour is to provide a small, short and sane API for the most common build tasks without requiring you to adjust your project structure, install extra tools or create long configuration files. Cake is all you need!

TODO:

  • tests
  • figure out how to magically bundle hogan templates

cake-flour's People

Contributors

elving avatar ricardobeat avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.