2019-06-29 22:16:09 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under AGPL 3 */
|
|
|
|
const gulp = require('gulp');
|
|
|
|
|
2019-07-05 03:09:27 +08:00
|
|
|
const concat = require('gulp-concat-util'),
|
2019-06-29 22:16:09 +08:00
|
|
|
header = require('gulp-header'),
|
|
|
|
rename = require('gulp-rename'),
|
|
|
|
replace = require('gulp-replace'),
|
2020-03-20 23:26:42 +08:00
|
|
|
terser = require('gulp-terser'),
|
2019-06-29 22:16:09 +08:00
|
|
|
plumber = require('gulp-plumber'),
|
|
|
|
gulpif = require('gulp-if'),
|
|
|
|
eol = require('gulp-eol'),
|
|
|
|
eslint = require('gulp-eslint'),
|
|
|
|
cache = require('gulp-cached'),
|
|
|
|
expect = require('gulp-expect-file'),
|
|
|
|
size = require('gulp-size'),
|
2019-07-05 03:09:27 +08:00
|
|
|
sourcemaps = require('gulp-sourcemaps'),
|
2019-06-29 22:16:09 +08:00
|
|
|
gutil = require('gulp-util');
|
|
|
|
|
2019-07-05 03:09:27 +08:00
|
|
|
const { config } = require('./config');
|
|
|
|
const { del, getHead } = require('./common');
|
2019-06-29 22:16:09 +08:00
|
|
|
|
2019-07-05 03:09:27 +08:00
|
|
|
const { webpack } = require('./webpack');
|
2019-06-29 22:16:09 +08:00
|
|
|
|
2019-07-05 03:09:27 +08:00
|
|
|
const jsClean = () => del(config.paths.staticJS + '/**/*.{js,map}');
|
2019-06-29 22:16:09 +08:00
|
|
|
|
2020-09-03 22:34:23 +08:00
|
|
|
// boot
|
|
|
|
const jsBoot = () => {
|
|
|
|
return gulp
|
|
|
|
.src('dev/boot.js')
|
|
|
|
.pipe(gulp.dest('rainloop/v/' + config.devVersion + '/static/js'));
|
|
|
|
};
|
|
|
|
|
2019-06-29 22:16:09 +08:00
|
|
|
// libs
|
|
|
|
const jsLibs = () => {
|
|
|
|
const src = config.paths.js.libs.src;
|
2019-07-05 03:09:27 +08:00
|
|
|
return gulp
|
|
|
|
.src(src)
|
|
|
|
.pipe(expect.real({ errorOnFailure: true }, src))
|
|
|
|
.pipe(concat(config.paths.js.libs.name, { separator: '\n\n' }))
|
2019-06-29 22:16:09 +08:00
|
|
|
.pipe(eol('\n', true))
|
2019-07-05 03:09:27 +08:00
|
|
|
.pipe(replace(/sourceMappingURL=[a-z0-9.\-_]{1,20}\.map/gi, ''))
|
2019-06-29 22:16:09 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticJS));
|
|
|
|
};
|
|
|
|
|
|
|
|
// app
|
|
|
|
const jsApp = () =>
|
2019-07-05 03:09:27 +08:00
|
|
|
gulp
|
|
|
|
.src(config.paths.staticJS + config.paths.js.app.name)
|
2019-06-29 22:16:09 +08:00
|
|
|
.pipe(header(getHead() + '\n'))
|
|
|
|
.pipe(eol('\n', true))
|
|
|
|
.pipe(gulp.dest(config.paths.staticJS))
|
|
|
|
.on('error', gutil.log);
|
|
|
|
|
|
|
|
const jsAdmin = () =>
|
2019-07-05 03:09:27 +08:00
|
|
|
gulp
|
|
|
|
.src(config.paths.staticJS + config.paths.js.admin.name)
|
2019-06-29 22:16:09 +08:00
|
|
|
.pipe(header(getHead() + '\n'))
|
|
|
|
.pipe(eol('\n', true))
|
|
|
|
.pipe(gulp.dest(config.paths.staticJS))
|
|
|
|
.on('error', gutil.log);
|
|
|
|
|
|
|
|
const jsMin = () =>
|
2019-07-05 03:09:27 +08:00
|
|
|
gulp
|
|
|
|
.src(config.paths.staticJS + '*.js')
|
|
|
|
.pipe(
|
|
|
|
size({
|
|
|
|
showFiles: true,
|
|
|
|
showTotal: false
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.pipe(gulpif(config.source, sourcemaps.init({ loadMaps: true })))
|
|
|
|
.pipe(replace(/"rainloop\/v\/([^/]+)\/static\/js\/"/g, '"rainloop/v/$1/static/js/min/"'))
|
|
|
|
.pipe(rename({ suffix: '.min' }))
|
|
|
|
.pipe(
|
2020-03-20 23:26:42 +08:00
|
|
|
terser({
|
2020-10-09 17:58:15 +08:00
|
|
|
output: {
|
|
|
|
comments: false
|
|
|
|
},
|
|
|
|
compress:{
|
|
|
|
ecma: 6,
|
|
|
|
drop_console: true
|
|
|
|
}
|
2019-07-05 03:09:27 +08:00
|
|
|
})
|
|
|
|
)
|
2019-06-29 22:16:09 +08:00
|
|
|
.pipe(eol('\n', true))
|
2019-07-05 03:09:27 +08:00
|
|
|
.pipe(gulpif(config.source, sourcemaps.write('./')))
|
|
|
|
.pipe(
|
|
|
|
size({
|
|
|
|
showFiles: true,
|
|
|
|
showTotal: false
|
|
|
|
})
|
|
|
|
)
|
2019-06-29 22:16:09 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticMinJS))
|
|
|
|
.on('error', gutil.log);
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
const jsLint = () =>
|
2019-07-05 03:09:27 +08:00
|
|
|
gulp
|
|
|
|
.src(config.paths.globjs)
|
2019-06-29 22:16:09 +08:00
|
|
|
.pipe(cache('eslint'))
|
|
|
|
.pipe(eslint())
|
|
|
|
.pipe(gulpif(config.watch, plumber()))
|
|
|
|
.pipe(eslint.format())
|
|
|
|
.pipe(eslint.failAfterError());
|
|
|
|
|
|
|
|
const jsState1 = gulp.series(jsLint);
|
2020-09-03 22:34:23 +08:00
|
|
|
const jsState3 = gulp.parallel(jsBoot, jsLibs, jsApp, jsAdmin);
|
2019-06-29 22:16:09 +08:00
|
|
|
const jsState2 = gulp.series(jsClean, webpack, jsState3, jsMin);
|
|
|
|
|
|
|
|
exports.jsLint = jsLint;
|
|
|
|
exports.js = gulp.parallel(jsState1, jsState2);
|