Skip to content

Commit

Permalink
readme driven development
Browse files Browse the repository at this point in the history
  • Loading branch information
joshrowley committed Nov 18, 2014
0 parents commit 50117a1
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules
coverage
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 0.10
after_script:
- npm run coveralls
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
build:
mv lib src
coffee -o lib -c src

unbuild:
rm -rf lib
mv src lib

publish:
make build
npm publish .
make unbuild

coveralls:
NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
31 changes: 31 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

# Contributing to Roots-netlify

Hello there! First of all, thanks for being interested in this project and helping out. We all think you are awesome, and by contributing to open source projects, you are making the world a better place. That being said, there are a few ways to make the process of contributing code to this project smoother, detailed below:

### Filing Issues

If you are opening an issue about a bug, make sure that you include clear steps for how we can reproduce the problem. _If we can't reproduce it, we can't fix it_. If you are suggesting a feature, make sure your explanation is clear and detailed.

### Getting Set Up

- Clone the project down
- Make sure [nodejs](http://nodejs.org) has been installed and is above version `0.10.x`
- Run `npm install`
- Put in work

### Testing

This project is constantly evolving, and to ensure that things are secure and working for everyone, we need to have tests. If you are adding a new feature, please make sure to add a test for it. The test suite for this project uses [mocha](http://visionmedia.github.io/mocha/) and [should](https://github.com/visionmedia/should.js/)/

To run the test suite, make sure you have installed mocha (`npm install mocha -g`), then you can use the `npm test` or simply `mocha` command to run the tests.

### Code Style

To keep a consistant coding style in the project, we're using [Polar Mobile's guide](https://github.com/polarmobile/coffeescript-style-guide), with one difference begin that much of this project uses `under_scores` rather than `camelCase` for variable naming. For any inline documentation in the code, we're using [JSDoc](http://usejsdoc.org/).

### Commit Cleanliness

It's ok if you start out with a bunch of experimentation and your commit log isn't totally clean, but before any pull requests are accepted, we like to have a nice clean commit log. That means [well-written and clear commit messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) and commits that each do something significant, rather than being typo or bug fixes.

If you submit a pull request that doesn't have a clean commit log, we will ask you to clean it up before we accept. This means being familiar with rebasing - if you are not, [this guide](https://help.github.com/articles/interactive-rebase) by github should help you to get started. And if you are still confused, feel free to ask!
9 changes: 9 additions & 0 deletions lib/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RootsUtil = require 'roots-util'
path = require 'path'

module.exports = (opts) ->
class RootsNetlify
constructor: (@roots) ->
@util = new RootsUtil(@roots)

setup: ->
10 changes: 10 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
License (MIT)
-------------

Copyright (c) 2014 Josh Rowley, Carrot Creative

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.
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "roots-netlify",
"version": "0.0.0",
"description": "A roots extension for configuring netlify",
"main": "lib",
"directories": {
"test": "test"
},
"dependencies": {
"roots-util": "0.0.4"
},
"devDependencies": {
"coffee-script": "1.7.x",
"mocha": "*",
"should": "*",
"roots": "3.x",
"coveralls": "2.x",
"istanbul": "0.3.x"
},
"peerDependencies": {
"roots": "3.x"
},
"scripts": {
"test": "mocha",
"coverage": "make build; NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha; make unbuild; open coverage/lcov-report/index.html;",
"coveralls": "make build; make coveralls; make unbuild;"
},
"repository": {
"type": "git",
"url": "https://github.com/carrot/roots-netlify.git"
},
"keywords": [
"roots-extension"
],
"author": "Josh Rowley",
"license": "MIT",
"bugs": {
"url": "https://github.com/carrot/roots-netlify/issues"
},
"homepage": "https://github.com/carrot/roots-netlify"
}
56 changes: 56 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Roots Netlify
=============================

[![npm](https://badge.fury.io/js/roots-netlify.png)](http://badge.fury.io/js/roots-netlify) [![tests](https://travis-ci.org/carrot/roots-netlify.png?branch=master)](https://travis-ci.org/carrot/roots-netlify) [![dependencies](https://david-dm.org/carrot/roots-netlify.png?theme=shields.io)](https://david-dm.org/carrot/roots-netlify)

A roots extension for creating Netlify configuration files.

> **Note:** This project is in early development, and versioning is a little different. [Read this](http://markup.im/#q4_cRZ1Q) for more details.
### Why Should You Care?

[Netlify](https://www.netlify.com/) is a great static hosting platform that allows developers to add powerful features to their static sites, like [redirects & rewrites](https://docs.netlify.com/) and [headers & basic auth](https://docs.netlify.com/headers_and_basic_auth/).

This abstracts Netlify's config files into your `app.coffee` with the rest of your configs so they can be one big happy family. This also allows you to create different Netlify configs based on your [roots environment](http://roots.readthedocs.org/en/latest/environments.html).

It's also common roots convention to start files with an `_` to ignore files when compiling. Since Netlify is configured with a `_headers` and `_redirects` file, using this extension allows you keep that nice clean convention throughout the whole project.

### Installation & Usage

- make sure you are in your roots project directory
- `npm install roots-netlify --save`
- modify your `app.coffee` file to include the extension, as such

```coffee
netlify = require 'roots-netlify'

module.exports =
extensions: [
netlify
redirects:
'/news': '/blog'
'/news/:year/:month:/:date/:slug': '/blog/:year/:month/:date/:story_id'
'/news/*': '/blog/:splat'
'302':
'/temp_redirect': '/'
'404':
'ecommerce'
rewrites:
'/*': '/index.html'
headers:
'/protected/path':
'Cache-Control': 'max-age: 3000'
'Basic-Auth': 'username:password'
]
```

Read the Netlify documentation on [redirects](https://docs.netlify.com/redirects/) and [headers](https://docs.netlify.com/headers_and_basic_auth) to learn more.

Redirects added to the `redirects` object return a status code of `301` while those added to the `rewrites` object will return `200` (a rewrite). Netlify also [supports](https://docs.netlify.com/redirects#http-status-codes) two other status codes: `302` and `404`. In order to configure your redirects for these, add a `302` or `404` key to `redirects` and nest your configuration object there (see example above).

> **Note:** `302` and `404` redirects are currently not supported in this extension. Use the `redirects` (`301`) or `rewrites` (`200`) configuration keys instead.
### License & Contributing

- Details on the license [can be found here](LICENSE.md)
- Details on running tests and contributing [can be found here](contributing.md)
7 changes: 7 additions & 0 deletions test/fixtures/basic/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
roots_netlify = require '../../..'

module.exports =
ignores: ["**/_*", "**/.DS_Store"]
extensions: [
roots_netlify
]
1 change: 1 addition & 0 deletions test/fixtures/basic/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p hello world
6 changes: 6 additions & 0 deletions test/fixtures/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "test",
"dependencies": {
"jade": "*"
}
}
3 changes: 3 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--reporter spec
--compilers coffee:coffee-script/register
--timeout 30000
29 changes: 29 additions & 0 deletions test/test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
path = require 'path'
fs = require 'fs'
should = require 'should'
Roots = require 'roots'
_path = path.join(__dirname, 'fixtures')
RootsUtil = require 'roots-util'
h = new RootsUtil.Helpers(base: _path)

# setup, teardown, and utils

compile_fixture = (fixture_name, done) ->
@public = path.join(fixture_name, 'public')
h.project.compile(Roots, fixture_name, done)

before (done) ->
h.project.install_dependencies('*', done)

after ->
h.project.remove_folders('**/public')

# tests

describe 'development', ->

before (done) -> compile_fixture.call(@, 'basic', -> done())

it 'compiles basic project', ->
p = path.join(@public, 'index.html')
h.file.exists(p).should.be.ok

0 comments on commit 50117a1

Please sign in to comment.