|
| 1 | +# JS Project Skeleton |
| 2 | +This project tries to provide a nice starting point for your JavaScript projects whether it is browser-oriented library, full-fledged client app or node.js module. |
| 3 | + |
| 4 | +Code is organized in [CommonJS](http://en.wikipedia.org/wiki/CommonJS) modules that can be [stitched](https://github.com/sstephenson/stitch) together for browser usage. All development dependencies are handled with [npm](http://npmjs.org/) and Makefile is provided to avoid typing in complex commands to run tests or build project. |
| 5 | + |
| 6 | +Testing is handled with [mocha](http://visionmedia.github.com/mocha/) allowing for either TDD or BDD style tests. Since both **mocha** and **stitch** support [CoffeeScript](http://coffeescript.org/) you can choose to use it for your project if you like. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +Skeleton requires working installation of **node.js** and **npm** on a Linux or OS X. |
| 11 | + |
| 12 | +Grab the [latest version](https://github.com/grassator/js-project-skeleton/zipball/master) of this repository and unpack it to the folder of your choosing. Then adjust name, description of the project and your personal info inside `package.json` file: |
| 13 | + |
| 14 | + "author": "You <[email protected]>", |
| 15 | + "name": "sample_project", |
| 16 | + "description": "Some amazing project", |
| 17 | + |
| 18 | +You should keep in mind that project name should be web friendly (i.e. alphanumeric characters and `_` or `-`). After that `cd` to your project folder in console and run: |
| 19 | + |
| 20 | + npm install |
| 21 | + |
| 22 | +It will install all project dependencies into `node_modules` folder and you are good to go. To make sure that everything is working try running following command in your terminal: |
| 23 | + |
| 24 | + make build |
| 25 | + |
| 26 | +It should create `build` folder with regular and minified versions of sample code. |
| 27 | + |
| 28 | +## Development |
| 29 | + |
| 30 | +Let's talk about how to use this skeleton. |
| 31 | + |
| 32 | +### Project structure |
| 33 | + |
| 34 | +First of all lets take a look at directory structure for your |
| 35 | + |
| 36 | +* `build/` – contains stitched version of your code + minified file; |
| 37 | +* `demo/` – for demonstration of browser-oriented projects; |
| 38 | +* `lib/` – holds all of your app/lib code; |
| 39 | +* `scripts/` – support folder for skeleton build and server scripts; |
| 40 | +* `test/` – contains all the test cases; |
| 41 | +* `vendor/` – for scripts that don't conform to CommonJS. |
| 42 | + |
| 43 | +### Building |
| 44 | + |
| 45 | +As described earlier in installation chapter: |
| 46 | + |
| 47 | + make build |
| 48 | + |
| 49 | +creates stitched version of your project from `lib/` and `vendor/` folders. Filenames are the same as your project name specified in `package.json`. |
| 50 | + |
| 51 | +### Testing |
| 52 | + |
| 53 | + make test |
| 54 | + |
| 55 | +or |
| 56 | + |
| 57 | + npm test |
| 58 | + |
| 59 | +runs all tests inside `test/` folder. By default tests use BDD style that can be changed by editing `test` target inside `Makefile`. You can learn more about **mocha** options in [official documentation](http://visionmedia.github.com/mocha/). |
| 60 | + |
| 61 | +### Browser Demo |
| 62 | + |
| 63 | +To be able to run default demo located in `demo/index.html` you first need to start **express** server by running: |
| 64 | + |
| 65 | + make serve |
| 66 | + |
| 67 | +After that you can always get latest stitched version of your project on [localhost:4000/lib.js](http://localhost:4000/lib.js). If open demo page now you should see that *“The answer is 42”*. |
0 commit comments