-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
executable file
·198 lines (181 loc) · 4.6 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
"use strict";
import autoprefixer from "autoprefixer";
import bs from "browser-sync";
import { readFileSync } from "fs";
import gulp from "gulp";
import fileInclude from "gulp-file-include";
import comments from "gulp-header-comment";
import jshint from "gulp-jshint";
import postcss from "gulp-postcss";
import template from "gulp-template";
import gUtil from "gulp-util";
import wrapper from "gulp-wrapper";
import rimraf from "rimraf";
import * as dartSass from "sass";
import tailwindcss from "tailwindcss";
import through2 from "through2";
const theme = JSON.parse(readFileSync("./src/theme.json"));
const node_env = process.argv.slice(2)[0];
const headerComments = `WEBSITE: https://zeon.studio/
TWITTER: https://twitter.com/zeon_studio/
FACEBOOK: https://facebook.com/heyzeonstudio/
GITHUB: https://github.com/zeon-studio/`;
const path = {
// source paths
src: {
theme: "src/theme.json",
pages: "src/pages/*.html",
partials: "src/partials/**/*.html",
styles: "src/styles/*.scss",
scripts: "src/scripts/*.js",
plugins: "src/plugins/**/*",
public: "src/public/**/*",
},
// build paths
build: {
dir: "theme/",
},
};
// Styles task using native Sass compilation
function styles() {
return gulp
.src(path.src.styles)
.pipe(
through2.obj(function (file, enc, callback) {
if (file.isBuffer()) {
try {
const result = dartSass.compileString(file.contents.toString(), {
style: "expanded",
loadPaths: ["src/styles"],
});
file.contents = Buffer.from(result.css);
file.path = file.path.replace(".scss", ".css");
} catch (error) {
console.error("Sass compilation error:", error);
}
}
this.push(file);
callback();
}),
)
.pipe(postcss([tailwindcss("./tailwind.config.js"), autoprefixer]))
.pipe(comments(headerComments))
.pipe(gulp.dest(path.build.dir + "styles/"))
.pipe(
bs.reload({
stream: true,
}),
);
}
// pages
function pages() {
return gulp
.src(path.src.pages)
.pipe(
wrapper({
header:
"<!DOCTYPE html>\n<html lang=\"zxx\">\n@@include('head.html')\n@@include('header.html')\n<body>",
footer:
node_env === "dev"
? "@@include('components/tw-size-indicator.html')\n @@include('footer.html')\n</body>\n</html>"
: "@@include('footer.html')\n</body>\n</html>",
}),
)
.pipe(
fileInclude({
basepath: "src/partials/",
}),
)
.pipe(
template({
fontPrimary: theme.fonts.font_family.primary,
fontSecondary: theme.fonts.font_family.secondary,
}),
)
.pipe(comments(headerComments))
.pipe(gulp.dest(path.build.dir))
.pipe(
bs.reload({
stream: true,
}),
);
}
// scripts
function scripts() {
return gulp
.src(path.src.scripts)
.pipe(jshint("./.jshintrc"))
.pipe(jshint.reporter("jshint-stylish"))
.on("error", gUtil.log)
.pipe(comments(headerComments))
.pipe(gulp.dest(path.build.dir + "scripts/"))
.pipe(
bs.reload({
stream: true,
}),
);
}
// Plugins
function plugins() {
return gulp
.src(path.src.plugins)
.pipe(gulp.dest(path.build.dir + "plugins/"))
.pipe(
bs.reload({
stream: true,
}),
);
}
// public files
function publicFiles() {
return gulp
.src(path.src.public, { encoding: false })
.pipe(gulp.dest(path.build.dir));
}
// Clean Theme Folder
function clean(cb) {
rimraf("./theme", cb);
}
// Watch Task
function watch() {
gulp.watch(path.src.theme, gulp.parallel(styles));
gulp.watch(path.src.pages, gulp.parallel(pages, styles));
gulp.watch(path.src.partials, gulp.parallel(pages, styles));
gulp.watch(path.src.scripts, gulp.parallel(scripts, styles));
gulp.watch(path.src.styles, gulp.parallel(styles));
gulp.watch(path.src.plugins, gulp.parallel(plugins, pages));
gulp.watch(path.src.public, gulp.parallel(publicFiles, pages));
}
// dev Task
const dev = gulp.series(
clean,
pages,
styles,
scripts,
plugins,
publicFiles,
gulp.parallel(watch, () => {
bs.init({
server: {
baseDir: path.build.dir,
},
});
}),
);
// Build Task
const build = gulp.series(clean, pages, styles, scripts, plugins, publicFiles);
// Deploy Task
const deploy = gulp.series(pages, styles, scripts, plugins, publicFiles);
export {
build,
clean,
deploy,
dev,
pages,
plugins,
publicFiles,
scripts,
styles,
watch,
};
export default dev;