commento/frontend/gulpfile.js

186 lines
4.6 KiB
JavaScript
Raw Normal View History

"use strict";
const gulp = require("gulp");
const sass = require('gulp-sass')(require('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/";
2019-02-19 06:33:11 +08:00
const fontsDir = "fonts/";
const fontsGlob = fontsDir + "**/*";
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": [
2018-12-25 10:49:53 +08:00
"js/constants.js",
"js/utils.js",
"js/http.js",
"js/auth-common.js",
"js/login.js"
],
"js/forgot.js": [
2018-12-25 10:49:53 +08:00
"js/constants.js",
"js/utils.js",
"js/http.js",
"js/forgot.js"
],
"js/reset.js": [
2018-12-25 10:49:53 +08:00
"js/constants.js",
"js/utils.js",
"js/http.js",
"js/reset.js"
],
"js/signup.js": [
2018-12-25 10:49:53 +08:00
"js/constants.js",
"js/utils.js",
"js/http.js",
"js/auth-common.js",
"js/signup.js"
],
"js/dashboard.js": [
2018-12-25 10:49:53 +08:00
"js/constants.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",
2019-01-31 15:06:11 +08:00
"js/dashboard-export.js",
],
"js/settings.js": [
"js/constants.js",
"js/utils.js",
"js/http.js",
"js/errors.js",
"js/self.js",
"js/settings.js"
],
"js/logout.js": [
2018-12-25 10:49:53 +08:00
"js/constants.js",
"js/utils.js",
"js/logout.js"
],
"js/commento.js": ["js/commento.js"],
2019-03-03 04:14:42 +08:00
"js/count.js": ["js/count.js"],
2019-02-19 05:30:54 +08:00
"js/unsubscribe.js": [
"js/constants.js",
"js/utils.js",
"js/http.js",
"js/unsubscribe.js",
],
"js/profile.js": [
"js/constants.js",
"js/utils.js",
"js/http.js",
"js/profile.js",
],
};
2019-09-14 08:14:43 +08:00
gulp.task("scss-devel", function (done) {
let res = gulp.src(scssSrc)
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: "expanded"}).on("error", sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest(develPath + cssDir));
2019-09-14 08:14:43 +08:00
done();
return res;
});
2019-09-14 08:14:43 +08:00
gulp.task("scss-prod", function (done) {
let res = gulp.src(scssSrc)
.pipe(sass({outputStyle: "compressed"}).on("error", sass.logError))
.pipe(cleanCss({compatibility: "ie8", level: 2}))
.pipe(gulp.dest(prodPath + cssDir));
2019-09-14 08:14:43 +08:00
done();
return res;
});
2019-09-14 08:14:43 +08:00
gulp.task("html-devel", function (done) {
gulp.src([htmlGlob]).pipe(gulp.dest(develPath));
2019-09-14 08:14:43 +08:00
done();
});
2019-09-14 08:14:43 +08:00
gulp.task("html-prod", function (done) {
gulp.src(htmlGlob)
.pipe(htmlMinifier({collapseWhitespace: true, removeComments: true}))
.pipe(gulp.dest(prodPath))
2019-09-14 08:14:43 +08:00
done();
});
2019-09-14 08:14:43 +08:00
gulp.task("fonts-devel", function (done) {
2019-02-19 06:33:11 +08:00
gulp.src([fontsGlob]).pipe(gulp.dest(develPath + fontsDir));
2019-09-14 08:14:43 +08:00
done();
2019-02-19 06:33:11 +08:00
});
2019-09-14 08:14:43 +08:00
gulp.task("fonts-prod", function (done) {
2019-02-19 06:33:11 +08:00
gulp.src([fontsGlob]).pipe(gulp.dest(prodPath + fontsDir));
2019-09-14 08:14:43 +08:00
done();
2019-02-19 06:33:11 +08:00
});
2019-09-14 08:14:43 +08:00
gulp.task("images-devel", function (done) {
gulp.src([imagesGlob]).pipe(gulp.dest(develPath + imagesDir));
2019-09-14 08:14:43 +08:00
done();
});
2019-09-14 08:14:43 +08:00
gulp.task("images-prod", function (done) {
gulp.src([imagesGlob]).pipe(gulp.dest(prodPath + imagesDir));
2019-09-14 08:14:43 +08:00
done();
});
2019-09-14 08:14:43 +08:00
gulp.task("js-devel", function (done) {
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))
}
2019-09-14 08:14:43 +08:00
done();
});
2019-09-14 08:14:43 +08:00
gulp.task("js-prod", function (done) {
for (let outputFile in jsCompileMap) {
gulp.src(jsCompileMap[outputFile])
.pipe(concat(outputFile))
.pipe(rename(outputFile))
.pipe(uglify())
.pipe(gulp.dest(prodPath))
}
2019-09-14 08:14:43 +08:00
done();
});
2019-09-14 08:14:43 +08:00
gulp.task("lint", function (done) {
let res = gulp.src(jsGlob)
.pipe(eslint())
2019-09-14 08:14:43 +08:00
.pipe(eslint.failAfterError());
done();
return res;
});
2019-09-14 08:14:43 +08:00
gulp.task("devel", gulp.parallel("scss-devel", "html-devel", "fonts-devel", "images-devel", "lint", "js-devel"));
gulp.task("prod", gulp.parallel("scss-prod", "html-prod", "fonts-prod", "images-prod", "lint", "js-prod"));