Asset compilation/packaging/compression utility
npm install brewer
|1||downloads in the last day|
|1||downloads in the last week|
|25||downloads in the last month|
|Version||0.3.12 last updated a year ago|
|Dependencies (9)||underscore, commander, walk, growl, ansi-color, semver, request, coffee-script, temp|
Your asset management best friend.
This project is about to have a significant API change, making it leaner, simpler and ready for a few big improvements
- Compilation of LESS or Stylus files to CSS
- Watching a directory for changes, triggering any or all of the above.
Watching a whole project structure of Coffee-script, LESS or Stylus source files can be as easy as :
$ brake watch Info Watching project /path/to/current/working/directory Compiled coffee/test.coffee Compiled less/index.less Packaged build/css/index.css Compressed build/css/index.css
If you wish to improve Brewer.js, feel free to fork the project on Github. Then, clone your fork somewhere on your computer, where you would do your own changes. If you are going to do this, you might want to
cd to your working copy and :
$ npm link
This will turn your working copy as a global node module so you can use your version of the executable
brake to test things out. You can always reinstall the official version using :
$ npm install -g brewer
Always update the tests (located in
tests/) to reflect your changes and make sure they pass before submitting your changes. You will need coffee-script to be installed globally to run the tests. You can run the tests as follow :
$ cake test
When you feel your fork is awesome (that includes you've updated the tests to reflect your changes and all the tests pass), go ahead and do a Pull Request, explaining what awesomeness you've added. If everything is in order and the project stays consistent with its goal, we'll merge it right in!
Using a prepared package
To setup Brewer.js, make sure you have installed Node.js. When this is done, enter the terminal and type.
$ npm install -g brewer
-g flag is used to make the installation global, so you get access to the
brake executable. Then, from a project directory you wish to manage using Brewer.js
$ brake init [<template name>]
<template name> part is optional. Anyway, for the moment, there is only one template available, lesscoffee, which is also the default. This template sets up LESS and Coffeescript support for the current directory.
What this does is create a Brewfile in the current directory, according to the template provided and run
brake make on it (see Usage).
Using this repository
You need Node.js, as well as coffee-script, installed globally to get the
cake executable. You can do so by doing :
$ npm install -g coffee-script
Then, to get brewer.js to work locally
$ git clone firstname.lastname@example.org:matehat/brewer.js.git brewer $ cd brewer $ npm install $ cake build
Then, if you want the
brewer executable, you can do
$ npm link
A Brewfile is a file that sits at the root folder of your project, named,
well, "Brewfile", which syntax is plain Coffeescript. It is used to specify the structure of the project to Brewer.js, so it knows what to do when you tell it to
At the top-level of the Brewfile, the following functions are available :
Those two functions can be used interchangeably with
css to be more concise. The
package_name is used to identify certain parts of a project, in case you would like to run
$ brake make package_name. A Package is a conceptual component of a project in which you can define bundles and in which files can import each other. A file contained in a package can really be anywhere on the file system -- a package is not bound to a specific directory.
Package can receive options, which can be specified in one of two ways :
build option specifies where to put bundles aggregated from source files, and
compress … well, I think you can guess that one.
@options is a method available in the package definition body, that specifies additional options for the package. Another such method is
@bundles(bundle1, bundle2, ...) which specifies file names for bundles in the package (see Bundles below). These two methods are prefixed with a
@, meaning that they are members of the package body context. Other methods of this kind are available, such as those to define sources in a package.
Now for a real-world example, so we don't get lost too quickly. Say we want to make a cool looking website using jQuery, Bootstrap and Chosen. Each of these libraries have their own source files, of different types and we want to manage all of that neatly. Here is the directory structure :
Root folder |-- js |-- coffee |-- css |-- less |-- vendor |-- bootstrap | |- less | |- js | |-- chosen |-- jquery.js
./vendor/bootstrap/js. Now let's look at what a bundle would look like :
# in coffee/home.coffee # import ["jquery", "chosen/chosen.jquery.js"] $ -> $('select').chosen()
If we had been running
brake watch while we wrote that script and saved it, we would have seen a file appear, named
coffee/home.coffee can be found in
./_cache. If we wanted it to appear somewhere more meaningful, we could set the
output option on a source directive. A more complete example of the above could be :
This dedicates a directory
./build, to contain files that would be deployed, and all source files in separate directories. You may have noticed we used
The command-line interface for brewer provides a few methods to manage the asset project.
brake init <template_name>
This command tells brewer to make a Brewfile in the current directory, according to the template provided, and make an initial directory structure to support the project.
brake clean [<package>*]
This command tells brewer to delete files that strongly depends on source files, such as those that are completely derived from the compilation of another file, bundles and their compressed counterparts.
This command tells brewer to first run
brake makeon the current directory and watch for changes (file content change, new files, moved files or deleted files).
This command tells Brewer.js to install all missing Node.js modules that it needs to work properly with the current project. For instance, had I put a few
@coffeescriptsource directives in the project's Brewfile, Brewer.js will make sure the coffee-script module is available, installing it under its own project directory if not.
Copyright © 2012 Mathieu D'Amours
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.