forked from enterstudio/conan.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
181 lines (160 loc) · 4.79 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
'use strict';
const colors = {
Reset: "\x1b[0m",
Bright: "\x1b[1m",
Dim: "\x1b[2m",
Underscore: "\x1b[4m",
Blink: "\x1b[5m",
Reverse: "\x1b[7m",
Hidden: "\x1b[8m",
fg: {
Black: "\x1b[30m",
Red: "\x1b[31m",
Green: "\x1b[32m",
Yellow: "\x1b[33m",
Blue: "\x1b[34m",
Magenta: "\x1b[35m",
Cyan: "\x1b[36m",
White: "\x1b[37m",
Crimson: "\x1b[38m" //القرمزي
},
bg: {
Black: "\x1b[40m",
Red: "\x1b[41m",
Green: "\x1b[42m",
Yellow: "\x1b[43m",
Blue: "\x1b[44m",
Magenta: "\x1b[45m",
Cyan: "\x1b[46m",
White: "\x1b[47m",
Crimson: "\x1b[48m"
}
};
const gulp = require('gulp');
const terser = require('gulp-terser');
const htmlmin = require('gulp-html-minifier-terser');
const concat = require('gulp-concat');
const sourcemaps = require('gulp-sourcemaps');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const image = require('gulp-image');
const sass = require('gulp-sass');
sass.compiler = require('node-sass');
const {src, series, parallel, dest, watch} = require('gulp');
//functions
function htmlTask() {
return src('src/*.html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('./'));
}
function jsTask() {
return src('src/js/*.js')
.pipe(sourcemaps.init('.'))
.pipe(concat('all.js'))
.pipe(terser())
.pipe(sourcemaps.write('.'))
.pipe(dest('js'));
}
function scssTask() {
return src('src/scss/*.scss')
.pipe(sourcemaps.init('.'))
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('src/css'))
.pipe(sourcemaps.write('.'));
}
function cssTask() {
return src('src/css/*.css')
.pipe(sourcemaps.init('.'))
.pipe(concat('all.css'))
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(sourcemaps.write('.'))
.pipe(dest('css'));
}
function imgTask() {
return src('./src/img/*')
.pipe(image())
.pipe(gulp.dest('img/'));
}
function imgAdvantagesTask() {
return src('./src/img/advantages/*')
.pipe(image())
.pipe(gulp.dest('img/advantages/'));
}
function imgbrandsTask() {
return src('./src/img/brands/*')
.pipe(image())
.pipe(gulp.dest('img/brands/'));
}
function imgdownloadsTask() {
return src('./src/img/downloads/*')
.pipe(image())
.pipe(gulp.dest('img/downloads/'));
}
function imglogoTask() {
return src('./src/img/logo/*')
.pipe(image())
.pipe(gulp.dest('img/logo/'));
}
function imgourusersTask() {
return src('./src/img/our-users/*')
.pipe(image())
.pipe(gulp.dest('img/our-users/'));
}
function imgsocialTask() {
return src('./src/img/social/*')
.pipe(image())
.pipe(gulp.dest('img/social/'));
}
function imgTribe2020() {
return src('./src/img/conan-tribe/*')
.pipe(image())
.pipe(gulp.dest('img/conan-tribe/'));
}
function watchAll() {
const htmlWatcher = watch(['src/*', '!src/img/*', '!src/css/*', '!src/js/*', '!src/scss/*']);
htmlWatcher.on('change', function(path, stats) {
console.log(`File ${path} was changed, running htmlTask`);
htmlTask();
console.log(colors.bg.Green, colors.fg.White, 'Success', colors.Reset);
});
const scssWatcher = watch(['src/scss/*']);
scssWatcher.on('change', function(path, stats) {
console.log(`File ${path} was changed, running scssTask`);
scssTask();
console.log(colors.bg.Green, colors.fg.White, 'Success', colors.Reset);
});
const cssWatcher = watch(['src/css/*']);
cssWatcher.on('change', function(path, stats) {
console.log(`File ${path} was changed, running cssTask`);
cssTask();
console.log(colors.bg.Green, colors.fg.White, 'Success', colors.Reset);
});
const jsWatcher = watch(['src/js/*']);
jsWatcher.on('change', function(path, stats) {
console.log(`File ${path} was changed, running jsTask`);
jsTask();
console.log(colors.bg.Green, colors.fg.White, 'Success', colors.Reset);
});
const imgWatcher = watch(['src/img/*']);
imgWatcher.on('change', function(path, stats) {
console.log(`File ${path} was changed, running imgTask.`);
imgTask();
});
console.log(colors.fg.Green, 'Watching files...', colors.Reset)
}
exports.scssTask = scssTask;
exports.cssTask = cssTask;
exports.jsTask = jsTask;
exports.htmlTask = htmlTask;
exports.imgTask = imgTask;
exports.imgAdvantagesTask = imgAdvantagesTask;
exports.imgbrandsTask = imgbrandsTask;
exports.imgdownloadsTask = imgdownloadsTask;
exports.imglogoTask = imglogoTask;
exports.imgourusersTask = imgourusersTask;
exports.imgsocialTask = imgsocialTask;
exports.imgTribe2020 = imgTribe2020;
exports.watchAll = watchAll;
exports.default = series(scssTask, cssTask, jsTask, htmlTask);
exports.imagesTask = series(imgTask, imgAdvantagesTask, imgbrandsTask, imgdownloadsTask, imglogoTask, imgourusersTask, imgsocialTask, imgTribe2020);