-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
152 lines (147 loc) · 4.04 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
var exec = require('child_process').exec;
var monk = require('monk');
var readline = require('readline');
var fs = require('fs');
var http = require('http');
var os = require('os');
module.exports = function(grunt){
function if_mongod_running(running,not_running){
/*
This function exists becaue you cannot register a task that does a task, then does a function.
You must pass an array of tasks or a function to registerTask, not an array of tasks and functions
This could be avoided in future versions of Grunt, when they impliment private tasks.
*/
var temp = function(){
var done = this.async();
exec("ps -A | grep '[m]ongod'",function(error, stdout, stderr){
if(error === null){
//running
if(running === true){
done(true);
} else if(running === false){
done(false);
} else {
running(done);
}
} else {
//not running
if(not_running === true){
done(true);
} else if(not_running === false){
done(false);
} else {
not_running(done);
}
}
});
};
return temp;
}
function mongorestore(done){
exec("mongorestore",function(error, stdout, stderr){
var status = (error === null);
if(!status){
console.log("Error: ");
console.log(error);
}
done(status);
});
}
function start_mongod(done){
exec("mongod --fork --logpath mongo/logs/mongo.log --dbpath mongo/db",function(error, stdout, stderr){
if(error === null){
console.log("Mongod is now running");
done(true);
} else {
done(false);
}
});
}
function stop_mongod(done){
exec("mongo --eval \"db = db.getSiblingDB('admin');db.shutdownServer()\"",function(error, stdout, stderr){
if(error === null){
done(true);
} else {
done(false);
}
});
}
function drop(done){
var adsb = monk("localhost/heart");
adsb.driver.open(function(_,db){
if(db === null){
//sometimes db is null. If it is, wait and try this function again.
setTimeout(function(){
drop(done);
},1000);
} else {
db.dropDatabase(function(ignore,status){
if(status){
console.log("Dropped database");
done(true);
} else {
console.log("Error dropping mongod");
console.log(error);
done(false);
}
});
}
});
}
grunt.initConfig({
run:{
options: {},
main:{
cmd: 'node',
args: ["main.js"]
}
},
sass:{
dist:{
files:{
"css/index.css":"css/index.scss"
}
}
},
babel: {
options:{
sourceMap:true
},
dist: {
files: {
'./js/index.js': './js/index.jsx',
}
}
},
watch: {
jsx:{
files: ['js/index.jsx'],
tasks: ['babel']
},
sass:{
files:['css/index.scss'],
tasks:['sass']
}
},
concurrent: {
options:{
logConcurrentOutput: true
},
watch:{
tasks: ["watch:sass","watch:jsx"]
}
}
});
grunt.loadNpmTasks('grunt-run');
grunt.loadNpmTasks("grunt-babel");
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-sass');
grunt.registerTask('sass-jsx', 'Watch:sass and Watch:jsx',['babel','sass','concurrent']);
grunt.registerTask("mongod_running","Check if mongod is running",if_mongod_running(true,false));
grunt.registerTask("start_mongod","Starts mongod",if_mongod_running(true,start_mongod));
grunt.registerTask("stop_mongod","Stops mongod",if_mongod_running(stop_mongod,true));
//grunt.registerTask("restore","Restores mongodb's data from dump",if_mongod_running(mongorestore,false));
grunt.registerTask("drop","Removes all captured data",if_mongod_running(drop,false));
grunt.registerTask("default", "Runs main.js",["run:main"]);
}