-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
200 lines (184 loc) · 4.13 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
/**
* Supported Packages
* List here all dependencies necessary to run required tasks.
*/
const gulp = require("gulp");
const rename = require("gulp-rename");
const sass = require("gulp-sass")(require("sass"));
const cleanCSS = require("gulp-clean-css");
const autoprefixer = require("gulp-autoprefixer");
const header = require("gulp-header");
const eslint = require("gulp-eslint");
const gulpIf = require("gulp-if");
const concat = require("gulp-concat");
const uglify = require("gulp-uglify-es").default;
const access = require("gulp-accessibility");
/**
* Uglify Settings
*
* @since 1.0.0
*/
const uglifyOptions = {
compress: {
// eslint-disable-next-line camelcase
drop_console: true,
},
};
/**
* Paths & Files
*
* @since 1.0.0
*/
const fileName = "@iamleigh/es6-components";
const srcInput = {};
srcInput.js = "./assets/js/";
srcInput.css = "./assets/scss/";
const srcOutput = {};
srcOutput.js = "./assets/js/dist/";
srcOutput.css = "./assets/css/";
/**
* Copyright Banner
*/
const banner = [
"/*!",
" * ES6 Components CSS (" + fileName + ")",
" * ",
" * Copyright 2023 Leighton Quito (https://iamleigh.com)",
" * Licensed under MIT (https://opensource.org/license/mit/)",
" */",
"",
].join("\n");
/**
* List of Supported Browsers
*
* @since 1.0.0
*/
const browsersList = ["last 2 version", "> 1%"];
/**
* 🗂️ Copy required files
*
* @since 1.0.0
*/
gulp.task("copy-css", function () {
return gulp.src(["."]); // do nothing
});
gulp.task("copy-js", function () {
return gulp
.src(["./node_modules/jquery/dist/jquery.min.js"])
.pipe(gulp.dest(srcOutput.js));
});
gulp.task("copy", gulp.series(["copy-css", "copy-js"]));
/**
* 📦 Build CSS
*
* - Linter issues
* - Concat files into one
* - Minify concated file
*
* @since 1.0.0
*/
gulp.task("styles", function () {
return (
gulp
.src(srcInput.css + "**/*.scss")
// Check if files have an error
.pipe(sass({ outputStyle: "expanded" }).on("error", sass.logError))
.pipe(autoprefixer(browsersList))
.pipe(header(banner))
.pipe(gulp.dest(srcOutput.css))
.pipe(cleanCSS())
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest(srcOutput.css))
.on("finish", function () {
console.log("📦 Finished compiling styles.");
})
);
});
/**
* 📦 Build JS
*
* - Linter and auto-fix issues
* - Concat files into one
* - Minify concated file
*
* @since 1.0.0
*/
function isFixed(file) {
// Check if ESLint has run the fix
return file.eslint !== null && file.eslint.fixed;
}
gulp.task("scripts", function () {
return (
gulp
.src(srcInput.js + "*.js")
.pipe(eslint({ fix: true }))
.pipe(eslint.format())
// Replace existing file with fixed one
.pipe(gulpIf(isFixed, gulp.dest(srcInput.js + "*.js")))
.pipe(eslint.failAfterError())
.pipe(concat("main.js"))
.pipe(header(banner))
.pipe(gulp.dest(srcOutput.js))
.pipe(uglify(uglifyOptions))
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest(srcOutput.js))
.on("finish", function () {
console.log("📦 Finished compiling scripts.");
})
);
});
/**
* 📦 Compile Assets
*
* @since 1.0.0
*/
gulp.task("compile", gulp.series(["copy", "styles", "scripts"]));
/**
* 🧪 Accessibility
*
* Lints WCAG2A suggestions:
* - [NOTICE] Elements to pay attention and run manual checks.
* - [WARNING] Elements that require an improvement.
* - [ERROR] Important semantic improvements.
*
* @since 1.0.0
*/
gulp.task("a11y", function () {
return gulp
.src("index.html")
.pipe(
access({
force: true,
})
)
.on("error", console.log)
.pipe(access.report({ reportType: "txt" }))
.pipe(
rename({
extname: ".txt",
})
)
.pipe(gulp.dest("reports/txt"));
});
/**
* 🧑🏻💻 Watch Changes
*
* Task written for development mode.
*
* @since 1.0.0
*/
gulp.task("watch", function () {
gulp.watch(srcInput.css + "**/**/**/*.scss", gulp.series(["styles"]));
gulp.watch(srcInput.js + "*.js", gulp.series(["scripts"]));
});
/**
* 🚀 Deploy
*
* Task written for production mode.
*
* @todo Include copy release files to `build` folder
* @todo Include `gh-pages` deploy task
*
* @since 1.0.0
*/
gulp.task("deploy", gulp.series(["compile"]));