-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
229 lines (197 loc) · 6.65 KB
/
gulpfile.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
'use strict';
/**
* Module dependencies.
*/
var _ = require('lodash'),
defaultAssets = require('./config/assets/default'),
testAssets = require('./config/assets/test'),
gulp = require('gulp'),
gulpLoadPlugins = require('gulp-load-plugins'),
runSequence = require('run-sequence'),
plugins = gulpLoadPlugins();
var minimist = require('minimist');
var args = minimist(process.argv.slice(2), {
string: 'testFiles'
});
// Set NODE_ENV to 'test'
gulp.task('env:test', function() {
process.env.NODE_ENV = 'test';
});
// Set NODE_ENV to 'development'
gulp.task('env:dev', function() {
process.env.NODE_ENV = 'development';
});
// Set NODE_ENV to 'production'
gulp.task('env:prod', function() {
process.env.NODE_ENV = 'production';
});
// Nodemon task
gulp.task('nodemon', function() {
return plugins.nodemon({
script: 'server.js',
nodeArgs: ['--debug'],
ext: 'js,html',
watch: _.union(defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
});
});
// Watch Files For Changes
gulp.task('watch', function() {
// Start livereload
plugins.livereload.listen();
// Add watch rules
gulp.watch(defaultAssets.server.views).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.server.allJS, ['jshint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.views).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.js, ['jshint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.css, ['csslint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.sass, ['sass', 'csslint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.less, ['less', 'csslint']).on('change', plugins.livereload.changed);
});
// CSS linting task
gulp.task('csslint', function(done) {
return gulp.src(defaultAssets.client.css)
.pipe(plugins.csslint('.csslintrc'))
.pipe(plugins.csslint.reporter())
.pipe(plugins.csslint.reporter(function(file) {
if (!file.csslint.errorCount) {
done();
}
}));
});
// JS linting task
gulp.task('jshint', function() {
return gulp.src(_.union(defaultAssets.server.allJS, defaultAssets.client.js, testAssets.tests.server, testAssets.tests.client, testAssets.tests.e2e))
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('default'))
.pipe(plugins.jshint.reporter('fail'));
});
// JS minifying task
gulp.task('uglify', function() {
return gulp.src(defaultAssets.client.js)
.pipe(plugins.ngAnnotate())
.pipe(plugins.uglify({
mangle: false
}))
.pipe(plugins.concat('application.min.js'))
.pipe(gulp.dest('public/dist'));
});
// CSS minifying task
gulp.task('cssmin', function() {
return gulp.src(defaultAssets.client.css)
.pipe(plugins.cssmin())
.pipe(plugins.concat('application.min.css'))
.pipe(gulp.dest('public/dist'));
});
// Sass task
gulp.task('sass', function() {
return gulp.src(defaultAssets.client.sass)
.pipe(plugins.sass())
.pipe(plugins.rename(function(path) {
path.dirname = path.dirname.replace('/scss', '/css');
}))
.pipe(gulp.dest('./modules/'));
});
// Less task
gulp.task('less', function() {
return gulp.src(defaultAssets.client.less)
.pipe(plugins.less())
.pipe(plugins.rename(function(path) {
path.dirname = path.dirname.replace('/less', '/css');
}))
.pipe(gulp.dest('./modules/'));
});
// Connect to MongoDB using the mongoose module
gulp.task('mongoose', function(done) {
var mongoose = require('./config/lib/mongoose.js');
mongoose.connect(function(db) {
done();
});
});
// Mocha tests task
gulp.task('mocha', ['env:test', 'mongoose'], function() {
var testFiles;
if (args.testFiles) testFiles = args.testFiles;
else testFiles = testAssets.tests.server;
return gulp.src(testFiles)
.pipe(plugins.mocha({
reporter: 'spec'
})).once('end', function() {
process.exit();
});
});
// Karma test runner task
gulp.task('karma', ['env:test'], function(done) {
return gulp.src([])
.pipe(plugins.karma({
configFile: 'karma.conf.js',
action: 'run',
singleRun: true
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
throw err;
});
});
// Selenium standalone WebDriver update task
gulp.task('webdriver-update', plugins.protractor.webdriver_update);
// Protractor test runner task
gulp.task('protractor', function() {
gulp.src([])
.pipe(plugins.protractor.protractor({
configFile: "protractor.conf.js"
}))
.on('error', function(e) {
throw e
})
});
// Lint CSS and JavaScript files.
gulp.task('lint', function(done) {
runSequence('less', 'sass', ['csslint', 'jshint'], done);
});
// Lint project files and minify them into two production files.
gulp.task('build', function(done) {
runSequence('env:dev', 'lint', ['uglify', 'cssmin'], done);
});
// Run the project tests
gulp.task('test', function(done) {
runSequence('karma', 'mocha', done);
});
// Run the project in development mode
gulp.task('default', function(done) {
runSequence('env:dev', 'lint', ['nodemon', 'watch'], done);
});
// Run the project in debug mode
gulp.task('debug', function(done) {
runSequence('env:dev', 'lint', ['nodemon', 'watch'], done);
});
// Run the project in production mode
gulp.task('prod', function(done) {
runSequence('build', 'lint', ['nodemon', 'watch'], done);
});
gulp.task('bulk-upload', ['env:prod', 'mongoose'], function(done){
var uploader = require('./modules/shortcuts/server/bulk.upload/uploader.js');
uploader.uploadShortcuts(defaultAssets.server.shortcutsDir, done);
});
// Run the project in production mode
gulp.task('migrate-favorites', ['mongoose'], function(done) {
var mongoose = require('mongoose');
var Shortcut = mongoose.model('Shortcut');
var User = mongoose.model('User');
User.find({
favorites: {
$not: {
$size: 0
}
}
}).populate("favorites").exec(function(err, users) {
users.forEach(function(user) {
user.favorites.forEach(function(shortcut) {
console.log("Incrementing favorite count for shortcut: " + shortcut._id);
shortcut["favoritesCount"] += 1;
shortcut.save()
})
})
}).then(function() {
process.exit()
});
});