-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·261 lines (205 loc) · 7.41 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
258
259
260
261
'use strict';
// -----------------------------------------------------------------------------
// Dependencies
// -----------------------------------------------------------------------------
var gulp = require('gulp');
// Sass and CSS Stuff
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var notify = require("gulp-notify");
var minifyCss = require('gulp-minify-css');
// Image Stuff
var imagemin = require('gulp-imagemin');
// Local Server Stuff
var browserSync = require('browser-sync').create();
var php = require('gulp-connect-php');
var httpProxy = require('http-proxy');
var replace = require('gulp-replace-path');
var path = require('path');
var proxy = httpProxy.createProxyServer({});
var reload = browserSync.reload;
// Housekeeping Stuff
var del = require('del');
var git = require('gulp-git');
var bump = require('gulp-bump');
var filter = require('gulp-filter');
var tag_version = require('gulp-tag-version');
// -----------------------------------------------------------------------------
// Configuration
// -----------------------------------------------------------------------------
// Files and Folders Configarables
var DevFolder = './dev';
var DistFolder = './dist';
// Sass Configarables
var SassInput = './scss/**/*.scss';
var SassOutput = './tmp/css';
var SassOutputBuild = './dist/css/';
var SassOptions = { outputStyle: 'expanded' };
var autoprefixerOptions = { browsers: ['last 2 versions', '> 5%', 'Firefox ESR'] };
// JavaScript Configarables
var JSInput = ['./scripts/monotype.js'];
var JSConcat = ['./javascript/block/**/*.js', './javascript/global/**/*.js'];
var JSOutput = './tmp/scripts/';
// Images Configurables
var ImagesFolder = './image';
// BrowserSync Files to watch changes for
var watchFiles = ['tmp/**/*.php', 'css/**/*.css', 'tmp/**/*.css', 'tmp/**/*.js'];
// -----------------------------------------------------------------------------
// Sass compilation
// -----------------------------------------------------------------------------
gulp.task('sass', function () {
return gulp
.src(SassInput)
.pipe(sourcemaps.init())
.pipe(sass(SassOptions)).on('error', notify.onError(function (error) {return "Problem file : " + error.message;}))
.pipe(sourcemaps.write())
.pipe(autoprefixer(autoprefixerOptions))
.pipe(browserSync.stream())
.pipe(gulp.dest(SassOutput))
});
// Production build
gulp.task('sass:build', function () {
return gulp
.src(SassInput)
.pipe(sass())
.pipe(autoprefixer(autoprefixerOptions))
.pipe(minifyCss())
.pipe(gulp.dest(SassOutputBuild));
});
// -----------------------------------------------------------------------------
// Image Optimisation
// -----------------------------------------------------------------------------
gulp.task('images', function () {
return gulp.src('dev/images/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('dist/image'));
});
// -----------------------------------------------------------------------------
// Local Server and BrowserSync
// -----------------------------------------------------------------------------
gulp.task('php-serve', function () {
php.server({
port: 9001,
open: false
});
browserSync.init({
notify: false,
port : 9000,
files : watchFiles,
server: {
baseDir : ['tmp'],
routes : {
'/bower_components': 'bower_components'
},
middleware: function (req, res, next) {
var url = req.url;
if (!url.match(/^\/(css|bower_components)\//)) {
proxy.web(req, res, { target: 'http://127.0.0.1:9001' });
} else {
next();
}
}
}
});
});
gulp.task('copyit', function() {
gulp.src('css/**/*')
.pipe(gulp.dest('tmp/css'))
});
gulp.task('copyBuild', function() {
gulp.src('doc/**/*')
.pipe(gulp.dest('dist/doc'));
gulp.src(['**/*.php', '!node_modules/**/*.php'])
.pipe(gulp.dest('dist/'));
gulp.src('images/**/*')
.pipe(gulp.dest('dist/images'));
gulp.src('javascript/**/*')
.pipe(gulp.dest('dist/javascript'));
gulp.src('markup/**/*')
.pipe(gulp.dest('dist/markup'));
gulp.src('sg-assets/**/*')
.pipe(gulp.dest('dist/sg-assets'));
gulp.src('data.json')
.pipe(gulp.dest('dist/'));
});
// -----------------------------------------------------------------------------
// Watchers
// -----------------------------------------------------------------------------
gulp.task('watch', function() {
gulp.watch(SassInput, ['sass'])
gulp.watch(JSConcat, ['concatScripts'])
.on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
gulp.watch([
'**/*.html',
'*.php',
'css/*.css',
'scss/*.scss',
'images/**/*',
'scripts/**/*'
]).on('change', reload);
gulp.watch(['tmp/css/**/*.css']);
});
// -----------------------------------------------------------------------------
// Delete Everything in Dist
// -----------------------------------------------------------------------------
gulp.task('del', function() {
del([
'./dist', './tmp'
]);
});
gulp.task('delete', function() {
del([
'./dist', './tmp', './dev/designlanguage/dist', './dev/designlanguage/*.json', './dev/designlanguage/gulpfile.js', './dev/designlanguage/LICENSE', './dev/designlanguage/README.md', 'bower_components'
]);
});
// -----------------------------------------------------------------------------
// Git Tag Bumps
// -----------------------------------------------------------------------------
/**
* Bumping version number and tagging the repository with it.
* Please read http://semver.org/
*
* You can use the commands
*
* gulp patch # makes v0.1.0 → v0.1.1
* gulp feature # makes v0.1.1 → v0.2.0
* gulp release # makes v0.2.1 → v1.0.0
*
* To bump the version numbers accordingly after you did a patch,
* introduced a feature or made a backwards-incompatible release.
*/
function inc(importance) {
// get all the files to bump version in
return gulp.src(['./package.json', './bower.json'])
// bump the version number in those files
.pipe(bump({type: importance}))
// save it back to filesystem
.pipe(gulp.dest('./'))
// commit the changed version number
.pipe(git.commit('bumps package version'))
// read only one file to get the version number
.pipe(filter('package.json'))
// **tag it in the repository**
.pipe(tag_version());
}
gulp.task('patch', function() { return inc('patch'); })
gulp.task('feature', function() { return inc('minor'); })
gulp.task('release', function() { return inc('major'); })
// -----------------------------------------------------------------------------
// Default task
// -----------------------------------------------------------------------------
// all the tasks in the world
gulp.task('default', ['sass', 'watch', 'php-serve']);
// single, one time set-up to move everything and delete things
gulp.task('tidy', ['delete']);
// used for when making things
gulp.task('dev', ['copyit', 'sass', 'watch', 'php-serve']);
// used for when ready to publish
gulp.task('build', ['sass:build', 'copyBuild']);