Permalink
Browse files

init

  • Loading branch information...
0 parents commit 7dc67d86527d77caf24bda84901650a1f4a62580 @funkytek funkytek committed May 28, 2013
Showing with 248 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +6 −0 .npmignore
  3. +7 −0 .travis.yml
  4. +20 −0 LICENSE
  5. +36 −0 Makefile
  6. +48 −0 README.md
  7. +2 −0 index.js
  8. +43 −0 lib/main.coffee
  9. +31 −0 package.json
  10. +6 −0 test/config.coffee
  11. +43 −0 test/main.coffee
@@ -0,0 +1,6 @@
+.DS_Store
+*.log
+node_modules
+build
+*.node
+components
@@ -0,0 +1,6 @@
+.DS_Store
+*.log
+node_modules
+build
+*.node
+components
@@ -0,0 +1,7 @@
+language: node_js
+node_js:
+ - 0.6
+ - 0.7
+ - 0.8
+ - 0.9
+ - 0.10
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2013 Fractal <contact@wearefractal.com>
+
+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.
@@ -0,0 +1,36 @@
+build: components lib
+ @rm -rf dist
+ @mkdir dist
+ @node_modules/.bin/coffee -b -o dist -c lib/*.coffee
+ @node_modules/.bin/component build --standalone APPNAME
+ @mv build/build.js APPNAME.js
+ @rm -rf build
+ @node_modules/.bin/uglifyjs -nc --unsafe -mt -o APPNAME.min.js APPNAME.js
+ @echo "File size (minified): " && cat APPNAME.min.js | wc -c
+ @echo "File size (gzipped): " && cat APPNAME.min.js | gzip -9f | wc -c
+ @cp ./APPNAME.js ./examples/
+
+test: build lib
+ @node_modules/.bin/mocha --compilers coffee:coffee-script
+
+components: component.json
+ @node_modules/.bin/component install --dev
+
+docs: lib
+ @node_modules/.bin/lidoc README.md manual/*.md lib/*.coffee --output docs --github wearefractal/APPNAME
+
+docs.deploy: docs
+ @cd docs && \
+ git init . && \
+ git add . && \
+ git commit -m "Update documentation"; \
+ git push "https://github.com/wearefractal/APPNAME" master:gh-pages --force && \
+ rm -rf .git
+
+clean:
+ @rm -rf dist
+ @rm -rf components
+ @rm -rf build
+ @rm -rf docs
+
+.PHONY: test docs docs.deploy
@@ -0,0 +1,48 @@
+![status](https://secure.travis-ci.org/wearefractal/APPNAME.png?branch=master)
+
+## Information
+
+<table>
+<tr>
+<td>Package</td><td>APPNAME</td>
+</tr>
+<tr>
+<td>Description</td>
+<td>DESCRIPTIONHERE</td>
+</tr>
+<tr>
+<td>Node Version</td>
+<td>>= 0.4</td>
+</tr>
+</table>
+
+## Usage
+
+```coffee-script
+NOTHING HERE YET
+```
+
+## LICENSE
+
+(MIT License)
+
+Copyright (c) 2013 Fractal <contact@wearefractal.com>
+
+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.
@@ -0,0 +1,2 @@
+require('coffee-script');
+module.exports = require('./lib/main');
@@ -0,0 +1,43 @@
+async = require 'async'
+{Schema} = require 'mongoose'
+
+module.exports =
+
+ class Seedling
+ constructor: (@models) -> @collection = {}
+
+ clear: (cb) ->
+ async.parallel (m.remove.bind m for _, m of db.models), cb
+
+ create: (cb) ->
+
+ console.log "inserting seed data..."
+
+ async.eachSeries Object.keys(@models), (name, done) =>
+ type = db.model name
+ data = @models[name]
+ @collection[name] = []
+ data = data() if data instanceof Function
+ async.each data, (model, next) =>
+ type.create model, (err, res) =>
+ if err? then console.log "err: #{err}"
+ @collection[name].push res
+ next()
+ , (err) ->
+ console.log err if err?
+ done()
+
+ , (err) ->
+ console.log err if err?
+ console.log "complete."
+ cb()
+
+ rand: (model) -> @collection[model][Math.floor(Math.random()*@collection[model].length)]
+
+ ref: (model) ->
+ # just ObjectId
+ return @rand(model)._id
+
+ embed: (model) ->
+ # randomize
+ return @rand(model)
@@ -0,0 +1,31 @@
+{
+ "name":"seedling",
+ "description":"seed data utility for mongoose",
+ "version":"0.0.1",
+ "homepage":"http://github.com/wearefractal/seedling",
+ "repository":"git://github.com/wearefractal/seedling.git",
+ "author":"Fractal <contact@wearefractal.com> (http://wearefractal.com/)",
+ "main":"./index.js",
+
+ "dependencies":{
+ "coffee-script":"*",
+ "async":"*",
+ "mongoose":"*"
+ },
+ "devDependencies":{
+ "mocha":"*",
+ "should":"*"
+ },
+ "scripts":{
+ "test":"mocha --compilers coffee:coffee-script"
+ },
+ "engines":{
+ "node":">= 0.4.0"
+ },
+ "licenses":[
+ {
+ "type":"MIT",
+ "url":"http://github.com/wearefractal/seedling/raw/master/LICENSE"
+ }
+ ]
+}
@@ -0,0 +1,6 @@
+module.exports =
+ appName: "seedling"
+ port: process.env.PORT or 8080
+ database: process.env.MONGODB or "mongodb://localhost/#{@appName}"
+ paths:
+ models: './models'
@@ -0,0 +1,43 @@
+seedling = require '../'
+should = require 'should'
+config = require './config'
+db = require('goosestrap') config
+
+module.exports =
+
+ "given some seed data": ->
+
+ seed = new seedling
+
+ User: [
+ username: 'admin'
+ id: '1'
+ token: '1'
+ password: 'secret'
+ ]
+
+ Location: [
+ name: "Scottsdale Fashion Square"
+ coords:
+ lat: 33.5038
+ lon: 111.9296
+ ]
+
+ Movie: -> [
+ name: "Star Trek Into Darkness"
+ date: "5/15/13"
+ imgUrl: "http://api.ning.com/files/K6cyghYfeIs47byqVTOkvuRkLd7EEz3FJZvL*6v*9uC3PsnxvdyZfyvxRKJbuHh4vNdtMcyCH6-V0VfdQtH9llTNpc2GR*qv/startrek_v1.jpg?size=173&crop=1:1"
+ location: seed.ref 'Location'
+ ,
+ name: "The Iceman"
+ date: "5/15/13"
+ imgUrl: "http://api.ning.com/files/ysdCY8Oh2FFFqeGsBQ6Qpeb6eJZ6ytFvsVN2r0QDqPaPnwC9Lu4NQSl6Mcch4lABkVqYrX-jUoZa8xK2ccGDnXbwANQcPvf-/iceman.jpg?size=173&crop=1:1"
+ location: seed.ref 'Location'
+ ]
+
+ "when seed.create is called": ->
+
+ seed.clear ->
+ seed.create (err) ->
+ console.log err if err?
+ err.should.not.exist()

0 comments on commit 7dc67d8

Please sign in to comment.