-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
171 lines (132 loc) · 3.47 KB
/
gulpfile.js
File metadata and controls
171 lines (132 loc) · 3.47 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
var
del = require('del'),
gulp = require('gulp'),
istanbul = require('gulp-istanbul'),
jshint = require('gulp-jshint'),
mocha = require('gulp-mocha'),
sequence = require('run-sequence'),
spawn = require('child_process').spawn,
/* IMPORTANT NOTE: This matches a setting in ./init/mongodb.conf */
MONGO_DB_DIRECTORY = '/usr/local/var/mongodb/hashtagsell';
function ensureDirectory (path, callback) {
// Note: using child_process.spawn instead of fs.mkdir so I can
// leverage the -p parameter
var
err,
message = '',
mkdir = spawn('mkdir', ['-p', path]);
mkdir.stdout.on('data', function (data) {
message += data;
});
mkdir.stderr.on('data', function (data) {
message += data;
});
mkdir.on('close', function (code) {
if (code !== 0) {
err = new Error(
'Error occurred attempting to create directory at ' +
path);
err.exitCode = code;
err.message = message;
return callback(err);
}
return callback(null, message);
});
}
gulp.task('clean', function (callback) {
return del(['coverage'], callback);
});
gulp.task('jshint', function () {
return gulp
.src(['lib/**/*.js', 'test/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('ensure-data-directory', function (callback) {
ensureDirectory(MONGO_DB_DIRECTORY, callback);
});
gulp.task('mongo-start', ['ensure-data-directory'], function (callback) {
var
err,
message = '',
mongod = spawn('mongod', ['--config', './init/mongodb.conf']);
mongod.stdout.on('data', function (data) {
message += data;
});
mongod.stderr.on('data', function (data) {
message += data;
});
mongod.on('close', function (code) {
if (code === 100) {
console.log('An instance of Mongo may already be running...');
console.log(message);
return callback(null, message);
}
if (code !== 0) {
err = new Error('Error occurred attempting to start Mongo');
err.exitCode = code;
err.message = message;
return callback(err);
}
return callback(null, message);
});
});
gulp.task('mongo-stop', function (callback) {
var
err = '',
message = '',
mongo = spawn('mongo', [
'--eval',
'db.getSiblingDB("admin").shutdownServer()']);
mongo.stdout.on('data', function (data) {
message += data;
});
mongo.stderr.on('data', function (data) {
message += data;
});
mongo.on('close', function (code) {
if (code !== 0) {
err = new Error('Error occurred attempting to stop Mongo');
err.exitCode = code;
err.message = message;
return callback(err);
}
return callback(null, message);
});
});
gulp.task('test-all', function (callback) {
sequence('clean', 'jshint', 'test-coverage', callback);
});
gulp.task('test-coverage', ['clean'], function () {
return gulp
.src(['./lib/**/*.js'])
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
gulp
.src(['./test/lib/**/*.js'])
.pipe(mocha({
reporter : 'spec'
}))
.pipe(istanbul.writeReports('./reports'));
});
});
gulp.task('test-functional', function () {
return gulp
.src(['./test/functional/**/*.js'], { read : false })
.pipe(mocha({
checkLeaks : true,
reporter : 'spec',
ui : 'bdd'
}));
});
gulp.task('test-unit', function () {
return gulp
.src(['./test/lib/**/*.js'], { read : false })
.pipe(mocha({
checkLeaks : true,
reporter : 'spec',
ui : 'bdd'
}));
});