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"),
|
2020-04-24 22:09:23 -04:00
|
|
|
concat = require("gulp-concat"),
|
|
|
|
fs = require("fs"),
|
|
|
|
crypto = require("crypto");
|
2017-11-21 23:12:31 -05:00
|
|
|
|
2018-05-02 14:30:29 -04:00
|
|
|
// Sass and CSS packages
|
2021-05-06 13:01:52 -04:00
|
|
|
const { sass } = require("@mr-hope/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"),
|
2020-12-07 00:06:20 -05:00
|
|
|
uglify = require("gulp-uglify-es").default;
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2017-11-21 23:12:31 -05:00
|
|
|
// Vue packages
|
2022-06-13 18:04:19 -04:00
|
|
|
const webpack = require("webpack"),
|
|
|
|
terserWebpackPlugin = require("terser-webpack-plugin"),
|
|
|
|
{ VueLoaderPlugin } = require("vue-loader"),
|
|
|
|
path = require("path");
|
2017-11-21 23:12:31 -05:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2022-06-13 18:04:19 -04:00
|
|
|
if (isProduction) {
|
|
|
|
process.env.NODE_ENV = "production";
|
|
|
|
} else {
|
2018-04-06 00:29:22 -04:00
|
|
|
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",
|
2020-01-17 00:43:25 -05:00
|
|
|
sassPaths = [ "node_modules" ],
|
2022-06-13 18:04:19 -04:00
|
|
|
autoprefixerSettings = { remove: false, cascade: false };
|
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",
|
2021-04-20 21:24:42 -04:00
|
|
|
"node_modules/sortablejs/Sortable.js",
|
2020-01-17 00:43:25 -05:00
|
|
|
"node_modules/list.js/dist/list.js",
|
2020-04-24 00:22:42 -04:00
|
|
|
"node_modules/easymde/dist/easymde.min.js",
|
|
|
|
"node_modules/autonumeric/dist/autoNumeric.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",
|
2020-02-25 17:43:02 -05:00
|
|
|
"node_modules/easymde/dist/easymde.min.css",
|
2020-02-25 18:08:27 -05:00
|
|
|
"node_modules/spinkit/spinkit.css"
|
2018-05-02 14:25:40 -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 = [
|
2020-02-25 17:43:02 -05:00
|
|
|
"resources/fonts/**",
|
|
|
|
"node_modules/@fortawesome/fontawesome-free/webfonts/**"
|
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
|
2022-06-13 18:04:19 -04:00
|
|
|
function processVue(outputFilename, inputFile, done) {
|
|
|
|
webpack({
|
|
|
|
mode: isProduction ? "production" : "development",
|
|
|
|
entry: [ `./${inputFile}` ],
|
|
|
|
output: { path: path.resolve(__dirname, "public/js"), filename: `${outputFilename}.js` },
|
|
|
|
devtool: false,
|
|
|
|
|
|
|
|
performance: {
|
|
|
|
maxEntrypointSize: 500000,
|
|
|
|
maxAssetSize: 500000
|
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
vue$: "vue/dist/vue.esm-bundler.js",
|
|
|
|
vuex$: "vuex/dist/vuex.esm-bundler.js",
|
|
|
|
pages: path.resolve(__dirname, "resources/components/pages"),
|
|
|
|
sections: path.resolve(__dirname, "resources/components/sections"),
|
|
|
|
partials: path.resolve(__dirname, "resources/components/partials"),
|
|
|
|
mixins: path.resolve(__dirname, "resources/js/mixins"),
|
|
|
|
imports: path.resolve(__dirname, "resources/js/imports")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loader: "vue-loader",
|
|
|
|
options: { presets: [ [ "@babel/preset-env" ] ] }
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: "babel-loader",
|
|
|
|
options: { presets: [ [ "@babel/preset-env" ] ] }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({ __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false }),
|
|
|
|
new VueLoaderPlugin()
|
|
|
|
],
|
|
|
|
|
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new terserWebpackPlugin({
|
|
|
|
extractComments: false,
|
|
|
|
|
|
|
|
terserOptions: {
|
|
|
|
format: { comments: false },
|
|
|
|
compress: { drop_console: isProduction }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
2019-09-28 01:50:06 -04:00
|
|
|
}
|
2022-06-13 18:04:19 -04:00
|
|
|
}, (err, stats) => {
|
|
|
|
let statsJson;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
log.error(err.stack || err);
|
|
|
|
|
|
|
|
if (err.details) {
|
|
|
|
log.error(err.details);
|
|
|
|
}
|
|
|
|
} else if (stats.hasWarnings() || stats.hasErrors()) {
|
|
|
|
statsString = stats.toString("errors-only", {
|
|
|
|
colors: true,
|
|
|
|
modules: false,
|
|
|
|
children: false,
|
|
|
|
chunks: false,
|
|
|
|
chunkModules: false
|
|
|
|
});
|
|
|
|
|
|
|
|
log.error(statsString);
|
2019-09-28 01:50:06 -04:00
|
|
|
}
|
|
|
|
|
2022-06-13 18:04:19 -04:00
|
|
|
done();
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
2020-04-24 22:09:23 -04:00
|
|
|
// Update the version string
|
|
|
|
function updateVersion() {
|
|
|
|
crypto.randomBytes(16, (err, buf) => {
|
|
|
|
if (err) { throw err; }
|
|
|
|
|
|
|
|
return fs.writeFile("storage/app/__version.txt", buf.toString("hex"), (err) => {
|
|
|
|
if (err) { throw err; }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
2022-06-13 18:04:19 -04:00
|
|
|
gulp.task("js-public", (done) => {
|
|
|
|
return processVue("app", jsPublic, done);
|
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
|
|
|
|
2020-04-24 22:09:23 -04:00
|
|
|
// Task to update the cache-bust version
|
|
|
|
gulp.task("version", (done) => {
|
|
|
|
updateVersion();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
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) => {
|
2020-04-24 22:09:23 -04:00
|
|
|
updateVersion();
|
2018-04-09 23:04:09 -04:00
|
|
|
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));
|
2021-07-29 16:40:55 -04:00
|
|
|
gulp.watch([ "resources/js/**/app.js", "resources/js/mixins/**/*.js", "resources/js/imports/**/*.js", "resources/components/**/*.vue" ], gulp.series("js-public", browserSyncReload));
|
2019-11-14 21:14:53 -05:00
|
|
|
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",
|
2020-04-24 22:09:23 -04:00
|
|
|
"fonts",
|
|
|
|
"version"
|
2018-04-09 23:04:09 -04:00
|
|
|
));
|