Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 7e033e3270f5550c7271820d82c51c89176fdabf 0 parents
@vslinko vslinko authored
Showing with 174 additions and 0 deletions.
  1. +19 −0 LICENSE
  2. +30 −0 README.md
  3. +27 −0 package.json
  4. +98 −0 stack.coffee
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2012-2013 Rithis Studio LLC
+
+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.
30 README.md
@@ -0,0 +1,30 @@
+# Our web stack: express, mongoose, rithis-crud
+
+## Example usage
+
+```coffeescript
+rithis = require 'rithis-stack'
+
+
+rithis.configure __dirname, "example-app", (app, db, callback) ->
+ # schemas
+ DocumentSchema = new rithis.Schema
+ name: type: 'string', required: true
+ date: type: 'date', required: true
+
+ # models
+ Document = db.model 'documents', DocumentSchema
+
+ # routes
+ app.get '/documents', rithis.crud
+ .list(Document)
+ .sort('-date')
+ .make()
+
+ app.post '/documents', rithis.crud
+ .post(Document)
+ .make()
+
+ # done
+ callback()
+```
27 package.json
@@ -0,0 +1,27 @@
+{
+ "name": "rithis-stack",
+ "version": "0.0.1",
+ "description": "Our web stack: express, mongoose, rithis-crud",
+ "keywords": ["web", "stack", "express", "mongoose", "crud"],
+ "author": {
+ "name": "Vyacheslav Slinko",
+ "email": "vyacheslav.slinko@gmail.com"
+ },
+ "main": "stack",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/rithis/node-rithis-stack"
+ },
+ "dependencies": {
+ "async": "~0.1",
+
+ "express": "~3.1",
+ "mongoose": "~3.4",
+ "rithis-crud": "~0.0",
+
+ "jade-static": "git://github.com/vslinko/jade-static.git#master",
+ "connect-coffee-script": "~0.1",
+ "stylus": "~0.32",
+ "bower": "~0.6"
+ }
+}
98 stack.coffee
@@ -0,0 +1,98 @@
+mongoose = require 'mongoose'
+express = require 'express'
+bower = require 'bower'
+async = require 'async'
+exec = require('child_process').exec
+crud = require 'rithis-crud'
+path = require 'path'
+fs = require 'fs'
+
+coffeescript = require 'connect-coffee-script'
+stylus = require('stylus').middleware
+jade = require 'jade-static'
+
+
+module.exports.configure = (directory, name, configurator) ->
+ # path to public directory
+ publicDirectory = path.join directory, 'public'
+
+ # application
+ app = express()
+
+ app.configure ->
+ app.use express.logger()
+ app.use express.json()
+
+ app.use jade publicDirectory
+ app.use coffeescript publicDirectory
+ app.use stylus publicDirectory
+ app.use express.static publicDirectory
+
+ app.configure 'development', ->
+ app.use express.errorHandler()
+
+ # database connection
+ connectionString = process.env.MONGOHQ_URL or "mongodb://localhost/#{name}"
+ db = mongoose.createConnection connectionString
+
+ # startup
+ componentsSource = path.join directory, 'component.json'
+ componentsDestination = path.join publicDirectory, 'component.json'
+
+ bowerTasks = [
+ # link components config
+ (callback) ->
+ console.log "#{name} linking components.json"
+ fs.symlink componentsSource, componentsDestination, ->
+ callback()
+
+ # install components
+ (callback) ->
+ previousDirectory = process.cwd()
+ process.chdir publicDirectory
+
+ installProcess = bower.commands.install()
+
+ installProcess.on 'data', (data) ->
+ console.log data
+
+ installProcess.on 'end', ->
+ process.chdir previousDirectory
+ callback()
+
+ # unlink components config
+ (callback) ->
+ console.log "#{name} unlinking components.json"
+ fs.unlink componentsDestination, callback
+ ]
+
+ setupTasks = [
+ # setup application
+ (callback) ->
+ console.log "#{name} configuring application"
+ configurator app, db, callback
+
+ # install components via bower
+ (callback) ->
+ console.log "#{name} installing components"
+ async.series bowerTasks, callback
+ ]
+
+ async.series [
+ # prepare application
+ (callback) ->
+ console.log "#{name} preparing application"
+ async.parallel setupTasks, callback
+
+ # serve application
+ (callback) ->
+ port = process.env.PORT or 3000
+
+ app.listen port, ->
+ console.log "#{name} listening port #{port}"
+ callback()
+ ]
+
+
+module.exports.Schema = mongoose.Schema
+module.exports.crud = crud
Please sign in to comment.
Something went wrong with that request. Please try again.