-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
200 lines (169 loc) · 5.32 KB
/
gulpfile.js
File metadata and controls
200 lines (169 loc) · 5.32 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
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
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var sourcemaps = require('gulp-sourcemaps');
var del = require('del');
var nodemon = require('gulp-nodemon');
var plumber = require('gulp-plumber');
var beeper = require('beeper');
var stylus = require('gulp-stylus');
var addsrc = require('gulp-add-src');
var less = require('gulp-less');
var runSequence = require('run-sequence');
var rm = require('gulp-rimraf');
var async = require('async');
var gulpFilter = require('gulp-filter');
var minifycss = require('gulp-minify-css');
var mainBowerFiles = require('main-bower-files');
var merge = require('merge-stream');
var streamqueue = require('streamqueue');
var gulpif = require('gulp-if');
var argv = require('yargs').argv;
// var jwtService = require('./server/service/jwtTokenService');
var minifyFiles = true;
var buildOptionsPrintedToConsole = false;
function onError(err) {
beeper();
console.log(err);
}
gulp.task('bowerScripts', ['setBuildOptions'], function(cb) {
var jsFilter = gulpFilter(['*.js', '!*.min.js'], {restore: true});
var fontFilter = gulpFilter(['*.eot', '*.woff', '*.svg', '*.ttf'], {restore: true});
gulp.src(mainBowerFiles())
.pipe(jsFilter)
.pipe(gulp.dest('client/dist/bowerScriptFilesList'))
.pipe(sourcemaps.init())
.pipe(concat('bowerComponents.js'))
//.pipe(gulpif(minifyFiles, uglify()))
.pipe(gulpif(minifyFiles, sourcemaps.write('./sourcemaps')))
.pipe(gulp.dest('client/dist/js'))
.on('end', cb);
});
// gulp.task('scripts', ['setBuildOptions'], function(cb) {
// gulp.src(['client/**/*.js'])
// .pipe(sourcemaps.init())
// .pipe(concat('scripts.js'))
//.pipe(gulpif(minifyFiles, uglify()))
// .pipe(gulpif(minifyFiles, sourcemaps.write('./sourcemaps')))
// .pipe(gulp.dest('client/dist/js'))
// .on('end', cb);
// });
gulp.task('lintScripts', function() {
var appScripts = function(cb) {
gulp.src(['client/scripts/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.on('end', cb);
}
gulp.src(['server/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.on('end', appScripts);
});
gulp.task('bowerStyles', ['setBuildOptions'], function(cb) {
var cssFilter = gulpFilter(['*.css', '!*.min.css']);
async.series([
function(next) {
gulp.src(mainBowerFiles())
.pipe(cssFilter)
.pipe(gulp.dest('client/dist/bowerCSSFileList'))
.pipe(concat('bowerComponents.css'))
.pipe(gulpif(minifyFiles, minifycss()))
.pipe(gulp.dest('client/dist/styles'))
.on('end', next);
},
function(next) {
gulp.src(['client/3rdPartyScripts/bower_components/font-awesome/css/font-awesome.css'])
.pipe(gulp.dest('client/dist/styles'))
.on('end', next);
},
function(next) {
gulp.src('client/3rdPartyScripts/bower_components/bootstrap/fonts/*')
.pipe(gulp.dest('client/dist/fonts'))
.on('end', next);
},
function(next) {
gulp.src('client/3rdPartyScripts/bower_components/font-awesome/fonts/*')
.pipe(gulp.dest('client/dist/fonts'))
.on('end', next);
}
], cb);
});
gulp.task('styles', ['setBuildOptions'], function(cb) {
// var cssFilter = gulpFilter(['*.css', '!.min.css'], {restore: true});
var queue = streamqueue({ objectMode: true });
queue.queue(gulp.src(['client/styles/**/*.css']));
queue.queue(gulp.src(['client/styles/**/*.styl']).pipe(stylus()));
queue.done()
.pipe(plumber({
errorHandler: onError
}))
.pipe(concat('styles.css'))
.pipe(gulpif(minifyFiles, minifycss()))
.pipe(gulp.dest('client/dist/styles'));
cb();
});
gulp.task('del', function(cb) {
return gulp.src('client/dist').pipe(rm());
});
gulp.task('watch', function() {
gulp.watch('client/styles/**/*', ['styles']);
gulp.watch('client/**/*.js', ['scripts']);
});
gulp.task('nodemon', function() {
beeper();
nodemon({
script: './startServer.js'
/*ignore: [
'/client/scripts/**',
'/node_modules/**',
'/bower_components/**',
'/test',
'*'
]*/
}).on('start', function () {
console.log("Nodemon started and monitoring.");
})
.on('restart', function() {
console.log("Nodemon restart...");
});
});
gulp.task('build', function () {
runSequence(['lintScripts', 'del'], ['bowerStyles', 'styles', 'bowerScripts']);
});
gulp.task('dev', function() {
runSequence(['nodemon', 'watch']);
});
// Set all tasks to run for development or production
// based on 'dev' being passed as argument
// (gulp [task] dev).
gulp.task('setBuildOptions', function(cb) {
if (argv.dev) {
if (!buildOptionsPrintedToConsole) {
console.log("\n=== Building for development without minification files ===\n");
}
minifyFiles = false;
}
else {
minifyFiles = true;
console.log("\n=== Building for production with minification of files ===\n");
}
cb();
});
gulp.task('resetJWTKey', function() {
jwtService.createNewKey();
});
// Call syntax: gulp createAdminUser --username='[username]' --password='[password]'
gulp.task('createAdminUser', function() {
console.log(argv.username);
console.log(argv.password);
var userService = require('./server/userService');
var user = {
username: argv.username,
password: argv.password,
role: 'admin'
};
userService.create(user);
});