hypothetical/gulpfile.js

173 lines
5.3 KiB
JavaScript
Raw Normal View History

2016-03-30 00:51:54 -04:00
// include packages
const gulp = require("gulp"),
gUtil = require("gulp-util"),
gLess = require("gulp-less"),
gConcat = require("gulp-concat"),
gPlumber = require("gulp-plumber"),
gUglify = require("gulp-uglify"),
gModernizr = require("gulp-modernizr"),
gBabel = require("gulp-babel"),
gPostCSS = require("gulp-postcss"),
autoprefixer = require("autoprefixer"),
lessGlob = require("less-plugin-glob"),
lessCleanCSS = require("less-plugin-clean-css");
2016-03-30 00:51:54 -04:00
// determine if gulp has been run with --production
const prod = gUtil.env.production;
2016-03-30 00:51:54 -04:00
// initialize plugins
const cleancss = new lessCleanCSS({ advanced: true });
// declare plugin settings and modernizr tests
const lessPlugins = prod ? [ lessGlob, cleancss ] : [ lessGlob ],
autoprefixerSettings = { remove: false, cascade: false, browsers: [ "last 6 versions" ] },
modernizrTests = [];
2016-03-30 00:51:54 -04:00
// javascript files for the public site
const jsPublic = [
"resources/assets/js/site-vars.js",
"resources/assets/js/contact.js",
"resources/assets/js/subscription.js",
"resources/assets/js/app.js"
];
2016-03-30 00:51:54 -04:00
// javascript libraries for the public site
const jsPublicLibs = [
"bower_components/jquery/dist/jquery.js",
"bower_components/bootstrap/dist/js/bootstrap.js",
"bower_components/jQuery.stickyFooter/assets/js/jquery.stickyfooter.js"
];
2016-03-30 00:51:54 -04:00
// javascript files for the dashboard
const jsDashboard = [
"resources/assets/js/dashboard.js"
];
2016-03-30 00:51:54 -04:00
// javascript libraries for the dashboard
const jsDashboardLibs = [
"bower_components/jquery/dist/jquery.js",
"bower_components/bootstrap/dist/js/bootstrap.js",
"bower_components/Sortable/Sortable.js",
"bower_components/datetimepicker/build/jquery.datetimepicker.full.js",
"bower_components/simplemde/dist/simplemde.min.js"
];
2016-03-30 00:51:54 -04:00
// 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/**"
2016-03-30 00:51:54 -04:00
];
// function to handle gulp-plumber errors
function plumberError(err) {
console.log(err);
this.emit("end");
2016-03-30 00:51:54 -04:00
}
// function to handle the processing of less files
function processLess(filename) {
return gulp.src("resources/assets/less/" + filename + ".less")
2016-03-30 00:51:54 -04:00
.pipe(gPlumber(plumberError))
.pipe(gLess({ plugins: lessPlugins, paths: "bower_components/" }))
.pipe(gPostCSS([ autoprefixer(autoprefixerSettings) ]))
.pipe(gConcat(filename + ".css"))
.pipe(gulp.dest("public/css/"));
2016-03-30 00:51:54 -04:00
}
// function to handle the processing of javascript files
function processJavaScript(ouputFilename, inputFiles, es6) {
const javascript = gulp.src(inputFiles)
2016-03-30 00:51:54 -04:00
.pipe(gPlumber(plumberError))
.pipe(gConcat(ouputFilename + ".js"));
2016-03-30 00:51:54 -04:00
if (es6) { javascript.pipe(gBabel({ presets: [ "es2015" ] })); }
if (prod) { javascript.pipe(gUglify()); }
return javascript.pipe(gulp.dest("public/js/"));
2016-03-30 00:51:54 -04:00
}
// gulp task for public styles
gulp.task("less-public", function() {
return processLess("app");
2016-03-30 00:51:54 -04:00
});
// gulp task for dashboard styles
gulp.task("less-dashboard", function() {
return processLess("dashboard");
});
2016-03-30 00:51:54 -04:00
// gulp task for public javascript
gulp.task("js-public", function() {
return processJavaScript("app", jsPublic, true);
2016-03-30 00:51:54 -04:00
});
// gulp task for public javascript libraries
gulp.task("js-public-libs", function() {
return processJavaScript("lib", jsPublicLibs, false);
2016-03-30 00:51:54 -04:00
});
// gulp task for dashboard javascript
gulp.task("js-dashboard", function() {
return processJavaScript("dashboard", jsDashboard, true);
2016-03-30 00:51:54 -04:00
});
// gulp task for dashboard javascript libraries
gulp.task("js-dashboard-libs", function() {
return processJavaScript("lib-dashboard", jsDashboardLibs, false);
});
// gulp task for modernizr
gulp.task("modernizr", function() {
const modernizr = gulp.src([ "public/js/lib.js", "public/js/app.js", "public/css/app.css" ])
.pipe(gModernizr({
tests: modernizrTests,
excludeTests: [ "hidden" ],
crawl: false,
options: [ "setClasses", "addTest", "html5printshiv", "testProp", "fnBind" ]
}))
.pipe(gPlumber(plumberError))
.pipe(gConcat("modernizr.js"));
// minify if running gulp with --production
if (prod) { modernizr.pipe(gUglify()); }
return modernizr.pipe(gulp.dest("public/js/"));
2016-03-30 00:51:54 -04:00
});
// gulp task to copy fonts
gulp.task("fonts", function() {
2016-03-30 00:51:54 -04:00
return gulp.src(fontPaths)
.pipe(gPlumber(plumberError))
.pipe(gulp.dest("public/fonts/"));
2016-03-30 00:51:54 -04:00
});
// gulp watch task
gulp.task("watch", function() {
const gLiveReload = require("gulp-livereload");
2016-03-30 00:51:54 -04:00
const liveReloadUpdate = function(wait) {
2016-03-30 00:51:54 -04:00
setTimeout(function() {
gLiveReload.changed(".");
2016-03-30 00:51:54 -04:00
}, wait || 1);
};
gLiveReload.listen();
gulp.watch(jsPublic, [ "js-public" ]).on("change", liveReloadUpdate);
gulp.watch(jsDashboard, [ "js-dashboard" ]).on("change", liveReloadUpdate);
gulp.watch([ "app/**/*.php", "resources/views/**/*.blade.php" ]).on("change", liveReloadUpdate);
2016-03-30 00:51:54 -04:00
gulp.watch("resources/assets/less/**/*.less", [ "less-public", "less-dashboard" ]).on("change", function() {
2016-03-30 00:51:54 -04:00
liveReloadUpdate(1000);
});
});
// gulp default task
gulp.task("default", [
"less-public",
"less-dashboard",
"js-public",
"js-public-libs",
"js-dashboard",
"js-dashboard-libs",
"fonts"
2016-03-30 00:51:54 -04:00
]);