This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·202 lines (168 loc) · 4.7 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
/* eslint-disable */
const gulp = require('gulp');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const browserSync = require('browser-sync').create();
const sitemap = require('gulp-sitemap');
const handlebars = require('gulp-compile-handlebars');
const path = require('path');
const rename = require('gulp-rename');
const svgstore = require('gulp-svgstore');
const svgo = require('gulp-svgo');
const copy = require('gulp-copy');
const webpack = require('webpack');
const w3cjs = require('gulp-w3cjs');
const access = require('gulp-accessibility');
const buildpath = {
main: 'public/',
js: 'public/js/',
css: 'public/css/',
images: 'public/images/',
favicon: 'public/favicon/'
};
const stylesheets = ['assets/sass/style-rtl.scss', 'assets/sass/style-ltr.scss'];
gulp.task('copy', ['copy:favicon', 'copy:images', 'copy:robots']);
gulp.task('copy:robots', function (cb) {
return gulp.src(['assets/robots.txt'])
.pipe(copy(buildpath.main, {
prefix: 2
}));
});
gulp.task('copy:favicon', function (cb) {
return gulp.src(['assets/favicon/**/*'])
.pipe(copy(buildpath.favicon, {
prefix: 2
}));
});
gulp.task('copy:images', function (cb) {
return gulp.src(['assets/images/**/*'])
.pipe(copy(buildpath.images, {
prefix: 2
}));
});
gulp.task('webpack', function () {
return webpack(require('./webpack.config.dev.js'), function (err, stats) {
if (err) {
console.error("webpack", err)
}
console.log("[webpack]", stats.toString({
colors: true
}));
browserSync.reload();
});
});
gulp.task('webpack:prod', function (cb) {
return webpack(require('./webpack.config.prod.js'), function (err, stats) {
if (err) {
console.error("[webpack]", err)
}
console.log("[webpack]", stats.toString({
colors: true
}));
});
});
gulp.task('postcss:dev', function () {
var processors = [
autoprefixer({
browsers: ['last 2 versions']
})
];
return gulp.src(stylesheets)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss(processors))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(buildpath.css))
.pipe(browserSync.stream({
match: "**/*.css"
}));
});
gulp.task('postcss:prod', function () {
var processors = [
autoprefixer({
browsers: ['last 2 versions']
}),
];
return gulp.src(stylesheets)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss(processors))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(buildpath.css))
});
gulp.task('svgo', function () {
return gulp.src('assets/icons/*.svg')
.pipe(svgo())
.pipe(gulp.dest('assets/icons'));
});
gulp.task('svgstore', ['svgo'], function () {
return gulp
.src('assets/icons/*.svg')
.pipe(rename({
prefix: 'icon-'
}))
.pipe(svgstore())
.pipe(gulp.dest(buildpath.images));
});
gulp.task('watch', function () {
gulp.watch(['source/**/*.html', 'partials/**/*.html'], ['handlebars']);
gulp.watch(['assets/sass/**/*.scss'], ['postcss:dev']);
gulp.watch(['assets/js/**/*.js'], ['webpack']);
gulp.watch(['assets/icons/*.svg'], ['svgstore']);
gulp.watch(['assets/images/**/*'], ['copy:images']);
});
gulp.task('browserSync', function () {
browserSync.init({
server: {
baseDir: "./public"
}
});
});
gulp.task('sitemap', function () {
gulp.src('public/**/*.html', {
read: false
})
.pipe(sitemap({
changefreq: 'weekly',
siteUrl: 'http://www.prototype.ae/',
lastmod: '2016-01-01T09:54:31.000Z',
priority: '1'
}))
.pipe(gulp.dest(buildpath.main));
});
gulp.task('handlebars', function () {
var options = {
batch: ['partials']
};
var files = [
['source/index.html', 'public/index.html']
];
return files.forEach(function (filePair) {
var src = filePair[0];
var dist = filePair[1];
var distDir = path.dirname(dist);
var distFileName = path.basename(dist);
return gulp.src(src)
.pipe(handlebars({}, options))
.pipe(rename(distFileName))
.pipe(gulp.dest(distDir))
.pipe(browserSync.stream());
});
});
gulp.task('w3cjs', function () {
return gulp.src(buildpath.main + '**/*.html')
.pipe(w3cjs())
.pipe(w3cjs.reporter());
});
gulp.task('a11y', function () {
return gulp.src(buildpath.main + '**/*.html')
.pipe(access({
force: true
}))
.on('error', console.log);
});
gulp.task('default', ['copy', 'handlebars', 'svgstore', 'webpack', 'postcss:dev', 'browserSync', 'watch']);
gulp.task('prod', ['copy', 'svgstore', 'webpack:prod', 'postcss:prod']);
gulp.task('test', ['w3cjs', 'a11y']);