Skip to content
Browse files

update new coffee template

  • Loading branch information...
1 parent e540f10 commit 62d97e60c968c0bd89fd9513a48fb00a8e6750c5 @twilson63 committed
Showing with 167 additions and 46 deletions.
  1. +1 −0 .gitignore
  2. +46 −23 Cakefile
  3. +24 −0 app/index.js
  4. +12 −0 assets/css/app.styl
  5. +1 −1 assets/js/app.coffee
  6. +12 −9 package.json
  7. +7 −6 readme.md
  8. +0 −1 server.js
  9. +7 −3 app.coffee → src/index.coffee
  10. +16 −0 test/app_test.coffee
  11. +41 −3 views/index.jade
View
1 .gitignore
@@ -1 +1,2 @@
node_modules
+.DS_Store
View
69 Cakefile
@@ -1,5 +1,5 @@
fs = require 'fs'
-{print} = require 'sys'
+{print} = require 'util'
{spawn, exec} = require 'child_process'
# ANSI Terminal Colors
@@ -8,45 +8,68 @@ red = '\x1B[0;31m'
green = '\x1B[0;32m'
reset = '\x1B[0m'
-package = JSON.parse fs.readFileSync('./package.json')
-testCmd = package.scripts.test
-startCmd = package.scripts.start
+pkg = JSON.parse fs.readFileSync('./package.json')
+testCmd = pkg.scripts.test
+startCmd = pkg.scripts.start
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
-build = (watch, callback) ->
- if typeof watch is 'function'
- callback = watch
- watch = false
- options = ['-c', '-o', 'lib', 'src']
- options.unshift '-w' if watch
-
+# Compiles app.coffee and src directory to the app directory
+build = (callback) ->
+ options = ['-c','-b', '-o', 'app', 'src']
coffee = spawn 'coffee', options
- coffee.stdout.on 'data', (data) -> print data.toString()
- coffee.stderr.on 'data', (data) -> log data.toString(), red
+ coffee.stdout.pipe process.stdout
+ coffee.stderr.pipe process.stderr
coffee.on 'exit', (status) -> callback?() if status is 0
-spec = (callback) ->
- options = ['spec', '--coffee']
- spec = spawn 'jasmine-node', options
- spec.stdout.on 'data', (data) -> print data.toString()
- spec.stderr.on 'data', (data) -> log data.toString(), red
+# mocha test
+test = (callback) ->
+ options = [
+ '--compilers'
+ 'coffee:coffee-script'
+ '--colors'
+ '--require'
+ 'should'
+ '--require'
+ './server'
+ ]
+ spec = spawn 'mocha', options
+ spec.stdout.pipe process.stdout
+ spec.stderr.pipe process.stderr
spec.on 'exit', (status) -> callback?() if status is 0
-
task 'docs', 'Generate annotated source code with Docco', ->
fs.readdir 'src', (err, contents) ->
files = ("src/#{file}" for file in contents when /\.coffee$/.test file)
docco = spawn 'docco', files
- docco.stdout.on 'data', (data) -> print data.toString()
- docco.stderr.on 'data', (data) -> log data.toString(), red
+ docco.pipe process.stdout
+ docco.stdout.pipe process.stdout
+ docco.stderr.pipe process.stderr
docco.on 'exit', (status) -> callback?() if status is 0
task 'build', ->
build -> log ":)", green
-task 'spec', 'Run Jasmine-Node', ->
- build -> spec -> log ":)", green
+task 'spec', 'Run Mocha tests', ->
+ build -> test -> log ":)", green
+
+task 'test', 'Run Mocha tests', ->
+ build -> test -> log ":)", green
+
+task 'dev', 'start dev env', ->
+ # watch_coffee
+ options = ['-c', '-b', '-w', '-o', 'app', 'src']
+ coffee = spawn './node_modules/coffee-script/bin/coffee', options
+ coffee.stdout.pipe process.stdout
+ coffee.stderr.pipe process.stderr
+ log 'Watching coffee files', green
+ # watch_js
+ supervisor = spawn 'node', ['./node_modules/supervisor/lib/cli-wrapper.js','-w','app,views', '-e', 'js|jade', 'server']
+ supervisor.stdout.pipe process.stdout
+ supervisor.stderr.pipe process.stderr
+ log 'Watching js files and running server', green
+
+
View
24 app/index.js
@@ -0,0 +1,24 @@
+// Generated by CoffeeScript 1.3.3
+var app, assets, express, port, stylus;
+
+express = require('express');
+
+stylus = require('stylus');
+
+assets = require('connect-assets');
+
+app = express();
+
+app.use(assets());
+
+app.set('view engine', 'jade');
+
+app.get('/', function(req, resp) {
+ return resp.render('index');
+});
+
+port = process.env.PORT || process.env.VMC_APP_PORT || 3000;
+
+app.listen(port, function() {
+ return console.log("Listening on " + port + "\nPress CTRL-C to stop server.");
+});
View
12 assets/css/app.styl
@@ -7,3 +7,15 @@ h2
smooth-button()
width: 90%
font-size: 2em
+
+h3
+ margin-top: 20px
+pre
+ font-family: courier
+ background-color: rgba(0,0,0,.8)
+ color: yellow
+ width: 100%
+ margin-bottom: 20px
+ padding: 10px
+ border: 1px solid black
+
View
2 assets/js/app.coffee
@@ -1,3 +1,3 @@
$ ->
- x = -> $('<h2>Express Coffee Template 1.3</h2>').prependTo('.right')
+ x = -> $('<h2>Express Coffee Template 1.4</h2>').prependTo('.right')
setTimeout x, 500
View
21 package.json
@@ -1,19 +1,22 @@
{
"name": "express-coffee"
- , "version": "1.3.0"
+ , "version": "1.3.1"
, "private": true
, "dependencies": {
- "coffee-script": "1.3.3"
- , "express": "3.0.0alpha4"
+ "express": "3.0.0alpha4"
, "jade": "0.26.0"
, "connect-assets": "2.2.1"
, "stylus": "0.27.0"
, "nib": "0.4.1"
, "markdown": "0.3.1"
- }
- , "scripts": {
- "start": "node server.js"
- }
- , "devDependencies": {}
- , "engine": "node ~> 0.6.17"
+ }, "scripts": {
+ "start": "node server.js",
+ "test": "mocha --require should --compilers coffee:coffee-script --colors"
+ }, "devDependencies": {
+ "coffee-script": "*"
+ , "mocha": "*"
+ , "should": "*"
+ , "request": "*"
+ , "supervisor": "*"
+ }, "engine": "node ~> 0.6.17"
}
View
13 readme.md
@@ -1,4 +1,4 @@
-# Express Coffee Template 3 (1.3)
+# Express Coffee Template 4 (1.4)
This is a Node Express CoffeeScript Stack Template
@@ -21,7 +21,8 @@ This is a template that can be used to create nodejs applications using
* [CoffeeScript](http://coffeescript.org)
* [Jade](http://jade-lang.org/)
* [connect-assets](http://github.com/TrevorBurnham/connect-assets)
-* [Jasmine-Node](https://github.com/mhevery/jasmine-node/)
+* [Mocha](http://visionmedia.github.com/mocha/)
+* [Should.Js](https://github.com/visionmedia/should.js/)
These will install with npm, just do
@@ -53,7 +54,7 @@ node server.js
* [Jeremy Ashkenas](https://github.com/jashkenas) for creating coffee-script
* [TJ Holowaychuk](https://github.com/visionmedia) for creating express
* [Miško Hevery](https://github.com/mhevery) for creating Jasmine-Node
-* [Pivotal Labs](http://github.com/pivotal/jasmine) for creating Jasmine
+* [TJ Holowaychuk](https://github.com/visionmedia) for creating mocha and should.js
## About
@@ -61,9 +62,9 @@ express-coffee is a template or boiler-plate to get started writting
express web applications in CoffeeScript. It comes ready to go with base
setup for an Express Web App. It includes a Cakefile that lets you build,
spec, and watch your coffeescript as you develop. You hack in the src folder
-and run cake build to build you server files, write your jasmine tests in
-your spec folder and run cake spec to run your test suite. Create your
-coffeekup views in the views folder and put your public assets in the public
+and run cake build to build you server files, write your mocha in
+your test folder and run cake test or spec to run your test suite. Create your
+jade views in the views folder and put your public assets in the public
folder. Enjoy your express-coffee
View
1 server.js
@@ -1,2 +1 @@
-require('coffee-script');
require('./app');
View
10 app.coffee → src/index.coffee
@@ -3,10 +3,14 @@ stylus = require 'stylus'
assets = require 'connect-assets'
app = express()
+# Add Connect Assets
app.use assets()
+# Set View Engine
app.set 'view engine', 'jade'
-
-app.get '/', (req, resp) -> resp.render 'index'
-
+# Get root_path return index view
+app.get '/', (req, resp) ->
+ resp.render 'index'
+# Define Port
port = process.env.PORT or process.env.VMC_APP_PORT or 3000
+# Start Server
app.listen port, -> console.log "Listening on #{port}\nPress CTRL-C to stop server."
View
16 test/app_test.coffee
@@ -0,0 +1,16 @@
+request = require 'request'
+describe 'Sample test', ->
+ it 'should be true', ->
+ true.should.equal true
+
+describe 'GET /', ->
+ response = null
+ before (done) ->
+ request 'http://localhost:3000', (e, r, b) ->
+ response = r
+ done()
+
+ it 'should return 200', (done) ->
+ response.statusCode.should.equal 200
+ done()
+
View
44 views/index.jade
@@ -25,9 +25,16 @@ block content
# Features
- ### No more Compile step
+ ### Automated Compile Step
+
+ express-coffee template is made to quickly start putting together an application/prototype.
+
+ Now you can run cake dev and when every coffee file is changed it will rebuild the app.
+
+ Also, it includes supervisor, which will restart you application everytime you change your views or js files.
+
+ cake dev
- express-coffee template is made to quickly start putting together an application/prototype. So we have changed the template back to automatically compile the coffee-script when you run your node app.
### Rails-like Asset Pipeline
@@ -35,7 +42,6 @@ block content
!= css('mycss')
#= Pull from /assets/css/mycss.styl
-
!= js('app')
#= Pull from /assets/js/app.coffee or app.js
@@ -45,6 +51,38 @@ block content
express-coffee template as switched to jade as the default template language. It seems to be the clear winner and the most mature at this point. The rich featureset of integrating markdown and coffeescript and other helpers is big plus for getting things up fast.
+ extends layout
+ block content
+ .container
+ .four.columns
+ :markdown
+ # Hello World
+
### Skeleton CSS as the default responsive grid
skeleton is clean and basic and can easily be adjusted.
+
+ ### Mocha and Request for testing
+
+ mocha is an extremely powerful and easy to use testing framework
+
+ see [http://visionmedia.github.com/mocha/](http://visionmedia.github.com/mocha/)
+
+ describe 'Sample test', ->
+ it 'should be true', ->
+ true.should.equal true
+
+ to run mocha
+
+ cake test
+
+ ### Setup to deploy to heroku
+
+ rm -rf .git
+ git init
+ echo 'node_modules' >> '.gitignore'
+ git add .
+ git commit -am "first commit"
+ heroku create
+ git push heroku master
+ heroku open

0 comments on commit 62d97e6

Please sign in to comment.
Something went wrong with that request. Please try again.