2017-11-21 23:12:31 -05:00
|
|
|
// Core packages
|
2016-06-21 13:52:52 -04:00
|
|
|
const gulp = require("gulp"),
|
2018-04-05 23:58:26 -04:00
|
|
|
minimist = require("minimist"),
|
|
|
|
log = require("fancy-log"),
|
2017-11-21 19:00:04 -05:00
|
|
|
plumber = require("gulp-plumber"),
|
2017-11-21 23:12:31 -05:00
|
|
|
concat = require("gulp-concat");
|
|
|
|
|
|
|
|
// Sass packages
|
|
|
|
const sass = require("gulp-sass"),
|
2017-11-21 19:00:04 -05:00
|
|
|
sassGlob = require("gulp-sass-glob"),
|
|
|
|
postCSS = require("gulp-postcss"),
|
2017-11-21 23:12:31 -05:00
|
|
|
autoprefixer = require("autoprefixer");
|
|
|
|
|
|
|
|
// Javascript packages
|
|
|
|
const babel = require("gulp-babel"),
|
2017-11-21 19:00:04 -05:00
|
|
|
stripDebug = require("gulp-strip-debug"),
|
|
|
|
uglify = require("gulp-uglify");
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Vue packages
|
|
|
|
const browserify = require("browserify"),
|
|
|
|
vueify = require("vueify"),
|
|
|
|
source = require("vinyl-source-stream"),
|
|
|
|
buffer = require("vinyl-buffer");
|
|
|
|
|
|
|
|
// Determine if gulp has been run with --production
|
2018-04-05 23:58:26 -04:00
|
|
|
const isProduction = minimist(process.argv.slice(2)).production !== undefined;
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2018-04-06 00:29:22 -04:00
|
|
|
// Include browsersync when gulp has not been run with --production
|
|
|
|
let browserSync = undefined;
|
|
|
|
|
|
|
|
if (!isProduction) {
|
|
|
|
browserSync = require("browser-sync").create();
|
|
|
|
}
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Declare plugin settings
|
|
|
|
const sassOutputStyle = isProduction ? "compressed" : "nested",
|
|
|
|
sassPaths = [ "bower_components", "node_modules" ],
|
|
|
|
autoprefixerSettings = { remove: false, cascade: false, browsers: [ "last 6 versions" ] },
|
|
|
|
vuePaths = [ "./bower_components", "./node_modules", "./resources/components", "./resources/assets/js" ];
|
2016-03-30 00:51:54 -04:00
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Javascript files for the public site
|
2018-04-15 21:05:42 -04:00
|
|
|
const jsPublic = [ "resources/assets/js/app.js" ];
|
2016-01-26 23:20:08 -05:00
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Javascript libraries for the public site
|
2016-06-21 13:52:52 -04:00
|
|
|
const jsPublicLibs = [
|
2018-01-09 22:21:59 -05:00
|
|
|
"node_modules/jquery/dist/jquery.js",
|
2018-01-09 22:00:45 -05:00
|
|
|
"node_modules/popper.js/dist/umd/popper.js",
|
|
|
|
"node_modules/bootstrap/dist/js/bootstrap.js",
|
2017-11-21 18:49:59 -05:00
|
|
|
"node_modules/gsap/src/uncompressed/TweenMax.js",
|
2017-11-21 18:47:31 -05:00
|
|
|
"node_modules/what-input/dist/what-input.js"
|
2015-07-08 03:34:58 -04:00
|
|
|
];
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Javascript files for the dashboard
|
2016-06-21 13:52:52 -04:00
|
|
|
const jsDashboard = [
|
2016-05-23 22:35:33 -04:00
|
|
|
"resources/assets/js/dashboard.js"
|
2015-07-08 03:34:58 -04:00
|
|
|
];
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Javascript libraries for the dashboard
|
2016-06-21 13:52:52 -04:00
|
|
|
const jsDashboardLibs = [
|
2018-04-18 22:50:22 -04:00
|
|
|
"node_modules/jquery/dist/jquery.js",
|
2018-04-18 23:00:05 -04:00
|
|
|
"node_modules/popper.js/dist/umd/popper.js",
|
2018-04-16 00:45:32 -04:00
|
|
|
"node_modules/bootstrap/dist/js/bootstrap.js",
|
2018-04-18 22:50:22 -04:00
|
|
|
"node_modules/pickadate/lib/picker.js",
|
|
|
|
"node_modules/pickadate/lib/picker.date.js",
|
2016-05-23 22:35:33 -04:00
|
|
|
"bower_components/Sortable/Sortable.js",
|
2016-12-22 00:20:44 -05:00
|
|
|
"bower_components/list.js/dist/list.js",
|
2016-05-23 22:35:33 -04:00
|
|
|
"bower_components/simplemde/dist/simplemde.min.js"
|
2015-07-08 03:34:58 -04:00
|
|
|
];
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Paths to folders containing fonts that should be copied to public/fonts/
|
2016-06-21 13:52:52 -04:00
|
|
|
const fontPaths = [
|
2018-04-15 20:45:31 -04:00
|
|
|
"resources/assets/fonts/**"
|
2016-03-30 00:51:54 -04:00
|
|
|
];
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Handle errors
|
|
|
|
function handleError(err) {
|
2018-04-05 23:58:26 -04:00
|
|
|
log.error(err);
|
2016-05-23 22:35:33 -04:00
|
|
|
this.emit("end");
|
2016-03-30 00:51:54 -04:00
|
|
|
}
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Process sass
|
2016-08-16 19:33:02 -04:00
|
|
|
function processSass(filename) {
|
2018-04-06 00:29:22 -04:00
|
|
|
const css = gulp.src("resources/assets/sass/" + filename + ".scss")
|
2017-11-21 23:12:31 -05:00
|
|
|
.pipe(plumber(handleError))
|
2017-11-21 19:00:04 -05:00
|
|
|
.pipe(sassGlob())
|
2017-11-21 23:12:31 -05:00
|
|
|
.pipe(sass({ outputStyle: sassOutputStyle, includePaths: sassPaths }))
|
2017-11-21 19:00:04 -05:00
|
|
|
.pipe(postCSS([ autoprefixer(autoprefixerSettings) ]))
|
2018-04-09 23:04:09 -04:00
|
|
|
.pipe(concat(filename + ".css"))
|
|
|
|
.pipe(gulp.dest("public/css/"));
|
2018-04-06 00:29:22 -04:00
|
|
|
|
2018-04-09 23:04:09 -04:00
|
|
|
if (!isProduction) {
|
|
|
|
css.pipe(browserSync.stream({ match: "**/" + filename + ".css" }));
|
2018-04-06 00:29:22 -04:00
|
|
|
}
|
2018-04-09 23:04:09 -04:00
|
|
|
|
|
|
|
return css;
|
2016-03-30 00:51:54 -04:00
|
|
|
}
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Process vue
|
|
|
|
function processVue(ouputFilename, inputFile) {
|
|
|
|
const javascript = browserify({
|
|
|
|
entries: [ inputFile ],
|
|
|
|
paths: vuePaths
|
|
|
|
}).transform("babelify")
|
|
|
|
.transform(vueify)
|
|
|
|
.bundle()
|
|
|
|
.on("error", handleError)
|
|
|
|
.pipe(source(ouputFilename + ".js"))
|
|
|
|
.pipe(buffer());
|
|
|
|
|
2018-04-09 23:04:09 -04:00
|
|
|
if (isProduction) {
|
|
|
|
javascript.pipe(stripDebug()).pipe(uglify().on("error", handleError));
|
|
|
|
}
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
return javascript.pipe(gulp.dest("public/js/"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process javascript
|
2016-06-21 13:52:52 -04:00
|
|
|
function processJavaScript(ouputFilename, inputFiles, es6) {
|
|
|
|
const javascript = gulp.src(inputFiles)
|
2017-11-21 23:12:31 -05:00
|
|
|
.pipe(plumber(handleError))
|
2017-11-21 19:00:04 -05:00
|
|
|
.pipe(concat(ouputFilename + ".js"));
|
2016-03-30 00:51:54 -04:00
|
|
|
|
2018-04-09 23:04:09 -04:00
|
|
|
if (es6) {
|
|
|
|
javascript.pipe(babel());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isProduction) {
|
|
|
|
javascript.pipe(stripDebug()).pipe(uglify());
|
|
|
|
}
|
|
|
|
|
2016-05-23 22:35:33 -04:00
|
|
|
return javascript.pipe(gulp.dest("public/js/"));
|
2016-03-30 00:51:54 -04:00
|
|
|
}
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Task for public styles
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.task("sass-public", () => {
|
2016-08-16 19:33:02 -04:00
|
|
|
return processSass("app");
|
2016-03-30 00:51:54 -04:00
|
|
|
});
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Task for dashboard styles
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.task("sass-dashboard", () => {
|
2016-08-16 19:33:02 -04:00
|
|
|
return processSass("dashboard");
|
2015-07-08 03:34:58 -04:00
|
|
|
});
|
2016-03-30 00:51:54 -04:00
|
|
|
|
2018-04-15 21:54:43 -04:00
|
|
|
// Task for error page styles
|
|
|
|
gulp.task("sass-error", () => {
|
|
|
|
return processSass("error");
|
|
|
|
});
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Task for public javascript
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.task("js-public", () => {
|
2018-04-15 21:05:42 -04:00
|
|
|
return processVue("app", jsPublic);
|
2016-03-30 00:51:54 -04:00
|
|
|
});
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Task for public javascript libraries
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.task("js-public-libs", () => {
|
2016-06-21 13:52:52 -04:00
|
|
|
return processJavaScript("lib", jsPublicLibs, false);
|
2016-03-30 00:51:54 -04:00
|
|
|
});
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Task for dashboard javascript
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.task("js-dashboard", () => {
|
2016-06-21 13:52:52 -04:00
|
|
|
return processJavaScript("dashboard", jsDashboard, true);
|
2016-03-30 00:51:54 -04:00
|
|
|
});
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Task for dashboard javascript libraries
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.task("js-dashboard-libs", () => {
|
2016-06-21 13:52:52 -04:00
|
|
|
return processJavaScript("lib-dashboard", jsDashboardLibs, false);
|
2016-05-23 22:35:33 -04:00
|
|
|
});
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Task to copy fonts
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.task("fonts", (done) => {
|
|
|
|
gulp.src(fontPaths)
|
2017-11-21 23:12:31 -05:00
|
|
|
.pipe(plumber(handleError))
|
2016-08-16 19:47:29 -04:00
|
|
|
.pipe(gulp.dest("public/fonts/"));
|
|
|
|
|
2018-04-06 00:29:22 -04:00
|
|
|
done();
|
2018-04-09 23:04:09 -04:00
|
|
|
});
|
2016-03-30 00:51:54 -04:00
|
|
|
|
2018-04-09 23:04:09 -04:00
|
|
|
// Task to watch files and run respective tasks when changes occur
|
|
|
|
gulp.task("watch", () => {
|
|
|
|
const browserSyncReload = (done) => {
|
|
|
|
browserSync.reload();
|
|
|
|
done();
|
|
|
|
};
|
2016-03-30 00:51:54 -04:00
|
|
|
|
2018-04-06 00:29:22 -04:00
|
|
|
browserSync.init({
|
|
|
|
logLevel: "silent",
|
2018-04-09 16:33:50 -04:00
|
|
|
baseDir: "./public",
|
2018-04-09 23:04:09 -04:00
|
|
|
notify: false,
|
2018-04-09 16:33:50 -04:00
|
|
|
|
|
|
|
ghostMode: {
|
|
|
|
clicks: true,
|
|
|
|
forms: true,
|
|
|
|
scroll: false
|
|
|
|
}
|
2017-11-21 23:12:31 -05:00
|
|
|
});
|
|
|
|
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.watch([ "app/**/*.php", "routes/**/*.php", "resources/views/**/*.blade.php" ], gulp.series(browserSyncReload));
|
2018-04-15 21:05:42 -04:00
|
|
|
gulp.watch([ jsPublic, "resources/assets/js/mixins/**/*.js", "resources/components/**/*.vue" ], gulp.series("js-public", browserSyncReload));
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.watch(jsDashboard, gulp.series("js-dashboard", browserSyncReload));
|
2018-04-15 21:54:43 -04:00
|
|
|
gulp.watch("resources/assets/sass/**/*.scss", gulp.parallel("sass-public", "sass-dashboard", "sass-error"));
|
2016-03-30 00:51:54 -04:00
|
|
|
});
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Task to run non-development tasks
|
2018-04-09 23:04:09 -04:00
|
|
|
gulp.task("default", gulp.parallel(
|
2016-08-16 19:33:02 -04:00
|
|
|
"sass-public",
|
|
|
|
"sass-dashboard",
|
2018-04-15 21:54:43 -04:00
|
|
|
"sass-error",
|
2016-05-23 22:35:33 -04:00
|
|
|
"js-public",
|
|
|
|
"js-public-libs",
|
|
|
|
"js-dashboard",
|
|
|
|
"js-dashboard-libs",
|
|
|
|
"fonts"
|
2018-04-09 23:04:09 -04:00
|
|
|
));
|