This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
gulpfile.js
135 lines (114 loc) · 4.01 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
var
path = require('path'),
gulp = require('gulp'),
source = require('vinyl-source-stream'),
sequence = require('gulp-sequence'),
gutil = require('gulp-util'),
watchify = require('watchify'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
stylus = require('gulp-stylus'),
buffer = require('gulp-buffer'),
autoprefixer = require('gulp-autoprefixer'),
csso = require('gulp-csso'),
plumber = require('gulp-plumber'),
rupture = require('rupture'),
del = require('del'),
inlineCss = require('gulp-inline-css'),
concat = require('gulp-concat'),
prompt = require('gulp-prompt'),
zip = require('gulp-zip'),
fs = require('fs'),
paths = {};
paths.dist = './dist/assets';
paths.css = './assets-src/css';
paths.js = './assets-src/js';
paths.images = './assets-src/images';
paths.fonts = './assets-src/fonts';
gulp.task('js-third-party', function() {
return gulp.src([
paths.js + '/third-party/jquery.js',
paths.js + '/third-party/*.js'
])
.pipe(plumber())
.pipe(concat('app-third-party.min.js'))
.pipe(uglify())
.pipe(plumber.stop())
.pipe(gulp.dest(paths.dist))
});
gulp.task('js', function() {
return gulp.src([
'!' + paths.js + '/third-party/**/*',
paths.js + '/lib/*.js',
paths.js + '/*.js'
])
.pipe(concat('app.js'))
.pipe(plumber())
.pipe(gulp.dest(paths.dist))
.pipe(rename('app.min.js'))
.pipe(uglify())
.pipe(plumber.stop())
.pipe(gulp.dest(paths.dist));
});
gulp.task('css', function() {
return gulp.src([
paths.css + '/index.styl'
])
.pipe(plumber())
.pipe(stylus({
'include css': true,
paths: ['node_modules'],
use: [rupture()]
}))
.pipe(autoprefixer(['last 2 versions', '> 2%']))
.pipe(csso())
.pipe(plumber.stop())
.pipe(rename('app.css'))
.pipe(gulp.dest(paths.dist));
});
gulp.task('images', function () {
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
return gulp.src(paths.images + '/**/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(paths.dist + '/images'));
});
gulp.task('fonts', function () {
return gulp.src(paths.fonts + '/**/*')
.pipe(gulp.dest(paths.dist + '/fonts'));
});
gulp.task('clean', function() {
return del(path.join(paths.dist, '*'));
});
gulp.task('all', sequence('clean', ['css', 'js', 'js-third-party', 'fonts', 'images']));
// Run everything but watch it after too
gulp.task('default', ['all'], function() {
gulp.watch([paths.css + '/**/*'], ['css']);
gulp.watch(['!' + paths.js + 'third-party/*', paths.js + '/**/*'], ['js']);
gulp.watch([paths.js + '/third-party/**/*'], ['js-third-party']);
gulp.watch([paths.images + '/**/*'], ['images']);
});
// Create a release for github
gulp.task('release', ['all'], function() {
gulp.src('gulpfile.js')
.pipe(prompt.prompt({
type: 'input',
name: 'version',
message: 'What version is this release?'
}, function(res){
console.log('version', res.version);
return gulp.src(['dist/**/*', 'dist/.htaccess', '!dist/config.php', '!dist/cache/events/*.json', '!dist/.DS_Store'])
.pipe(zip('r3-' + res.version + '.zip'))
.pipe(gulp.dest('release'));
}));
});
// This is the same as the default task but it doesn't have any watchers
// which means it correctly exits when complete (used on deployment)
gulp.task('build', ['css', 'js', 'js-third-party', 'fonts'], function() {
console.log('All built!');
});