forked from gijs/dashku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
73 lines (66 loc) · 2.58 KB
/
Cakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Cakefile
# If you move to a new Redis DB, you may want to run this function
# to regenerate the API Key database
regenerateApiKeyDb = (cb) ->
ss = require 'socketstream'
internals = require './internals'
User = ss.api.app.models.User
Redis = ss.api.app.Redis
User.find {}, (err, docs) ->
if !err
if docs.length > 0
for doc in docs
Redis.hset "apiKeys", doc.apiKey, doc._id, Redis.print
if docs.indexOf doc is docs.length-1
cb 0
else
console.log "There are no users in the database, no need to regenerate the API key database"
cb 0
# This populates the WidgetTemplates collection with Widget Templates
populateWidgetTemplates = (cb) ->
fs = require 'fs'
ss = require 'socketstream'
internals = require './internals'
WidgetTemplate = ss.api.app.models.WidgetTemplate
console.log "Clearing the WidgetTemplates collection"
WidgetTemplate.remove {}, (err) ->
if err is null
fs.readdir "#{__dirname}/server/seed/widgetTemplates/", (err, files) ->
if !err and files
count = 0
for file in files
widgetTemplate = new WidgetTemplate require "#{__dirname}/server/seed/widgetTemplates/#{file}"
widgetTemplate.save (err,doc) ->
count++
if err? then console.log "There was an error populating the WidgetTemplate collection"
if count is files.length-1
console.log "WidgetTemplate collection populated"
cb 0
else
console.log "There was an error clearing the WidgetTemplates collection"
cb 1
# TODO - figure out a way to automate this
files = [
"server/models/user.coffee"
"server/rpc/authentication.coffee"
"server/rpc/dashboard.coffee"
"server/rpc/general.coffee"
"server/rpc/widget.coffee"
"server/rpc/widgetTemplate.coffee"
]
test = (cb) ->
mocha = require 'mocha'
process.env["SS_ENV"] = "test"
ss = require 'socketstream'
internals = require './internals'
Mocha = new mocha
for file in files
Mocha.addFile "test/#{file.replace('.coffee','_test.coffee')}"
Mocha.run (res) ->
cb res if cb?
task 'test', 'run unit tests for the project', ->
test process.exit
task 'regenerateApiKeyDb', 'Compiles the SocketStream assets, and copies them to a fixed path', ->
regenerateApiKeyDb process.exit
task 'populateWidgetTemplates', "Populates the database with widget templates", ->
populateWidgetTemplates process.exit