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');
|
|
|
|
|
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'),
|
2023-02-24 19:27:50 +08:00
|
|
|
size = require('gulp-size');
|
2019-06-29 22:16:09 +08:00
|
|
|
|
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
|
2022-01-31 16:38:33 +08:00
|
|
|
.src('vendors/openpgp-5/dist/openpgp.js')
|
2021-05-01 22:33:30 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticJS));
|
2021-01-26 05:00:13 +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));
|
|
|
|
};
|
|
|
|
|
2022-03-09 19:33:31 +08:00
|
|
|
// sieve
|
|
|
|
const jsSieve = async () =>
|
|
|
|
(await rollupJS(config.paths.js.sieve.name))
|
|
|
|
// .pipe(sourcemaps.write('.'))
|
|
|
|
.pipe(header(getHead() + '\n'))
|
|
|
|
.pipe(eol('\n', true))
|
2023-02-24 19:27:50 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticJS));
|
2022-03-09 19:33:31 +08:00
|
|
|
|
2019-06-29 22:16:09 +08:00
|
|
|
// 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))
|
2023-02-24 19:27:50 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticJS));
|
2019-06-29 22:16:09 +08:00
|
|
|
|
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))
|
2023-02-24 19:27:50 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticJS));
|
2019-06-29 22:16:09 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
)
|
2023-02-24 19:27:50 +08:00
|
|
|
.pipe(gulp.dest(config.paths.staticMinJS));
|
2019-06-29 22:16:09 +08:00
|
|
|
|
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());
|
|
|
|
|
|
|
|
exports.jsLint = jsLint;
|
2021-09-01 17:18:57 +08:00
|
|
|
exports.js = gulp.series(
|
|
|
|
jsClean,
|
|
|
|
jsLint,
|
2022-03-11 17:26:25 +08:00
|
|
|
gulp.parallel(jsBoot, jsServiceWorker, jsOpenPGP, jsLibs, jsSieve, jsApp, jsAdmin),
|
2021-09-01 17:18:57 +08:00
|
|
|
jsMin
|
|
|
|
);
|