2016-06-11 13:43:57 -05:00
|
|
|
const autoprefixer = require('gulp-autoprefixer');
|
2019-07-02 13:04:15 -05:00
|
|
|
const cleancss = require("gulp-clean-css");
|
2020-01-11 10:28:54 -05:00
|
|
|
const fs = require("fs");
|
2020-01-20 07:03:01 -05:00
|
|
|
const gulp = require("gulp");
|
|
|
|
const gulpif = require("gulp-if");
|
|
|
|
const gzip = require("gulp-gzip");
|
2020-01-11 10:28:54 -05:00
|
|
|
const l = require("lodash");
|
2020-01-20 07:03:01 -05:00
|
|
|
const mustache = require("gulp-mustache");
|
|
|
|
const rename = require("gulp-rename");
|
|
|
|
const rimraf = require("rimraf");
|
|
|
|
const scss = require("gulp-sass");
|
2016-06-11 13:43:57 -05:00
|
|
|
|
|
|
|
const paths = {};
|
2016-02-21 09:42:35 -05:00
|
|
|
paths.app = "./resources/";
|
|
|
|
paths.output = "./resources/public/";
|
2020-01-20 07:03:01 -05:00
|
|
|
paths.dist = "./target/dist/";
|
2015-06-18 12:35:50 -05:00
|
|
|
paths.scss = paths.app + "styles/**/*.scss";
|
|
|
|
|
2016-06-11 13:43:57 -05:00
|
|
|
/***********************************************
|
2016-06-14 15:50:55 -05:00
|
|
|
* Helper Tasks
|
2016-06-11 13:43:57 -05:00
|
|
|
***********************************************/
|
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
gulp.task("clean", function(next) {
|
|
|
|
rimraf(paths.output + "css/", function() {
|
|
|
|
rimraf(paths.output + "js/", function() {
|
2019-08-07 13:08:11 -05:00
|
|
|
next()
|
2016-06-14 15:50:55 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-03 09:51:20 -05:00
|
|
|
gulp.task("dist:clean", function(next) {
|
|
|
|
rimraf(paths.dist, next);
|
|
|
|
});
|
|
|
|
|
2016-04-03 05:19:11 -05:00
|
|
|
function makeAutoprefixer() {
|
2020-01-20 07:03:01 -05:00
|
|
|
return autoprefixer('last 2 version');
|
2016-04-03 05:19:11 -05:00
|
|
|
}
|
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
|
|
|
|
function isProduction() {
|
|
|
|
return (process.env.NODE_ENV === 'production');
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************
|
|
|
|
* Development
|
|
|
|
***********************************************/
|
|
|
|
|
|
|
|
// Styles
|
|
|
|
|
2016-04-03 05:19:11 -05:00
|
|
|
function scssPipeline(options) {
|
2016-06-14 15:50:55 -05:00
|
|
|
return function() {
|
|
|
|
const input = options.input;
|
|
|
|
const output = options.output;
|
|
|
|
|
|
|
|
return gulp.src(input)
|
2019-07-02 13:04:15 -05:00
|
|
|
.pipe(scss({
|
|
|
|
style: "expanded",
|
|
|
|
errLogToConsole: false
|
|
|
|
}).on("error", (err) => {
|
|
|
|
console.log(err.messageFormatted);
|
|
|
|
}))
|
2016-06-14 15:50:55 -05:00
|
|
|
.pipe(makeAutoprefixer())
|
2019-07-02 13:04:15 -05:00
|
|
|
.pipe(gulpif(isProduction, cleancss()))
|
2016-06-14 15:50:55 -05:00
|
|
|
.pipe(gulp.dest(output));
|
|
|
|
};
|
2016-04-03 05:19:11 -05:00
|
|
|
}
|
2016-02-21 09:42:35 -05:00
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
gulp.task("scss:main", scssPipeline({
|
|
|
|
input: paths.app + "styles/main.scss",
|
|
|
|
output: paths.output + "css/"
|
|
|
|
}));
|
2016-02-21 09:42:35 -05:00
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
// gulp.task("scss:view", scssPipeline({
|
|
|
|
// input: paths.app + "styles/view.scss",
|
|
|
|
// output: paths.output + "css/"
|
|
|
|
// }));
|
2016-04-03 05:19:11 -05:00
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
gulp.task("scss", gulp.parallel("scss:main"));
|
2016-04-03 05:19:11 -05:00
|
|
|
|
2020-01-11 10:28:54 -05:00
|
|
|
function readLocales() {
|
|
|
|
const path = __dirname + "/resources/locales.json";
|
|
|
|
const content = JSON.parse(fs.readFileSync(path, {encoding: "utf8"}));
|
|
|
|
|
|
|
|
let result = {};
|
|
|
|
for (let key of Object.keys(content)) {
|
|
|
|
const item = content[key];
|
|
|
|
if (l.isString(item)) {
|
|
|
|
result[key] = {"en": item};
|
|
|
|
} else if (l.isPlainObject(item) && l.isPlainObject(item.translations)) {
|
|
|
|
result[key] = item.translations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return JSON.stringify(result);
|
|
|
|
}
|
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
// Templates
|
2015-06-18 12:35:50 -05:00
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
function templatePipeline(options) {
|
|
|
|
return function() {
|
|
|
|
const input = options.input;
|
|
|
|
const output = options.output;
|
|
|
|
const ts = Math.floor(new Date());
|
2020-01-11 10:28:54 -05:00
|
|
|
|
|
|
|
const locales = readLocales();
|
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
const tmpl = mustache({
|
2020-01-11 10:28:54 -05:00
|
|
|
ts: ts,
|
|
|
|
tr: JSON.stringify(locales),
|
2016-06-14 15:50:55 -05:00
|
|
|
});
|
2016-06-11 13:43:57 -05:00
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
return gulp.src(input)
|
|
|
|
.pipe(tmpl)
|
|
|
|
.pipe(rename("index.html"))
|
|
|
|
.pipe(gulp.dest(output));
|
|
|
|
};
|
|
|
|
}
|
2016-02-28 03:12:25 -05:00
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
gulp.task("template:main", templatePipeline({
|
2020-01-11 10:28:54 -05:00
|
|
|
input: paths.app + "templates/index.mustache",
|
|
|
|
output: paths.output
|
2016-06-14 15:50:55 -05:00
|
|
|
}));
|
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
// gulp.task("template:view", templatePipeline({
|
|
|
|
// input: paths.app + "templates/view.mustache",
|
|
|
|
// output: paths.output + "view/"
|
|
|
|
// }));
|
2016-06-14 15:50:55 -05:00
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
gulp.task("templates", gulp.parallel("template:main"));
|
2016-06-11 13:43:57 -05:00
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
// Entry Point
|
|
|
|
|
2019-05-31 06:50:55 -05:00
|
|
|
gulp.task("watch:main", function() {
|
|
|
|
gulp.watch(paths.scss, gulp.task("scss"));
|
2020-01-11 10:28:54 -05:00
|
|
|
gulp.watch([paths.app + "templates/*.mustache",
|
|
|
|
paths.app + "locales.json"],
|
|
|
|
gulp.task("templates"));
|
2016-06-14 15:50:55 -05:00
|
|
|
});
|
|
|
|
|
2019-05-31 06:50:55 -05:00
|
|
|
gulp.task("watch", gulp.series(
|
2020-01-11 10:28:54 -05:00
|
|
|
gulp.parallel("scss", "templates"),
|
2019-05-31 06:50:55 -05:00
|
|
|
gulp.task("watch:main")
|
|
|
|
));
|
|
|
|
|
2016-06-11 13:43:57 -05:00
|
|
|
/***********************************************
|
2016-06-14 15:50:55 -05:00
|
|
|
* Production
|
2016-06-11 13:43:57 -05:00
|
|
|
***********************************************/
|
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
gulp.task("dist:clean", function(next) {
|
|
|
|
rimraf(paths.dist, next);
|
2016-06-11 13:43:57 -05:00
|
|
|
});
|
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
// Templates
|
2016-06-11 13:43:57 -05:00
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
gulp.task("dist:template:main", templatePipeline({
|
2020-01-20 07:03:01 -05:00
|
|
|
input: paths.app + "templates/index.mustache",
|
2016-06-14 15:50:55 -05:00
|
|
|
output: paths.dist,
|
|
|
|
}));
|
2016-06-11 13:43:57 -05:00
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
// gulp.task("dist:template:view", templatePipeline({
|
|
|
|
// input: paths.app + "view.mustache",
|
|
|
|
// output: paths.dist + "view/",
|
|
|
|
// }));
|
2016-02-21 09:42:35 -05:00
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
gulp.task("dist:templates", gulp.parallel("dist:template:main"));
|
2016-02-21 13:42:01 -05:00
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
// Styles
|
2016-06-11 13:43:57 -05:00
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
gulp.task("dist:scss:main", scssPipeline({
|
|
|
|
input: paths.app + "styles/main.scss",
|
|
|
|
output: paths.dist + "css/"
|
|
|
|
}));
|
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
// gulp.task("dist:scss:view", scssPipeline({
|
|
|
|
// input: paths.app + "styles/view.scss",
|
|
|
|
// output: paths.dist + "css/"
|
|
|
|
// }));
|
2016-06-14 15:50:55 -05:00
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
gulp.task("dist:scss", gulp.parallel("dist:scss:main"));
|
2016-06-14 15:50:55 -05:00
|
|
|
|
|
|
|
// Copy
|
|
|
|
|
|
|
|
gulp.task("dist:copy:fonts", function() {
|
|
|
|
return gulp.src(paths.output + "/fonts/**/*")
|
|
|
|
.pipe(gulp.dest(paths.dist + "fonts/"));
|
2016-02-21 11:01:27 -05:00
|
|
|
});
|
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
gulp.task("dist:copy:images", function() {
|
|
|
|
return gulp.src(paths.output + "/images/**/*")
|
|
|
|
.pipe(gulp.dest(paths.dist + "images/"));
|
2016-02-21 09:42:35 -05:00
|
|
|
});
|
2015-06-18 12:35:50 -05:00
|
|
|
|
2016-06-11 13:43:57 -05:00
|
|
|
|
2019-05-31 06:50:55 -05:00
|
|
|
gulp.task("dist:copy", gulp.parallel("dist:copy:fonts", "dist:copy:images"));
|
2016-06-14 15:50:55 -05:00
|
|
|
|
2017-02-21 07:23:15 -05:00
|
|
|
// GZip
|
|
|
|
|
|
|
|
gulp.task("dist:gzip", function() {
|
|
|
|
return gulp.src(`${paths.dist}**/!(*.gz|*.br|*.jpg|*.png)`)
|
|
|
|
.pipe(gzip({gzipOptions: {level: 9}}))
|
|
|
|
.pipe(gulp.dest(paths.dist));
|
|
|
|
});
|
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
// Entry Point
|
|
|
|
|
2019-06-03 09:51:20 -05:00
|
|
|
gulp.task("dist", gulp.parallel(
|
2020-01-11 10:28:54 -05:00
|
|
|
gulp.task("dist:templates"),
|
2019-06-03 09:51:20 -05:00
|
|
|
gulp.task("dist:scss"),
|
|
|
|
gulp.task("dist:copy")
|
2019-05-31 06:50:55 -05:00
|
|
|
));
|
2015-06-18 12:35:50 -05:00
|
|
|
|