Use Bootstrap Project Manager to manage multiple Twitter Bootstrap projects without having to maintain multiple versions of Bootstrap.
If you gon't already have Grunt installed, do this.
$ npm install -g grunt-cli
Clone Bootstrap Project Manager.
$ git clone https://github.com/cdcarson/bootstrap-project-manager.git
Change into the directory.
$ cd bootstrap-project-manager
Initialize and update the Bootstrap submodule.
$ git submodule init
$ git submodule update
Install the dependencies.
$ npm install
All commands take the the following form:
$ grunt <command>:<project-name>
$ grunt init:foobar
This command initializes a new project. It:
- Creates the
bootstrap-roject-manger/projectsfolder if one does not exist (i.e. this is your first project.) This folder is.gitignore'd, and is where your projects are stored. - Under that directory, it creates the project folder named with what you provided to the command, in this case
foobar. - Copies the Bootstrap fonts from
boostrap/fontsintofoobar/assets/fonts. See update-fonts. - Concats and minifies the js
boostrap/jsintofoobar/assets/js. See update-bootstrap-js. - Creates
less/style.less. This file contains one line:@import "../../../bootstrap/less/bootstrap";. That file is compiled and minified. See update-css. - Creates a
project.jsonfile that tracks versions and where you can add additional targets. See bump.
The file layout:
- bootstrap-project-manager
- projects
- foobar
- assets
- css
- style.css
- style.min.css
- fonts
- glyphicons-halflings-regular.eot
- glyphicons-halflings-regular.svg
- glyphicons-halflings-regular.ttf
- glyphicons-halflings-regular.woff
- js
- bootstrap.js
- bootstrap.min.js
- less
- style.less
- project.json
$ grunt update-fonts:foobar
- Freshly copies the Bootstrap fonts from
bootstrap/fontstofoobar/assets/fonts. Note that other font files and directories infoobar/assets/fontsare not overwritten. - For each target you've defined:
- Cleans the
target/assets/fontsdirectory withclean. This means that fonts you've added to the target without adding them tofoobar/assets/fontswill be deleted. - Copies everything from
foobar/assets/fontstotarget/assets/fonts
- Cleans the
- Bumps the version number if called directly from the command line
$ grunt update-bootstrap-js:foobar
- Creates fresh copies of
bootstrap.jsandbootstrap.min.jsinfoobar/assets/jsfrom the bootstrap source code usingconcatanduglify. Note that other js files and directories infoobar/assets/jsare not overwritten. - For each target you've defined:
- Cleans the
target/assets/jsdirectory withclean. This means that anything you've added to the target without adding them tofoobar/assets/jswill be deleted. - Copies everything from
foobar/assets/jstotarget/assets/js
- Cleans the
- Bumps the version number if called directly from the command line
$ grunt update-css:foobar
- Compiles
less/style.lessintofoobar/assets/css/style.cssandfoobar/assets/css/style.min.cssusingrecess. Note that other css files and directories infoobar/assets/cssare not overwritten. - The
less/directory is where you'll make your style changes. All the files in this directory are watched by thewatchercommand below; but onlyless/style.lessis compiled That means that you have to@importthe LESS files you want intostyle.less. - For each target you've defined:
- Cleans the
target/assets/cssdirectory withclean. This means that anything you've added to the target without adding them tofoobar/assets/csswill be deleted. - Copies everything from
foobar/assets/csstotarget/assets/css
- Cleans the
- Bumps the version number if called directly from the command line
$ grunt bump:foobar
- Bumps the least significant version number in
project.json.
$ grunt watch-css:foobar
- Calls update-css once, then uses
watchto watch theassets/lessdirectory for changes. update-css is called every time a less file changes. - Bumps the version number every time.
- Do control-c to remove the watch.
project.json looks like this:
{
"name": "foobar",
"description": "New project. Put your description here.",
"version": "0.0.4",
"targets": []
}
You can change the description and version number. The project name should always be the same as the directory name.
Additionally, you can add use the targets array to pass additional file paths to be updated when update-fonts, update-bootstrap-js, or update-css are called:
{
"name": "foobar",
"description": "New project. Put your description here.",
"version": "0.0.4",
"targets": [
"/Users/chris/dev/another",
"/Users/chris/dev/something",
]
}
This will copy assets/css, assets/fonts and assets/js into both /Users/chris/dev/another and /Users/chris/dev/something every time the project changes.