snappymail/tasks/js.js

136 lines
3.1 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'),
gap = require('gulp-append-prepend'),
2019-06-29 22:16:09 +08:00
rename = require('gulp-rename'),
replace = require('gulp-replace'),
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 } = require('./common');
2019-06-29 22:16:09 +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
const prepend = () => gap.prependText(config.head.agpl + '\n');
2020-09-03 22:34:23 +08:00
// boot
const jsBoot = () => {
return gulp
.src('dev/boot.js')
.pipe(gulp.dest(config.paths.staticJS));
2020-09-03 22:34:23 +08:00
};
// ServiceWorker
const jsServiceWorker = () => {
return gulp
.src('dev/serviceworker.js')
.pipe(gulp.dest(config.paths.staticJS));
};
// OpenPGP
const jsOpenPGP = () => {
return gulp
.src('vendors/openpgp-5/dist/openpgp.js')
.pipe(gulp.dest(config.paths.staticJS));
};
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(prepend())
2022-03-09 19:33:31 +08:00
.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
const jsApp = async () =>
(await rollupJS(config.paths.js.app.name))
// .pipe(sourcemaps.write('.'))
.pipe(prepend())
2019-06-29 22:16:09 +08:00
.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 jsAdmin = async () =>
(await rollupJS(config.paths.js.admin.name))
// .pipe(sourcemaps.write('.'))
.pipe(prepend())
2019-06-29 22:16:09 +08:00
.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
})
)
.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(
terser({
output: {
comments: false
},
keep_classnames: true, // Required for AbstractModel and AbstractCollectionModel
compress:{
ecma: 6,
drop_console: true
/*
,hoist_props: false
,keep_fargs: false
,toplevel: true
,unsafe_arrows: true // Issue with knockoutjs
,unsafe_methods: true
,unsafe_proto: true
*/
}
// ,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,
gulp.parallel(jsBoot, jsServiceWorker, jsOpenPGP, jsLibs, jsSieve, jsApp, jsAdmin),
2021-09-01 17:18:57 +08:00
jsMin
);