commento/frontend/gulpfile.js

134 lines
3.5 KiB
JavaScript
Raw Normal View History

"use strict";
const gulp = require("gulp");
const sass = require("gulp-sass");
const sourcemaps = require("gulp-sourcemaps");
const cleanCss = require("gulp-clean-css");
const htmlMinifier = require("gulp-html-minifier");
const uglify = require("gulp-uglify");
const concat = require("gulp-concat");
const rename = require("gulp-rename");
const eslint = require("gulp-eslint");
const develPath = "build/devel/";
const prodPath = "build/prod/";
const scssSrc = "./sass/*.scss";
const cssDir = "css/";
const imagesDir = "images/";
const imagesGlob = imagesDir + "**/*";
const jsDir = "js/";
const jsGlob = jsDir + "*.js";
const htmlGlob = "./*.html";
const jsCompileMap = {
"js/jquery.js": ["node_modules/jquery/dist/jquery.min.js"],
"js/vue.js": ["node_modules/vue/dist/vue.min.js"],
"js/highlight.js": ["node_modules/highlightjs/highlight.pack.min.js"],
"js/chartist.js": ["node_modules/chartist/dist/chartist.min.js"],
"js/login.js": [
"js/utils.js",
"js/http.js",
"js/auth-common.js",
"js/login.js"
],
"js/forgot.js": [
"js/utils.js",
"js/http.js",
"js/forgot.js"
],
"js/reset.js": [
"js/utils.js",
"js/http.js",
"js/reset.js"
],
"js/signup.js": [
"js/utils.js",
"js/http.js",
"js/auth-common.js",
"js/signup.js"
],
"js/dashboard.js": [
"js/utils.js",
"js/http.js",
"js/errors.js",
"js/self.js",
"js/dashboard.js",
"js/dashboard-setting.js",
"js/dashboard-domain.js",
"js/dashboard-installation.js",
"js/dashboard-general.js",
"js/dashboard-moderation.js",
"js/dashboard-statistics.js",
"js/dashboard-import.js",
"js/dashboard-danger.js",
],
"js/logout.js": [
"js/utils.js",
"js/logout.js"
],
"js/commento.js": ["js/commento.js"],
};
gulp.task("scss-devel", function () {
return gulp.src(scssSrc)
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: "expanded"}).on("error", sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest(develPath + cssDir));
});
gulp.task("scss-prod", function () {
return gulp.src(scssSrc)
.pipe(sass({outputStyle: "compressed"}).on("error", sass.logError))
.pipe(cleanCss({compatibility: "ie8", level: 2}))
.pipe(gulp.dest(prodPath + cssDir));
});
gulp.task("html-devel", function () {
gulp.src([htmlGlob]).pipe(gulp.dest(develPath));
});
gulp.task("html-prod", function () {
gulp.src(htmlGlob)
.pipe(htmlMinifier({collapseWhitespace: true, removeComments: true}))
.pipe(gulp.dest(prodPath))
});
gulp.task("images-devel", function () {
gulp.src([imagesGlob]).pipe(gulp.dest(develPath + imagesDir));
});
gulp.task("images-prod", function () {
gulp.src([imagesGlob]).pipe(gulp.dest(prodPath + imagesDir));
});
gulp.task("js-devel", function () {
for (let outputFile in jsCompileMap) {
gulp.src(jsCompileMap[outputFile])
.pipe(sourcemaps.init())
.pipe(concat(outputFile))
.pipe(rename(outputFile))
.pipe(sourcemaps.write())
.pipe(gulp.dest(develPath))
}
});
gulp.task("js-prod", function () {
for (let outputFile in jsCompileMap) {
gulp.src(jsCompileMap[outputFile])
.pipe(concat(outputFile))
.pipe(rename(outputFile))
.pipe(uglify())
.pipe(gulp.dest(prodPath))
}
});
gulp.task("lint", function () {
return gulp.src(jsGlob)
.pipe(eslint())
.pipe(eslint.failAfterError())
});
gulp.task("devel", ["scss-devel", "html-devel", "images-devel", "lint", "js-devel"]);
gulp.task("prod", ["scss-prod", "html-prod", "images-prod", "lint", "js-prod"]);