Backbone Stack (0.2.6)
A pre-configured Backbone Stack for starting new projects, it alleviates a lot of the common boilerplate code and setup. It uses AMD modules, mocha for TDD and handlebars precompiled templates. Grunt plays a major role in the automated linting, testing and building of your code.
Latest changes (31st Mar 2013)
- Update package.json to use grunt 0.4.1 for node 0.10.x
- Upgrade Backbone to v 1.0.0.
- Add node-version-assets for cache busting
- Add less compile step
- Add boostrap from bower
- Grunt - A task runner like Make, used to watch and compile the JS code
- Require JS - To asynchronously load in all of the scripts and templates
- Almond - To run the built AMD code in production
- jQuery - For DOM manipulation and ajax
- Handlebars JS - for templating
- Twitter Bootstrap - For a quick and dirty UI prototype
Libraries for Test Driven Development
- Chai.js - Nice assertions
- Sinon - Spies, Stubs and Mocks
Bower is used as for package management, the default client-side dependencies are listed in the
# Install bower package manager $ npm install -g bower # Install grunt build tool $ npm install -g grunt-cli # Install additional grunt tasks $ npm install # Install client-side packages $ bower install
# Search for a library $ bower search [name..] # Install a library and save it to the component.json file $ bower install [name..] --save
Running your app
Open up the
./index.html file in your browser to view your app, it will be using pre-compiled templates and build and minified JS.
Testing your code
The unit tests can be opened up in the browser with the
test/test-runner.html file, or can be done through grunt on the command line.
The idea behind linting first, then testing and then building is to fail as quickly and early as possible, this will really help to boost productivity.
# Watch src/ and test/ files and lint, test, then build on change (handy for TDD) $ grunt watch # Lint and test files $ grunt test
Note the test suite loads requireJS dynamically and you don't need to build to run the tests, this lets you do TDD with less effort.
Building your code
# Watch src/ and test/ files and test, then build on change $ grunt watch # Do a one off build - will lint and test your code first $ grunt build # Compile the handlebars templates $ grunt handlebars # Compile less and css styles $ grunt styles
git pre-commit hook
Simply run these commands inside your project dir to set a commit hook that will run before each commit. If any of the test or build phase fails the commit will not be accepted.
# Create a pre-commit hook $ touch .git/hooks/pre-commit # Make executable $ chmod +x .git/hooks/pre-commit # Build on commit $ echo "grunt test" > .git/hooks/pre-commit
- Pete Hawkins - github.com/phawk
- Miguel Andrade - github.com/miguelcobain
Copyright (C) 2013 Pete Hawkins
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.