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');
|
|
|
|
|
2019-07-05 03:09:27 +08:00
|
|
|
const concat = require('gulp-concat-util');
|
|
|
|
const rename = require('gulp-rename');
|
|
|
|
const replace = require('gulp-replace');
|
|
|
|
const plumber = require('gulp-plumber');
|
|
|
|
const gulpif = require('gulp-if');
|
|
|
|
const eol = require('gulp-eol');
|
|
|
|
const livereload = require('gulp-livereload');
|
|
|
|
const filter = require('gulp-filter');
|
|
|
|
const expect = require('gulp-expect-file');
|
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 cssClean = () => del(config.paths.staticCSS + '/*.css');
|
|
|
|
|
|
|
|
const cssMainBuild = () => {
|
|
|
|
const autoprefixer = require('gulp-autoprefixer'),
|
|
|
|
less = require('gulp-less'),
|
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)
|
|
|
|
.pipe(gulpif(config.watch, plumber()))
|
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(autoprefixer())
|
|
|
|
.pipe(replace(/\.\.\/(img|images|fonts|svg)\//g, '$1/'))
|
|
|
|
.pipe(eol('\n', true))
|
|
|
|
.pipe(gulp.dest(config.paths.staticCSS))
|
|
|
|
.pipe(livereload());
|
|
|
|
};
|
|
|
|
|
|
|
|
const cssSocialBuild = () => {
|
|
|
|
const autoprefixer = require('gulp-autoprefixer'),
|
|
|
|
src = config.paths.css.social.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(concat(config.paths.css.social.name))
|
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(replace(/\.\.\/(img|images|fonts|svg)\//g, '$1/'))
|
|
|
|
.pipe(eol('\n', true))
|
|
|
|
.pipe(gulp.dest(config.paths.staticCSS));
|
|
|
|
};
|
|
|
|
|
|
|
|
const cssMainMin = () => {
|
|
|
|
const cleanCss = require('gulp-clean-css');
|
2019-07-05 03:09:27 +08:00
|
|
|
return gulp
|
|
|
|
.src(config.paths.staticCSS + config.paths.css.main.name)
|
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 cssSocialMin = () => {
|
|
|
|
const cleanCss = require('gulp-clean-css');
|
2019-07-05 03:09:27 +08:00
|
|
|
return gulp
|
|
|
|
.src(config.paths.staticCSS + config.paths.css.social.name)
|
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 cssBuild = gulp.parallel(cssMainBuild, cssSocialBuild);
|
|
|
|
const cssMin = gulp.parallel(cssMainMin, cssSocialMin);
|
|
|
|
|
|
|
|
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);
|