2020-01-11 10:28:54 -05:00
|
|
|
const fs = require("fs");
|
2020-02-25 10:18:55 -05:00
|
|
|
const l = require("lodash");
|
2020-11-20 18:14:59 -05:00
|
|
|
const path = require("path");
|
2020-02-25 10:18:55 -05:00
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
const gulp = require("gulp");
|
2020-11-20 18:14:59 -05:00
|
|
|
const gulpConcat = require("gulp-concat");
|
2020-11-12 07:35:20 -05:00
|
|
|
const gulpGzip = require("gulp-gzip");
|
|
|
|
const gulpMustache = require("gulp-mustache");
|
2020-11-20 18:14:59 -05:00
|
|
|
const gulpPostcss = require("gulp-postcss");
|
2020-11-12 07:35:20 -05:00
|
|
|
const gulpRename = require("gulp-rename");
|
2021-07-13 06:24:42 -05:00
|
|
|
const gulpSass = require("gulp-sass")(require("sass"));
|
2020-02-25 10:18:55 -05:00
|
|
|
const svgSprite = require("gulp-svg-sprite");
|
|
|
|
|
2020-11-20 18:14:59 -05:00
|
|
|
const autoprefixer = require("autoprefixer")
|
|
|
|
const clean = require("postcss-clean");
|
2020-02-25 10:18:55 -05:00
|
|
|
const mkdirp = require("mkdirp");
|
2020-01-20 07:03:01 -05:00
|
|
|
const rimraf = require("rimraf");
|
2020-02-25 10:18:55 -05:00
|
|
|
const sass = require("sass");
|
2021-04-12 02:29:09 -05:00
|
|
|
const gettext = require("gettext-parser");
|
2021-04-29 06:04:19 -05:00
|
|
|
const marked = require("marked");
|
2016-06-11 13:43:57 -05:00
|
|
|
|
2020-06-02 09:14:23 -05:00
|
|
|
const mapStream = require("map-stream");
|
2016-06-11 13:43:57 -05:00
|
|
|
const paths = {};
|
2020-02-25 10:18:55 -05:00
|
|
|
paths.resources = "./resources/";
|
2016-02-21 09:42:35 -05:00
|
|
|
paths.output = "./resources/public/";
|
2020-01-20 07:03:01 -05:00
|
|
|
paths.dist = "./target/dist/";
|
2020-11-12 07:35:20 -05:00
|
|
|
|
2015-06-18 12:35:50 -05:00
|
|
|
|
2016-06-11 13:43:57 -05:00
|
|
|
/***********************************************
|
2020-02-25 10:18:55 -05:00
|
|
|
* Helpers
|
2016-06-11 13:43:57 -05:00
|
|
|
***********************************************/
|
|
|
|
|
2020-02-25 10:18:55 -05:00
|
|
|
// Templates
|
2016-04-03 05:19:11 -05:00
|
|
|
|
2020-01-11 10:28:54 -05:00
|
|
|
function readLocales() {
|
2021-10-27 04:22:24 -05:00
|
|
|
const langs = ["ar", "he", "ca", "de", "el", "en", "es", "fr", "tr", "ru", "zh_CN", "pt_BR", "ro"];
|
2021-04-12 02:29:09 -05:00
|
|
|
const result = {};
|
|
|
|
|
|
|
|
for (let lang of langs) {
|
2021-04-23 05:57:33 -05:00
|
|
|
const content = fs.readFileSync(`./translations/${lang}.po`, {encoding:"utf-8"});
|
2021-04-12 02:29:09 -05:00
|
|
|
|
|
|
|
lang = lang.toLowerCase();
|
|
|
|
|
|
|
|
const data = gettext.po.parse(content, "utf-8");
|
|
|
|
const trdata = data.translations[""];
|
|
|
|
|
|
|
|
for (let key of Object.keys(trdata)) {
|
|
|
|
if (key === "") continue;
|
2021-04-29 06:04:19 -05:00
|
|
|
const comments = trdata[key].comments || {};
|
2021-04-12 02:29:09 -05:00
|
|
|
|
|
|
|
if (l.isNil(result[key])) {
|
|
|
|
result[key] = {};
|
|
|
|
}
|
|
|
|
|
2021-04-29 06:04:19 -05:00
|
|
|
const isMarkdown = l.includes(comments.flag, "markdown");
|
|
|
|
|
|
|
|
const msgs = trdata[key].msgstr;
|
|
|
|
if (msgs.length === 1) {
|
|
|
|
let message = msgs[0];
|
|
|
|
if (isMarkdown) {
|
|
|
|
message = marked.parseInline(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
result[key][lang] = message;
|
2021-04-12 02:29:09 -05:00
|
|
|
} else {
|
2021-04-29 06:04:19 -05:00
|
|
|
result[key][lang] = msgs.map((item) => {
|
|
|
|
if (isMarkdown) {
|
|
|
|
return marked.parseInline(item);
|
|
|
|
} else {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
});
|
2021-04-12 02:29:09 -05:00
|
|
|
}
|
2021-04-29 06:04:19 -05:00
|
|
|
// if (key === "modals.delete-font.title") {
|
|
|
|
// console.dir(trdata[key], {depth:10});
|
|
|
|
// console.dir(result[key], {depth:10});
|
|
|
|
// }
|
2020-01-11 10:28:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return JSON.stringify(result);
|
|
|
|
}
|
|
|
|
|
2020-08-18 09:33:12 -05:00
|
|
|
function readManifest() {
|
2020-06-02 09:14:23 -05:00
|
|
|
try {
|
|
|
|
const path = __dirname + "/resources/public/js/manifest.json";
|
|
|
|
const content = JSON.parse(fs.readFileSync(path, {encoding: "utf8"}));
|
|
|
|
|
2020-08-18 09:33:12 -05:00
|
|
|
const index = {
|
2021-04-19 11:35:36 -05:00
|
|
|
"config": "js/config.js?ts=" + Date.now(),
|
2020-11-20 18:14:59 -05:00
|
|
|
"polyfills": "js/polyfills.js?ts=" + Date.now(),
|
2020-08-18 09:33:12 -05:00
|
|
|
};
|
|
|
|
|
2020-06-02 09:14:23 -05:00
|
|
|
for (let item of content) {
|
2021-04-19 11:35:36 -05:00
|
|
|
index[item.name] = "js/" + item["output-name"];
|
2020-06-02 09:14:23 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
return index;
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Error on reading manifest, using default.");
|
2020-06-08 12:07:13 -05:00
|
|
|
return {
|
2021-04-19 11:35:36 -05:00
|
|
|
"config": "js/config.js",
|
2020-11-20 18:14:59 -05:00
|
|
|
"polyfills": "js/polyfills.js",
|
2021-04-19 11:35:36 -05:00
|
|
|
"main": "js/main.js",
|
|
|
|
"shared": "js/shared.js",
|
|
|
|
"worker": "js/worker.js"
|
2020-06-08 12:07:13 -05:00
|
|
|
};
|
2020-06-02 09:14:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function touch() {
|
|
|
|
return mapStream(function(file, cb) {
|
|
|
|
if (file.isNull()) {
|
|
|
|
return cb(null, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update file modification and access time
|
|
|
|
return fs.utimes(file.path, new Date(), new Date(), () => {
|
|
|
|
cb(null, file)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-14 15:50:55 -05:00
|
|
|
function templatePipeline(options) {
|
|
|
|
return function() {
|
|
|
|
const input = options.input;
|
|
|
|
const output = options.output;
|
2020-04-13 05:03:56 -05:00
|
|
|
|
2020-08-18 10:16:23 -05:00
|
|
|
const ts = Math.floor(new Date());
|
2020-08-18 12:26:37 -05:00
|
|
|
const th = process.env.APP_THEME || "default";
|
2020-04-13 05:03:56 -05:00
|
|
|
const themes = ["default"];
|
2020-08-18 10:16:23 -05:00
|
|
|
|
2020-01-11 10:28:54 -05:00
|
|
|
const locales = readLocales();
|
2020-08-18 09:33:12 -05:00
|
|
|
const manifest = readManifest();
|
2020-06-08 12:07:13 -05:00
|
|
|
|
2020-11-12 07:35:20 -05:00
|
|
|
const tmpl = gulpMustache({
|
2020-01-11 10:28:54 -05:00
|
|
|
ts: ts,
|
2020-04-08 03:57:29 -05:00
|
|
|
th: th,
|
2020-06-02 09:14:23 -05:00
|
|
|
manifest: manifest,
|
2020-03-11 03:20:12 -05:00
|
|
|
translations: JSON.stringify(locales),
|
2020-04-08 03:57:29 -05:00
|
|
|
themes: JSON.stringify(themes),
|
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)
|
2020-11-12 07:35:20 -05:00
|
|
|
.pipe(gulpRename("index.html"))
|
2020-06-02 09:14:23 -05:00
|
|
|
.pipe(gulp.dest(output))
|
|
|
|
.pipe(touch());
|
2016-06-14 15:50:55 -05:00
|
|
|
};
|
|
|
|
}
|
2016-02-28 03:12:25 -05:00
|
|
|
|
2020-02-25 10:18:55 -05:00
|
|
|
/***********************************************
|
|
|
|
* Generic
|
|
|
|
***********************************************/
|
2016-06-14 15:50:55 -05:00
|
|
|
|
2020-11-12 07:35:20 -05:00
|
|
|
gulpSass.compiler = sass;
|
2020-04-08 03:57:29 -05:00
|
|
|
|
2020-11-12 07:35:20 -05:00
|
|
|
gulp.task("scss", function() {
|
|
|
|
return gulp.src(paths.resources + "styles/main-default.scss")
|
2021-07-13 06:24:42 -05:00
|
|
|
.pipe(gulpSass.sync().on('error', gulpSass.logError))
|
2020-11-12 07:35:20 -05:00
|
|
|
.pipe(gulpPostcss([
|
|
|
|
autoprefixer,
|
2020-11-20 18:14:59 -05:00
|
|
|
// clean({format: "keep-breaks", level: 1})
|
2020-11-12 07:35:20 -05:00
|
|
|
]))
|
|
|
|
.pipe(gulp.dest(paths.output + "css/"));
|
|
|
|
});
|
2016-06-14 15:50:55 -05:00
|
|
|
|
2021-01-27 06:25:27 -05:00
|
|
|
gulp.task("svg:sprite:icons", function() {
|
2020-02-25 10:18:55 -05:00
|
|
|
return gulp.src(paths.resources + "images/icons/*.svg")
|
2020-11-12 07:35:20 -05:00
|
|
|
.pipe(gulpRename({prefix: "icon-"}))
|
2021-01-27 06:25:27 -05:00
|
|
|
.pipe(svgSprite({mode:{symbol: {inline: true, sprite: "icons.svg"}}}))
|
|
|
|
.pipe(gulp.dest(paths.output + "images/sprites/"));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("svg:sprite:cursors", function() {
|
|
|
|
return gulp.src(paths.resources + "images/cursors/*.svg")
|
|
|
|
.pipe(gulpRename({prefix: "cursor-"}))
|
|
|
|
.pipe(svgSprite({mode:{symbol: {inline: true, sprite: "cursors.svg"}}}))
|
2020-11-12 07:35:20 -05:00
|
|
|
.pipe(gulp.dest(paths.output + "images/sprites/"));
|
2016-06-14 15:50:55 -05:00
|
|
|
});
|
|
|
|
|
2020-02-25 10:18:55 -05:00
|
|
|
gulp.task("template:main", templatePipeline({
|
|
|
|
input: paths.resources + "templates/index.mustache",
|
2020-03-30 16:56:15 -05:00
|
|
|
output: paths.output
|
2020-02-25 10:18:55 -05:00
|
|
|
}));
|
|
|
|
|
2021-01-27 06:25:27 -05:00
|
|
|
gulp.task("templates", gulp.series("svg:sprite:icons", "svg:sprite:cursors", "template:main"));
|
2019-05-31 06:50:55 -05:00
|
|
|
|
2020-11-20 18:14:59 -05:00
|
|
|
gulp.task("polyfills", function() {
|
|
|
|
return gulp.src(paths.resources + "polyfills/*.js")
|
|
|
|
.pipe(gulpConcat("polyfills.js"))
|
|
|
|
.pipe(gulp.dest(paths.output + "js/"));
|
|
|
|
});
|
|
|
|
|
2016-06-11 13:43:57 -05:00
|
|
|
/***********************************************
|
2020-02-25 10:18:55 -05:00
|
|
|
* Development
|
2016-06-11 13:43:57 -05:00
|
|
|
***********************************************/
|
|
|
|
|
2020-04-18 13:34:34 -05:00
|
|
|
gulp.task("clean", function(next) {
|
2020-03-30 16:56:15 -05:00
|
|
|
rimraf(paths.output, next);
|
2016-06-11 13:43:57 -05:00
|
|
|
});
|
|
|
|
|
2020-04-18 13:34:34 -05:00
|
|
|
gulp.task("copy:assets:images", function() {
|
2020-02-25 10:18:55 -05:00
|
|
|
return gulp.src(paths.resources + "images/**/*")
|
|
|
|
.pipe(gulp.dest(paths.output + "images/"));
|
|
|
|
});
|
2016-06-11 13:43:57 -05:00
|
|
|
|
2020-04-18 13:34:34 -05:00
|
|
|
gulp.task("copy:assets:fonts", function() {
|
2020-02-25 10:18:55 -05:00
|
|
|
return gulp.src(paths.resources + "fonts/**/*")
|
|
|
|
.pipe(gulp.dest(paths.output + "fonts/"));
|
|
|
|
});
|
2016-06-11 13:43:57 -05:00
|
|
|
|
2020-04-18 13:34:34 -05:00
|
|
|
gulp.task("copy:assets", gulp.parallel("copy:assets:images", "copy:assets:fonts"));
|
2016-06-14 15:50:55 -05:00
|
|
|
|
2020-09-07 06:38:17 -05:00
|
|
|
gulp.task("dev:dirs", async function(next) {
|
|
|
|
await mkdirp("./resources/public/css/");
|
|
|
|
await mkdirp("./resources/public/js/");
|
|
|
|
next();
|
2020-02-25 10:18:55 -05:00
|
|
|
});
|
2016-06-14 15:50:55 -05:00
|
|
|
|
2020-02-25 10:18:55 -05:00
|
|
|
gulp.task("watch:main", function() {
|
2020-11-12 07:35:20 -05:00
|
|
|
gulp.watch(paths.resources + "styles/**/**.scss", gulp.series("scss"));
|
|
|
|
gulp.watch(paths.resources + "images/**/*", gulp.series("copy:assets:images"));
|
2016-06-14 15:50:55 -05:00
|
|
|
|
2020-02-25 10:18:55 -05:00
|
|
|
gulp.watch([paths.resources + "templates/*.mustache",
|
2021-04-12 02:29:09 -05:00
|
|
|
"translations/*.po"],
|
2020-03-30 16:56:15 -05:00
|
|
|
gulp.series("templates"));
|
2020-02-25 10:18:55 -05:00
|
|
|
});
|
2016-06-14 15:50:55 -05:00
|
|
|
|
2020-11-20 18:14:59 -05:00
|
|
|
gulp.task("build", gulp.parallel("polyfills", "scss", "templates", "copy:assets"));
|
2020-11-12 07:35:20 -05:00
|
|
|
gulp.task("watch", gulp.series("dev:dirs", "build", "watch:main"));
|
2020-02-25 10:18:55 -05:00
|
|
|
|
|
|
|
/***********************************************
|
|
|
|
* Production
|
|
|
|
***********************************************/
|
|
|
|
|
|
|
|
gulp.task("dist:clean", function(next) {
|
2020-03-30 16:56:15 -05:00
|
|
|
rimraf(paths.dist, next);
|
2020-02-25 10:18:55 -05:00
|
|
|
});
|
|
|
|
|
2020-03-30 16:56:15 -05:00
|
|
|
gulp.task("dist:copy", function() {
|
|
|
|
return gulp.src(paths.output + "**/*")
|
2020-02-25 10:18:55 -05:00
|
|
|
.pipe(gulp.dest(paths.dist));
|
2016-02-21 11:01:27 -05:00
|
|
|
});
|