snappymail/tasks/css.js

114 lines
3 KiB
JavaScript
Raw Normal View History

2022-09-01 02:15:45 +08:00
/* RainLoop Webmail (c) RainLoop Team | Licensed under MIT */
2019-06-29 22:16:09 +08:00
const gulp = require('gulp');
const concat = require('gulp-concat');
2019-07-05 03:09:27 +08:00
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const eol = require('gulp-eol');
const filter = require('gulp-filter');
const expect = require('gulp-expect-file');
const gcmq = require('gulp-group-css-media-queries');
2023-02-24 19:27:50 +08:00
const less = require('gulp-less');
2019-06-29 22:16:09 +08:00
2019-07-05 03:09:27 +08:00
const { config } = require('./config');
const { del } = require('./common');
2019-06-29 22:16:09 +08:00
const cleanCss = require('gulp-clean-css');
2019-06-29 22:16:09 +08:00
const cssClean = () => del(config.paths.staticCSS + '/*.css');
const cssBootBuild = () => {
const
src = config.paths.css.boot.src;
return gulp
.src(src)
.pipe(expect.real({ errorOnFailure: true }, src))
.pipe(concat(config.paths.css.boot.name))
.pipe(replace(/\.\.\/(img|images|fonts|svg)\//g, '$1/'))
.pipe(eol('\n', true))
.pipe(gulp.dest(config.paths.staticCSS));
};
2019-06-29 22:16:09 +08:00
const cssMainBuild = () => {
const
2019-07-05 03:09:27 +08:00
lessFilter = filter('**/*.less', { restore: true }),
2019-06-29 22:16:09 +08:00
src = config.paths.css.main.src.concat([config.paths.less.main.src]);
2019-07-05 03:09:27 +08:00
return gulp
.src(src)
.pipe(expect.real({ errorOnFailure: true }, src))
2019-06-29 22:16:09 +08:00
.pipe(lessFilter)
2019-07-05 03:09:27 +08:00
.pipe(
less({
'paths': config.paths.less.main.options.paths
})
)
2019-06-29 22:16:09 +08:00
.pipe(lessFilter.restore)
.pipe(concat(config.paths.css.main.name))
.pipe(replace(/\.\.\/(img|images|fonts|svg)\//g, '$1/'))
.pipe(eol('\n', true))
.pipe(gulp.dest(config.paths.staticCSS));
2019-06-29 22:16:09 +08:00
};
const cssAdminBuild = () => {
const
lessFilter = filter('**/*.less', { restore: true }),
src = config.paths.css.admin.src;
return gulp
.src(src)
.pipe(expect.real({ errorOnFailure: true }, src))
.pipe(lessFilter)
.pipe(
less({
'paths': config.paths.less.main.options.paths
})
)
.pipe(lessFilter.restore)
.pipe(concat(config.paths.css.admin.name))
.pipe(replace(/\.\.\/(img|images|fonts|svg)\//g, '$1/'))
.pipe(eol('\n', true))
.pipe(gulp.dest(config.paths.staticCSS));
};
const cssBootMin = () => {
return gulp
.src(config.paths.staticCSS + config.paths.css.boot.name)
.pipe(cleanCss())
.pipe(rename({ suffix: '.min' }))
.pipe(eol('\n', true))
.pipe(gulp.dest(config.paths.staticCSS));
};
2019-06-29 22:16:09 +08:00
const cssMainMin = () => {
2019-07-05 03:09:27 +08:00
return gulp
.src(config.paths.staticCSS + config.paths.css.main.name)
.pipe(gcmq())
2019-06-29 22:16:09 +08:00
.pipe(cleanCss())
2019-07-05 03:09:27 +08:00
.pipe(rename({ suffix: '.min' }))
2019-06-29 22:16:09 +08:00
.pipe(eol('\n', true))
.pipe(gulp.dest(config.paths.staticCSS));
};
const cssAdminMin = () => {
return gulp
.src(config.paths.staticCSS + config.paths.css.admin.name)
.pipe(gcmq())
.pipe(cleanCss())
.pipe(rename({ suffix: '.min' }))
.pipe(eol('\n', true))
.pipe(gulp.dest(config.paths.staticCSS));
};
const cssBuild = gulp.parallel(cssBootBuild, cssMainBuild, cssAdminBuild);
const cssMin = gulp.parallel(cssBootMin, cssMainMin, cssAdminMin);
2019-06-29 22:16:09 +08:00
const cssLint = (done) => done();
const cssState1 = gulp.series(cssLint);
const cssState2 = gulp.series(cssClean, cssBuild, cssMin);
exports.cssLint = cssLint;
exports.cssBuild = cssBuild;
exports.css = gulp.parallel(cssState1, cssState2);