-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
155 lines (144 loc) · 4.35 KB
/
Gruntfile.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
module.exports = function(grunt) {
var Q = require('q')
// requirejs boilerplate
var requirejs = require('requirejs');
requirejs.config({
baseUrl: './server',
nodeRequire: require
});
// end requirejs boilerplate
grunt.initConfig({
test: {
config: grunt.file.readJSON('./config-test.json')
},
dev: {
config: grunt.file.readJSON('./config-dev.json')
},
createDev: {
config: grunt.file.readJSON('./config-dev.json')
},
importDeck: {
config: grunt.file.readJSON('./config-dev.json')
},
jshint: {
options: {
asi: true,
laxcomma: true,
laxbreak: true
},
all: ['Gruntfile.js', 'www/**/*.js', 'server/**/*.js']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
function asyncTask(done, promise) {
promise.then(done).fail(
function(e) {
done(e)
}
).done()
}
grunt.task.registerTask('createDev', 'Create the dev database', function() {
var done = this.async();
requirejs
([
'createDB',
'createTables'
], function (createDB, createTables) {
var conf = grunt.config('createDev.config')
,dbConf = conf.db
asyncTask(done,
createDB(dbConf).then(
function () {
return createTables(dbConf)
}
))
})
})
grunt.task.registerTask('importDeck', 'import a deck into a database', function() {
var done = this.async()
requirejs
([
'createPool',
'import'
],
function (createPool,
importDeck) {
var conf = grunt.config('importDeck.config')
,dbConf = conf.db
asyncTask(done, importDeck(dbConf, grunt.option('from') || 'reformation'))
}
)
})
grunt.task.registerTask('dev', 'start the dev server', function() {
var done = this.async();
requirejs
([
'start',
'open'
],
function (startServer,
open) {
var conf = grunt.config('dev.config')
startServer(conf).then(
function() {
console.log('opening')
open('http://'+conf.server.host+':'+conf.server.port+'/sheets/all')
}).done()
})
})
// Set up test data and run the test suite. You can pass the
// option --no-run if you don't want this to actually open a
// browser window to run the tests. This enables a debugging
// technique: Fist you set a breakpoint in your browser, then run
// grunt test to initialize data, then reload your test page
// yourself, which pauses in the debugger.
grunt.task.registerTask('test', 'Run the test suite', function() {
var done = this.async();
requirejs
([
'createDB',
'createTables',
'test/createData',
'test/runTests',
'step',
'start'
],
function (createDB,
createTables,
createData,
runTests,
step,
startServer) {
var conf = grunt.config('test.config')
,dbConf = conf.db
,serverConf = conf.server
,pool = null
if (conf.server.port === grunt.config('dev.config').server.port)
grunt.fail.fatal("Test and dev configs should be different.")
step(
function() {
createDB(dbConf, this)
},
function(err) {
if (err) throw err
createTables(dbConf, this)
},
function(err, pool_) {
if (err) throw err
pool = pool_
createData(pool, this)
},
function(err) {
if (err) throw err
startServer(pool, serverConf, this)
},
function(err) {
if (err) throw err
if(!grunt.option('no-run')) {
runTests(serverConf, done)
}
}
)
})
})
}