-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.babel.js
177 lines (161 loc) · 4.3 KB
/
gulpfile.babel.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
// Get gulp components and templates.
/* eslint-disable */
import { series, parallel, watch } from "gulp";
import { css, js, lib, sass } from "@coldfrontlabs/gulp-templates";
/* eslint-enable */
const paths = {
css: {
src: "assets/css",
dest: "assets/css",
selector: "**/*.css",
},
js: {
src: "assets/js",
dest: "assets/js",
selector: "**/*.js",
},
sass: {
src: "assets/scss",
dest: "assets/scss",
selector: "**/*.scss",
// Ignore specifically for Stylelint:fix bug.
ignore: ["!src/scss/ignored-code/**/*.scss"],
},
min: "**/*.min.*",
};
/**
* Lints all Sass files.
*
* @return {Object} - Gulp stream.
*/
export const lintStyles = () =>
sass.lint(`${paths.sass.src}/${paths.sass.selector}`);
lintStyles.description = "Lints all Sass files.";
/**
* Lints all JS files.
*
* @return {Object} - Gulp stream.
*/
export const lintScripts = () =>
js.lint(`${paths.js.src}/${paths.js.selector}`);
lintScripts.description = "Lints all JS files.";
/**
* Lints and fixes all Sass files.
*
* @return {Object} - Gulp stream.
*/
export const lintStylesFix = () =>
sass.fix([`${paths.sass.src}/${paths.sass.selector}`, ...paths.sass.ignore]);
lintStylesFix.description = "Lints and fixes all Sass files.";
/**
* Lints and fixes all JS files.
*
* @return {Object} - Gulp stream.
*/
export const lintScriptsFix = () =>
js.fix(`${paths.js.src}/${paths.js.selector}`);
lintScriptsFix.description = "Lints and fixes all JS files.";
/**
* Compiles all Sass files.
*
* @return {Object} - Gulp stream.
*/
const compileSass = () =>
sass.compile(`${paths.sass.src}/${paths.sass.selector}`, paths.css.dest);
/**
* Compiles all CSS files.
*
* @return {Object} - Gulp stream.
*/
const compileCSS = () =>
css.compile(
[`${paths.css.src}/${paths.css.selector}`, `!${paths.min}`],
paths.css.dest
);
/**
* Compiles all Sass files and CSS files afterward.
*
* @returns {Object} - Gulp stream.
*/
export const compileStyles = series(compileSass, compileCSS);
compileStyles.description = "Compiles all Sass files and CSS files afterward.";
/**
* Compiles all JS files using Babel.
*
* @return {Object} - Gulp stream.
*/
export const compileScripts = () =>
js.compile(`${paths.js.src}/${paths.js.selector}`, paths.js.dest);
compileScripts.description = "Compiles all JS files using Babel.";
/**
* Minifies all CSS files.
*
* @return {Object} - Gulp stream.
*/
export const minifyStyles = () =>
css.minify(
[`${paths.css.src}/${paths.css.selector}`, `!${paths.min}`],
paths.css.dest
);
minifyStyles.description = "Minifies all CSS files.";
/**
* Minifies all JS files.
*
* @return {Object} - Gulp stream.
*/
export const minifyScripts = () =>
js.minify(
[`${paths.js.dest}/${paths.js.selector}`, `!${paths.min}`],
paths.js.dest
);
minifyScripts.description = "Minifies all JS files.";
/**
* Gathers all required libraries.
*
* @return {Object} - Gulp stream.
*/
export const fetchLibs = () =>
lib.fetch(paths.lib.src, paths.lib.dest, { base: "./node_modules/" });
fetchLibs.description = "Gathers all required libraries.";
/**
* Lints, compiles, and minifies all Sass/CSS/JS files and gathers all libraries.
*
* @returns {Object} - Gulp stream.
*/
export const buildDev = parallel(
series(lintStyles, compileStyles, minifyStyles),
series(lintScripts, compileScripts, minifyScripts),
fetchLibs
);
buildDev.description =
"Lints, compiles, and minifies all Sass/CSS/JS files and gathers all libraries.";
/**
* Compiles and minifies all Sass/CSS/JS files and gathers all libraries.
*
* @returns {Object} - Gulp stream.
*/
export const buildProd = parallel(
series(compileStyles, minifyStyles),
series(compileScripts, minifyScripts),
fetchLibs
);
buildProd.description =
"Compiles and minifies all Sass/CSS/JS files and gathers all libraries.";
/**
* Watches all Sass/JS files and lints, compiles, and minifies them.
*/
function watchFiles() {
watch(
`${paths.sass.src}/${paths.sass.selector}`,
series(lintStyles, compileStyles, minifyStyles)
);
watch(
`${paths.js.src}/${paths.js.selector}`,
series(lintScripts, compileScripts, minifyScripts)
);
}
watchFiles.description =
"Watches all Sass/JS files and lints, compiles, and minifies them.";
export { watchFiles as watch };
// Create default tasks
export default buildProd;