-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
150 lines (124 loc) · 4.24 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
// Core packages
const gulp = require("gulp"),
minimist = require("minimist"),
log = require("fancy-log"),
plumber = require("gulp-plumber"),
concat = require("gulp-concat");
// Less and CSS packages
const less = require("gulp-less"),
lessGlob = require("less-plugin-glob"),
postCSS = require("gulp-postcss"),
autoprefixer = require("autoprefixer"),
lessCleanCSS = require("less-plugin-clean-css");
// Javascript packages
const uglify = require("gulp-uglify");
// Determine if gulp has been run with --production
const isProduction = minimist(process.argv.slice(2)).production !== undefined;
// Include browsersync when gulp has not been run with --production
let browserSync = undefined;
if (!isProduction) {
browserSync = require("browser-sync").create();
}
// declare plugin settings
const lessPlugins = isProduction ? [ lessGlob, new lessCleanCSS({ advanced: true }) ] : [ lessGlob ],
autoprefixerSettings = { remove: false, cascade: false };
// javascript files for the public site
const jsPublic = [
"resources/assets/js/site-vars.js",
"resources/assets/js/builder.js",
"resources/assets/js/downloads.js",
"resources/assets/js/mirrorlist.js",
"resources/assets/js/packages.js",
"resources/assets/js/app.js"
];
// javascript libraries for the public site
const jsPublicLibs = [
"bower_components/jquery/dist/jquery.min.js",
"bower_components/bootstrap/dist/js/bootstrap.min.js",
"bower_components/formstone/dist/js/core.js",
"bower_components/formstone/dist/js/touch.js",
"bower_components/formstone/dist/js/checkbox.js",
"bower_components/formstone/dist/js/dropdown.js",
"bower_components/jQuery.stickyFooter/assets/js/jquery.stickyfooter.min.js",
"bower_components/list.js/dist/list.min.js"
];
// paths to folders containing fonts that should be copied to public/fonts/
const fontPaths = [
"resources/assets/fonts/**",
"bower_components/bootstrap/dist/fonts/**",
"bower_components/font-awesome/fonts/**"
];
// Handle errors
function handleError(err) {
log.error(err);
this.emit("end");
}
// function to handle the processing of less files
function processLess(filename) {
const css = gulp.src("resources/assets/less/" + filename + ".less")
.pipe(plumber(handleError))
.pipe(less({ plugins: lessPlugins, paths: "bower_components/" }))
.pipe(postCSS([ autoprefixer(autoprefixerSettings) ]))
.pipe(concat(filename + ".css"))
.pipe(gulp.dest("public/css/"));
if (!isProduction) {
css.pipe(browserSync.stream({ match: `**/${filename}.css` }));
}
return css;
}
// function to handle the processing of javascript files
function processJavaScript(ouputFilename, inputFiles) {
const javascript = gulp.src(inputFiles)
.pipe(plumber(handleError))
.pipe(concat(`${ouputFilename}.js`));
if (isProduction) {
javascript.pipe(uglify());
}
return javascript.pipe(gulp.dest("public/js/"));
}
// gulp task for public styles
gulp.task("less-public", () => {
return processLess("app");
});
// gulp task for public javascript
gulp.task("js-public", () => {
return processJavaScript("app", jsPublic);
});
// gulp task for public javascript libraries
gulp.task("js-public-libs", () => {
return processJavaScript("lib", jsPublicLibs);
});
// gulp task to copy fonts
gulp.task("fonts", (done) => {
gulp.src(fontPaths)
.pipe(plumber(handleError))
.pipe(gulp.dest("public/fonts/"));
done();
});
// gulp watch task
gulp.task("watch", () => {
const browserSyncReload = (done) => {
browserSync.reload();
done();
};
browserSync.init({
logLevel: "silent",
baseDir: "./public",
notify: false,
ghostMode: {
clicks: false,
forms: true,
scroll: false
}
});
gulp.watch([ "app/**/*.php", "routes/**/*.php", "resources/views/**/*.blade.php" ], gulp.series(browserSyncReload));
gulp.watch("resources/assets/js/**/*.js", gulp.series("js-public", browserSyncReload));
gulp.watch("resources/assets/less/**/*.less", gulp.parallel("less-public"));
});
// gulp default task
gulp.task("default", gulp.parallel(
"less-public",
"js-public",
"js-public-libs",
"fonts"
));