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"),
|
2019-09-28 01:50:06 -04:00
|
|
|
insert = require("gulp-insert"),
|
2017-11-21 19:00:04 -05:00
|
|
|
plumber = require("gulp-plumber"),
|
2017-11-21 23:12:31 -05:00
|
|
|
concat = require("gulp-concat");
|
|
|
|
|
2018-05-02 14:30:29 -04:00
|
|
|
// Sass and CSS packages
|
2017-11-21 23:12:31 -05:00
|
|
|
const sass = require("gulp-sass"),
|
2017-11-21 19:00:04 -05:00
|
|
|
sassGlob = require("gulp-sass-glob"),
|
|
|
|
postCSS = require("gulp-postcss"),
|
2018-05-02 14:30:29 -04:00
|
|
|
autoprefixer = require("autoprefixer"),
|
|
|
|
cleanCSS = require("gulp-clean-css");
|
2018-05-02 14:25:40 -04:00
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// 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"),
|
2019-01-10 14:45:54 -05:00
|
|
|
vueify = require("vueify-next"),
|
2017-11-21 23:12:31 -05:00
|
|
|
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
|
2018-05-08 17:17:25 -04:00
|
|
|
const sassOutputStyle = isProduction ? "compressed" : "expanded",
|
2017-11-21 23:12:31 -05:00
|
|
|
sassPaths = [ "bower_components", "node_modules" ],
|
2019-08-28 14:21:03 -04:00
|
|
|
autoprefixerSettings = { remove: false, cascade: false },
|
2019-11-14 21:14:53 -05:00
|
|
|
vuePaths = [ "./bower_components", "./node_modules", "./resources/components", "./resources/js" ];
|
2016-03-30 00:51:54 -04:00
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Javascript files for the public site
|
2019-11-14 21:14:53 -05:00
|
|
|
const jsPublic = "resources/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",
|
2019-11-15 14:46:44 -05:00
|
|
|
"node_modules/gsap/dist/gsap.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 = [
|
2019-11-14 21:14:53 -05:00
|
|
|
"resources/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",
|
2019-07-17 01:11:09 -04:00
|
|
|
"node_modules/flatpickr/dist/flatpickr.js",
|
2019-10-14 21:32:11 -04:00
|
|
|
"node_modules/sortablejs/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
|
|
|
];
|
|
|
|
|
2018-05-02 14:25:40 -04:00
|
|
|
// CSS libraries for the dashboard
|
2018-05-24 22:57:42 -04:00
|
|
|
const cssDashboardLibs = [
|
2019-07-17 01:11:09 -04:00
|
|
|
"node_modules/flatpickr/dist/flatpickr.css",
|
2018-05-02 14:25:40 -04:00
|
|
|
"bower_components/simplemde/dist/simplemde.min.css",
|
|
|
|
"bower_components/SpinKit/css/spinners/11-folding-cube.css"
|
|
|
|
];
|
|
|
|
|
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 = [
|
2019-11-14 21:14:53 -05:00
|
|
|
"resources/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) {
|
2019-11-14 21:14:53 -05:00
|
|
|
const css = gulp.src(`resources/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-23 23:08:50 -04:00
|
|
|
.pipe(concat(`${filename}.css`))
|
2018-04-09 23:04:09 -04:00
|
|
|
.pipe(gulp.dest("public/css/"));
|
2018-04-06 00:29:22 -04:00
|
|
|
|
2018-04-09 23:04:09 -04:00
|
|
|
if (!isProduction) {
|
2018-04-23 23:08:50 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-02 14:25:40 -04:00
|
|
|
// Process css
|
2019-09-20 15:10:25 -04:00
|
|
|
function processCSS(outputFilename, inputFiles) {
|
2018-05-02 14:25:40 -04:00
|
|
|
const css = gulp.src(inputFiles)
|
|
|
|
.pipe(plumber(handleError))
|
|
|
|
.pipe(postCSS([ autoprefixer(autoprefixerSettings) ]))
|
2019-09-20 15:10:25 -04:00
|
|
|
.pipe(concat(`${outputFilename}.css`));
|
2018-05-02 14:25:40 -04:00
|
|
|
|
|
|
|
if (isProduction) {
|
|
|
|
css.pipe(cleanCSS());
|
|
|
|
}
|
|
|
|
|
|
|
|
return css.pipe(gulp.dest("public/css/"));
|
|
|
|
}
|
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Process vue
|
2019-09-20 15:10:25 -04:00
|
|
|
function processVue(outputFilename, inputFile) {
|
2019-09-28 01:50:06 -04:00
|
|
|
const processedDir = "storage/app/",
|
|
|
|
processedFile = `__${outputFilename}.js`;
|
2017-11-21 23:12:31 -05:00
|
|
|
|
2019-09-28 01:50:06 -04:00
|
|
|
const preProcess = () => {
|
|
|
|
const javascript = gulp.src([ inputFile ]);
|
2018-04-09 23:04:09 -04:00
|
|
|
|
2019-09-28 01:50:06 -04:00
|
|
|
if (isProduction) {
|
|
|
|
javascript.pipe(insert.transform(function(contents) {
|
|
|
|
return contents.replace(/vue\.js/, "vue.min.js");
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return javascript.pipe(concat(processedFile))
|
|
|
|
.pipe(gulp.dest(processedDir));
|
|
|
|
};
|
|
|
|
|
|
|
|
const process = () => {
|
|
|
|
const javascript = browserify({
|
|
|
|
entries: [ processedDir + processedFile ],
|
|
|
|
paths: vuePaths
|
|
|
|
}).transform("babelify")
|
|
|
|
.transform(vueify)
|
|
|
|
.bundle()
|
|
|
|
.on("error", handleError)
|
|
|
|
.pipe(source(`${outputFilename}.js`))
|
|
|
|
.pipe(buffer());
|
|
|
|
|
|
|
|
if (isProduction) {
|
|
|
|
javascript.pipe(stripDebug()).pipe(uglify().on("error", handleError));
|
|
|
|
}
|
|
|
|
|
|
|
|
return javascript.pipe(gulp.dest("public/js/"));
|
|
|
|
};
|
|
|
|
|
|
|
|
preProcess();
|
|
|
|
return process();
|
2017-11-21 23:12:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process javascript
|
2019-09-20 15:10:25 -04:00
|
|
|
function processJavaScript(outputFilename, inputFiles, es6) {
|
2016-06-21 13:52:52 -04:00
|
|
|
const javascript = gulp.src(inputFiles)
|
2017-11-21 23:12:31 -05:00
|
|
|
.pipe(plumber(handleError))
|
2019-09-20 15:10:25 -04:00
|
|
|
.pipe(concat(`${outputFilename}.js`));
|
2016-03-30 00:51:54 -04:00
|
|
|
|
2018-04-09 23:04:09 -04:00
|
|
|
if (es6) {
|
2019-01-14 14:28:02 -05:00
|
|
|
if (isProduction) {
|
|
|
|
javascript.pipe(babel()).pipe(stripDebug()).pipe(uglify());
|
|
|
|
} else {
|
|
|
|
javascript.pipe(babel());
|
|
|
|
}
|
|
|
|
} else if (isProduction) {
|
2018-04-09 23:04:09 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-02 14:25:40 -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 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-05-02 14:25:40 -04:00
|
|
|
// Task for dashboard css libraries
|
|
|
|
gulp.task("css-dashboard-libs", () => {
|
2018-05-24 22:57:42 -04:00
|
|
|
return processCSS("lib-dashboard", cssDashboardLibs);
|
2018-04-15 21:54:43 -04:00
|
|
|
});
|
|
|
|
|
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: {
|
2018-06-18 16:31:28 -04:00
|
|
|
clicks: false,
|
2018-04-09 16:33:50 -04:00
|
|
|
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));
|
2019-11-14 21:14:53 -05:00
|
|
|
gulp.watch([ "resources/js/**/app.js", "resources/js/mixins/**/*.js", "resources/components/**/*.vue" ], gulp.series("js-public", browserSyncReload));
|
|
|
|
gulp.watch("resources/js/**/dashboard.js", gulp.series("js-dashboard", browserSyncReload));
|
|
|
|
gulp.watch("resources/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(
|
2018-05-02 14:25:40 -04:00
|
|
|
"sass-error",
|
2016-08-16 19:33:02 -04:00
|
|
|
"sass-public",
|
|
|
|
"sass-dashboard",
|
2018-05-02 14:25:40 -04:00
|
|
|
"css-dashboard-libs",
|
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
|
|
|
));
|