-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
257 lines (215 loc) · 6.78 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
(function () {
'use strict';
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
eslint = require('gulp-eslint'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
jade = require('gulp-jade'),
minifyCss = require('gulp-minify-css'),
sourcemaps = require('gulp-sourcemaps'),
concatCss = require('gulp-concat'),
ngAnnotate = require('gulp-ng-annotate'),
nodemon = require('gulp-nodemon'),
sass = require('gulp-sass'),
path = require('path'),
usemin = require('gulp-usemin'),
del = require('del'),
imagemin = require('gulp-imagemin'),
webdriver_standalone = require("gulp-protractor").webdriver_standalone,
autoprefixer = require('gulp-autoprefixer'),
protractor = require("gulp-protractor").protractor;
/* asset paths */
var paths = {
scripts: ['client/assets/js/side-comments.js', "client/assets/js/marked.js",
'client/assets/lib/ngInfiniteScroll/build/ng-infinite-scroll.js', '!client/lib/**/*', 'client/app/**/*.js'],
css: ['client/assets/scss/*.scss'],
jade: ['client/**/*.jade'],
html: ['client/**/*.html', '!client/assets/lib/**/*.html']
};
/* gulp default task */
gulp.task('default', ['lint', 'test'], function () {
console.log('READDDDY TO RUMMMMBLE');
});
/* main watch task which will compile assets and refresh */
gulp.task('watch', ['jade', 'sass', 'browser-sync'], function () {
gulp.watch(paths.css, ['sass']);
gulp.watch(paths.jade, ['jade']);
});
/* build task, which will properly build entire client */
gulp.task('build', ['scripts', 'css', 'usemin', 'images', 'fonts'], function () {
console.log('app built');
});
/* clean build folder */
gulp.task('clean', function (cb) {
del('./build', cb);
});
/* minify and concat js files */
gulp.task('scripts', function () {
// Minify and copy all JavaScript (except vendor scripts)
// with sourcemaps all the way down
return gulp.src(paths.scripts)
.pipe(ngAnnotate())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(concat('app.min.js'))
.pipe(gulp.dest('./build/assets/js'));
});
// gulp.task('comment-js', function() {
// return gulp.src('client/assets/js/side-comments.js')
// .pipe(uglify())
// .pipe(gulp.dest('./build/assets/js'));
// });
/* css compiliation for production. Also browsersync called */
gulp.task('css', ['sass'], function () {
return gulp.src(paths.css)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(minifyCss())
.pipe(concatCss("styles.min.css"))
.pipe(sourcemaps.write())
.pipe(gulp.dest("./build/assets/css"));
});
/* simply compile sass to css */
gulp.task('sass', function () {
return gulp.src(paths.css)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(minifyCss())
.pipe(concatCss("styles.min.css"))
.pipe(sourcemaps.write())
.pipe(gulp.dest("./client/assets/css"));
});
/* browser sync initialization */
gulp.task('browser-sync', ['nodemon'], function () {
var browserSync = require('browser-sync');
browserSync({
proxy: "localhost:8000", // local node app address
port: 5000, // use *different* port than above
notify: true
});
gulp.watch(["./client/assets/css/*.css", "./client/**/*.html", "./client/index.html"]).on('change', browserSync.reload);
});
/* run nodemon server */
gulp.task('nodemon', function (cb) {
var browserSync = require('browser-sync');
var called = false;
return nodemon({
script: 'server/server.js',
ignore: [
'gulpfile.js',
'node_modules/'
],
ext: 'js',
env: {
'NODE_ENV': 'development'
}
})
.on('start', function () {
if (!called) {
called = true;
cb();
}
})
.on('restart', function () {
setTimeout(function () {
browserSync.reload({
stream: false
});
}, 1000);
});
});
/* jade compiliation */
gulp.task('jade', [], function () {
gulp.src(paths.jade)
.pipe(jade())
.pipe(gulp.dest('./client/'));
});
/* html build */
/* replace unoptimized scripts with minified */
gulp.task('html', ['jade'], function () {
return gulp.src(paths.html)
.pipe(gulp.dest('build'));
});
gulp.task('usemin', ['html'], function() {
return gulp.src('./build/index.html')
.pipe(usemin())
.pipe(gulp.dest('./build/'));
});
/* minify and move images */
gulp.task('images', function () {
return gulp.src('./client/assets/img/**/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}]
}))
.pipe(gulp.dest('build/assets/img'));
});
gulp.task('fonts', function() {
return gulp.src('./client/assets/fonts/**/*')
.pipe(gulp.dest('build/assets/fonts'));
});
/* testing call */
gulp.task('test', function (done) {
console.log('*****TESTING*****');
// var karma = require('karma').server;
// console.log('*****TESTING*****');
// karma.start({
// configFile: path.join(__dirname, '/karma.conf.js'),
// singleRun: true
// }, done);
return gulp.src(['test/unit/*.js', 'test/integration/*.js'], {
read: false
})
.pipe(mocha({
reporter: 'spec',
globals: {
chai: require('chai'),
assert: require('chai').assert,
expect: require('chai').expect,
should: require('chai').should()
}
}));
});
/* protractor task */
gulp.task('protractor', function(cb) {
gulp.src(["./test/e2e/specs/*.js"])
.pipe(protractor({
configFile: "test/e2e/conf.js",
args: ['--baseUrl', 'http://127.0.0.1:8000']
}))
.on('error', function(e) { throw e; });
});
gulp.task('webdriver_standalone', webdriver_standalone);
// /* eslint task */
gulp.task('lint', function () {
console.log('*****LINTING*****');
return gulp.src(['server/**/*.js', 'client/**/*.js', '!client/assets/**', '!client/app/shared/mdParser/fm.js', './gulpfile.js', '!server/assets/**', '!server/services/fuse.js'])
.pipe(eslint())
.pipe(eslint.format());
});
/* integrate instructions */
gulp.task('integrate', function () {
console.log('\n');
console.log('*****DEV TEAM TASKS******');
console.log('\n');
console.log('1. ensure that you have latest known-good code. ("git pull --rebase upstream master")');
console.log('2. make sure git status is clean');
console.log('3. test and lint on your box (run "gulp")');
console.log('4. Squash any unecessary commits with rebase');
console.log('5. push to YOUR repository branch ("git push origin staging")');
console.log('6. Create pull request to master branch of upstream repo');
console.log('7. If PR closes your issue, write "close #<issue number>"');
console.log('\n');
console.log('*****YOU DID IT******');
});
})();