2019-06-29 22:16:09 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under AGPL 3 */
|
|
|
|
const gulp = require('gulp');
|
|
|
|
|
2021-07-21 17:20:55 +08:00
|
|
|
const concat = require('gulp-concat'),
|
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
|
|
|
eol = require('gulp-eol'),
|
|
|
|
eslint = require('gulp-eslint'),
|
|
|
|
cache = require('gulp-cached'),
|
|
|
|
expect = require('gulp-expect-file'),
|
|
|
|
size = require('gulp-size'),
|
|
|
|
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
|
|
|
|
2021-02-02 20:54:48 +08:00
|
|
|
const { rollupJS } = require('./rollup');
|
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')
|
2021-01-26 05:00:13 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticJS));
|
2020-09-03 22:34:23 +08:00
|
|
|
};
|
|
|
|
|
2020-11-10 03:14:04 +08:00
|
|
|
// ServiceWorker
|
|
|
|
const jsServiceWorker = () => {
|
|
|
|
return gulp
|
|
|
|
.src('dev/serviceworker.js')
|
2021-01-26 05:00:13 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticJS));
|
|
|
|
};
|
|
|
|
|
|
|
|
// OpenPGP
|
|
|
|
const jsOpenPGP = () => {
|
|
|
|
return gulp
|
2021-05-01 22:33:30 +08:00
|
|
|
.src('vendors/openpgp-2.6.2/dist/openpgp.js')
|
|
|
|
.pipe(gulp.dest(config.paths.staticJS));
|
2021-01-26 05:00:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// OpenPGP Worker
|
|
|
|
const jsOpenPGPWorker = () => {
|
|
|
|
return gulp
|
2021-05-01 21:10:04 +08:00
|
|
|
.src('vendors/openpgp-2.6.2/dist/openpgp.worker.min.js')
|
2021-01-26 05:00:13 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticMinJS));
|
2020-11-10 03:14:04 +08:00
|
|
|
};
|
|
|
|
|
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
|
2021-02-02 20:54:48 +08:00
|
|
|
const jsApp = async () =>
|
|
|
|
(await rollupJS(config.paths.js.app.name))
|
|
|
|
// .pipe(sourcemaps.write('.'))
|
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);
|
|
|
|
|
2021-02-02 20:54:48 +08:00
|
|
|
const jsAdmin = async () =>
|
|
|
|
(await rollupJS(config.paths.js.admin.name))
|
|
|
|
// .pipe(sourcemaps.write('.'))
|
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
|
|
|
|
})
|
|
|
|
)
|
2020-10-15 22:21:52 +08:00
|
|
|
.pipe(replace(/"snappymail\/v\/([^/]+)\/static\/js\/"/g, '"snappymail/v/$1/static/js/min/"'))
|
2019-07-05 03:09:27 +08:00
|
|
|
.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
|
|
|
|
},
|
2020-10-21 01:54:10 +08:00
|
|
|
keep_classnames: true, // Required for AbstractModel and AbstractCollectionModel
|
2020-10-09 17:58:15 +08:00
|
|
|
compress:{
|
|
|
|
ecma: 6,
|
|
|
|
drop_console: true
|
2020-10-15 22:21:52 +08:00
|
|
|
/*
|
|
|
|
,hoist_props: false
|
|
|
|
,keep_fargs: false
|
|
|
|
,toplevel: true
|
|
|
|
,unsafe_arrows: true // Issue with knockoutjs
|
|
|
|
,unsafe_methods: true
|
|
|
|
,unsafe_proto: true
|
|
|
|
*/
|
2020-10-09 17:58:15 +08:00
|
|
|
}
|
2020-10-15 22:21:52 +08:00
|
|
|
// ,mangle: {reserved:['SendMessage']}
|
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(
|
|
|
|
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(eslint.format())
|
|
|
|
.pipe(eslint.failAfterError());
|
|
|
|
|
|
|
|
const jsState1 = gulp.series(jsLint);
|
2021-02-02 20:54:48 +08:00
|
|
|
const jsState3 = gulp.parallel(jsBoot, jsServiceWorker, jsOpenPGP, jsOpenPGPWorker, jsLibs, jsApp, jsAdmin);
|
|
|
|
const jsState2 = gulp.series(jsClean, jsState3, jsMin);
|
2019-06-29 22:16:09 +08:00
|
|
|
|
|
|
|
exports.jsLint = jsLint;
|
|
|
|
exports.js = gulp.parallel(jsState1, jsState2);
|