This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
229 lines (197 loc) · 6.46 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';
//load dependencies
var gulp = require('gulp'),
git = require('gulp-git'),
bump = require('gulp-bump'),
jshint = require('gulp-jshint'),
size = require('gulp-size'),
uglify = require('gulp-uglify-es').default,
useref = require('gulp-useref'),
cleanCSS = require('gulp-clean-css'),
connect = require('gulp-connect'),
autoprefixer = require('gulp-autoprefixer'),
filter = require('gulp-filter'),
del = require('del'),
open = require('open'),
semver = require('semver'),
replace = require('gulp-string-replace'),
stylish = require('jshint-stylish');
//get current app version
var version = require('./package.json').version;
//function for version lookup and tagging
function inc(importance) {
//get new version number
var newVer = semver.inc(version, importance);
//bump appConfig version
gulp.src('./src/appConfig.js')
.pipe(replace(/configuration.version = "([^"]+)"/g, 'configuration.version = "' + newVer + '"'))
.pipe(gulp.dest('./src/'));
//.pipe(git.add());
gulp.src('./dist/appConfig.js')
.pipe(replace(/configuration.version = "([^"]+)"/g, 'configuration.version = "' + newVer + '"'))
.pipe(gulp.dest('./dist/'));
//.pipe(git.add());
//bump test appConfig version
gulp.src('./src/appConfig_test.js')
.pipe(replace(/configuration.version = "([^"]+)"/g, 'configuration.version = "' + newVer + '"'))
.pipe(gulp.dest('./src/'));
//.pipe(git.add());
gulp.src('./dist/appConfig_test.js')
.pipe(replace(/configuration.version = "([^"]+)"/g, 'configuration.version = "' + newVer + '"'))
.pipe(gulp.dest('./dist/'));
//.pipe(git.add());
//bump dev appConfig version
gulp.src('./src/appConfig_dev.js')
.pipe(replace(/configuration.version = "([^"]+)"/g, 'configuration.version = "' + newVer + '"'))
.pipe(gulp.dest('./src/'));
//.pipe(git.add());
gulp.src('./dist/appConfig_dev.js')
.pipe(replace(/configuration.version = "([^"]+)"/g, 'configuration.version = "' + newVer + '"'))
.pipe(gulp.dest('./dist/'));
//.pipe(git.add());
// get all the files to bump version in
gulp.src(['package.json'])
// bump the version number in those files
.pipe(bump({ type: importance }))
// save it back to filesystem
.pipe(gulp.dest(function(file) {
return file.base;
}))
// commit the changed version number
.pipe(git.commit('Release v' + newVer))
// **tag it in the repository**
//.pipe(git.tag('v' + newVer));
.pipe(git.tag('v' + newVer, 'Version message', function (err) {
if (err) throw err;
}));
}
//tasks for version tags
gulp.task('patch', ['dist'], function () { return inc('patch'); });
gulp.task('feature', ['dist'], function () { return inc('minor'); });
gulp.task('release', ['dist'], function () { return inc('major'); });
//push task for versioning
gulp.task('push', function () {
console.info('Pushing...');
return git.push('USGS-WiM', 'master', { args: " --tags" }, function (err) {
if (err) {
console.error(err);
throw err;
} else {
console.info('done pushing to github!');
}
});
});
//copy data
gulp.task('data', function () {
return gulp.src('src/data/**/*')
.pipe(gulp.dest('dist/data'));
});
//copy to views folder
gulp.task('views', function () {
return gulp.src('src/Views/**/*')
.pipe(gulp.dest('dist/Views'));
});
// Styles
gulp.task('styles', function () {
return gulp.src(['src/styles/main.css'])
.pipe(autoprefixer('last 1 version'))
.pipe(gulp.dest('dist/styles'))
.pipe(size());
});
// Icons
gulp.task('icons', function () {
return gulp.src(['node_modules/font-awesome/fonts/*.*'])
.pipe(gulp.dest('dist/fonts'));
});
// Scripts
gulp.task('scripts', function () {
return gulp.src(['src/**/*.js'])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(stylish))
.pipe(size());
});
// HTML
gulp.task('html', ['styles', 'scripts', 'icons', 'views', 'data'], function () {
var jsFilter = filter('**/*.js', { restore: true });
var cssFilter = filter('**/*.css', { restore: true });
function createErrorHandler(name) {
return function (err) {
console.error('Error from ' + name + ' in compress task', err.toString());
};
}
return gulp.src('src/*.html')
.pipe(useref())
.pipe(jsFilter)
.pipe(uglify())
.on('error', createErrorHandler('uglify'))
.pipe(jsFilter.restore)
.pipe(cssFilter)
.pipe(cleanCSS({ processImport: false }))
.pipe(cssFilter.restore)
.pipe(gulp.dest('dist'))
.pipe(size());
});
// Images
gulp.task('images', function () {
return gulp.src('src/images/**/*')
.pipe(gulp.dest('dist/images'))
.pipe(size());
});
// Leaflet
gulp.task('leaflet', function () {
return gulp.src('node_modules/leaflet/dist/images/**/*')
.pipe(gulp.dest('dist/styles/images'))
.pipe(size());
});
// usgs-search-api
gulp.task('usgs-search-api', function () {
return gulp.src('node_modules/usgs-search-api/dist/*.gif')
.pipe(gulp.dest('dist/styles/images'))
.pipe(size());
});
// appConfig
gulp.task('appConfig', function () {
return gulp.src(['src/appConfig.js', 'web.config'])
.pipe(gulp.dest('dist/'))
});
// test appConfig
gulp.task('appConfig_test', function () {
return gulp.src(['src/appConfig_test.js', 'web.config'])
.pipe(gulp.dest('dist/'))
});
// dev appConfig
gulp.task('appConfig_dev', function () {
return gulp.src(['src/appConfig_dev.js', 'web.config'])
.pipe(gulp.dest('dist/'))
});
// Clean
gulp.task('clean', function (cb) {
del([
'dist/Views/**',
'dist/fonts/**',
'dist/styles/**',
'dist/scripts/**',
'dist/images/**'
], cb);
});
// build dist
gulp.task('dist', ['html', 'images', 'leaflet','usgs-search-api','appConfig','appConfig_test','appConfig_dev']);
// Default task
gulp.task('default', ['clean'], function () {
gulp.start('dist');
});
// Watch
gulp.task('watch', ['default', 'connect', 'serve'], function () {
// start up
});
// Connect
gulp.task('connect', function () {
connect.server({
root: 'dist',
port: 9000
});
});
// Open
gulp.task('serve', ['connect'], function () {
open("http://localhost:9000", { url: true });
});