forked from UNIC-IFF/KNOB-BBF-Web-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
262 lines (215 loc) · 6.29 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import gulp from "gulp";
import path from 'path';
import util from "gulp-util";
import gulpSass from "gulp-sass";
import concat from "gulp-concat";
import imagemin from "gulp-imagemin";
import sourcemaps from "gulp-sourcemaps";
import autoprefixer from "gulp-autoprefixer";
import sassCompiler from "sass";
import panini from "panini";
import del from "del";
import browserify from "browserify";
import babelify from "babelify";
import source from "vinyl-source-stream";
import logSymbols from "log-symbols";
import BrowserSync from "browser-sync";
import options from "./config.js";
import {fileURLToPath} from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const { src, dest, watch, series, parallel } = gulp;
const browserSync = BrowserSync.create();
var reload = browserSync.reload;
const nodepath = __dirname+"/node_modules/";
const sass = gulpSass(sassCompiler);
function livePreview(done) {
browserSync.init(
{
server: {
baseDir: options.paths.dist.base,
},
port: 5000,
});
done();
}
//Copy latest installed Bulma
function setupBulma() {
console.log("\n\t" + logSymbols.info, "Installing Bulma Files..\n");
return src([nodepath + "bulma/*.sass", nodepath + "bulma/**/*.sass"]).pipe(
dest("static/sass/")
);
}
//Triggers Browser reload
function previewReload(done) {
console.log(logSymbols.info, "Reloading Browser Preview.");
browserSync.reload();
done();
}
// Let's write our task in a function to keep things clean
function javascriptBuild() {
// Start by calling browserify with our entry pointing to our main javascript file
return (
browserify({
entries: [`${options.paths.src.js}/main.js`],
// Pass babelify as a transform and set its preset to @babel/preset-env
transform: [babelify.configure({ presets: ["@babel/preset-env"] })],
})
// Bundle it all up!
.bundle()
// Source the bundle
.pipe(source("bundle.js"))
// Then write the resulting files to a folder
.pipe(dest(`static/dist/js`))
);
}
//Compile HTML partials with Panini
function compileHTML() {
console.log(logSymbols.info, "Compiling HTML..");
panini.refresh();
return src(__dirname+"/templates/**/*.html")
.pipe(
panini({
root: "templates",
layouts: "/static/layouts/",
partials: "/static/partials/",
})
)
.pipe(dest(__dirname+"/static/dist/"))
.pipe(browserSync.stream());
}
function copyFonts() {
console.log(logSymbols.info, "Copying fonts to dist folder.");
return src(["static/fonts/*"])
.pipe(dest("static/dist/fonts/"))
.pipe(browserSync.stream());
}
function devClean() {
console.log(logSymbols.info, "Cleaning dist folder for fresh start.");
return del([options.paths.dist.base]);
}
//Compile Scss code
function compileSCSS() {
console.log(logSymbols.info, "Compiling App SCSS..");
return src(["static/scss/main.scss"])
.pipe(
sass({
outputStyle: "compressed",
sourceComments: "map",
sourceMap: "scss",
// includePaths: bourbon,
}).on("error", sass.logError)
)
.pipe(autoprefixer("last 2 versions"))
.pipe(dest("static/dist/css"))
.pipe(browserSync.stream());
}
//Concat JS
function concatJs() {
console.log(logSymbols.info, "Compiling Vendor Js..");
return src(["static/js/*"])
.pipe(sourcemaps.init())
.pipe(concat("app.js"))
.pipe(sourcemaps.write("./"))
.pipe(dest("static/dist/js"))
.pipe(browserSync.stream());
}
//Concat CSS Plugins
function concatCssPlugins() {
console.log(logSymbols.info, "Compiling Plugin styles..");
return src([
nodepath + "simplebar/dist/simplebar.min.css",
nodepath + "plyr/dist/plyr.css",
nodepath + "codemirror/lib/codemirror.css",
nodepath + "codemirror/theme/shadowfox.css",
"static/vendor/css/*",
])
.pipe(sourcemaps.init())
.pipe(concat("app.css"))
.pipe(sourcemaps.write("./"))
.pipe(dest("static/dist/css"))
.pipe(browserSync.stream());
}
//Reset Panini Cache
function resetPages(done) {
console.log(logSymbols.info, "Clearing Panini Cache..");
panini.refresh();
done();
}
/*
//Triggers Browser reload
function previewReload(done) {
console.log(logSymbols.info, "Reloading Browser Preview.");
browserSync.init(
[paths.src.css + "/*.css", paths.src.js + "*.js", paths.templates + '*.html'],
{
proxy: "localhost:5000"
}
).reload();
done();
}
*/
//Copy images
function copyImages() {
return src(`${options.paths.src.img}/**/*`).pipe(
dest(options.paths.dist.img)
);
}
//Optimize images
function optimizeImages() {
return src(`${options.paths.src.img}/**/*`)
.pipe(imagemin())
.pipe(dest(options.paths.dist.img));
}
function watchFiles() {
watch(
`${options.paths.src.base}/**/*.html`,
series( previewReload)
).on("change", reload);
watch(["static/scss/**/*", "static/scss/*"], compileSCSS);
watch(
`${options.paths.src.js}/**/*.js`,
series(javascriptBuild, previewReload)
).on("change", reload);
watch(
`${options.paths.src.fonts}/**/*`,
series(copyFonts, previewReload)
).on("change", reload);
watch(`${options.paths.src.img}/**/*`, series(copyImages, previewReload)).on("change", reload);
console.log(logSymbols.info, "Watching for Changes..");
}
/*
// Build all files and watches for changes
gulp.task('build:watch', ['build', 'watch']);
// Build all files, run the server, start BrowserSync and watch for file changes
gulp.task('default', function () {
runSequence('build', 'runServer', 'browserSync', 'watch');
});
*/
const buildTasks = [
devClean,
resetPages,
parallel(
concatJs,
copyFonts,
concatCssPlugins,
compileSCSS,
javascriptBuild,
),
];
export const build = (done) => {
series( devClean,resetPages, parallel(...buildTasks, optimizeImages))();
done();
};
export default (done) => {
series(
devClean,
resetPages,
parallel(...buildTasks, copyImages),
parallel(livePreview,watchFiles),
)();
done();
};
export const setup = () => {
series(setupBulma);
};