forked from the-djmaze/snappymail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.js
135 lines (120 loc) · 3.14 KB
/
js.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* RainLoop Webmail (c) RainLoop Team | Licensed under MIT */
const gulp = require('gulp');
const concat = require('gulp-concat'),
gap = require('gulp-append-prepend'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
terser = require('gulp-terser'),
eol = require('gulp-eol'),
eslint = require('gulp-eslint'),
cache = require('gulp-cached'),
expect = require('gulp-expect-file'),
size = require('gulp-size');
const { config } = require('./config');
const { del } = require('./common');
const { rollupJS } = require('./rollup');
const jsClean = () => del(config.paths.staticJS + '/**/*.{js,map}');
const prepend = () => gap.prependText(config.head.agpl + '\n');
// boot
const jsBoot = () => {
return gulp
.src('dev/boot.js')
.pipe(gulp.dest(config.paths.staticJS));
};
// 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));
};
// libs
const jsLibs = () => {
const src = config.paths.js.libs.src;
return gulp
.src(src)
.pipe(expect.real({ errorOnFailure: true }, src))
.pipe(concat(config.paths.js.libs.name, { separator: '\n\n' }))
.pipe(eol('\n', true))
.pipe(replace(/sourceMappingURL=[a-z0-9.\-_]{1,20}\.map/gi, ''))
.pipe(gulp.dest(config.paths.staticJS));
};
// sieve
const jsSieve = async () =>
(await rollupJS(config.paths.js.sieve.name))
// .pipe(sourcemaps.write('.'))
.pipe(prepend())
.pipe(eol('\n', true))
.pipe(gulp.dest(config.paths.staticJS));
// app
const jsApp = async () =>
(await rollupJS(config.paths.js.app.name))
// .pipe(sourcemaps.write('.'))
.pipe(prepend())
.pipe(eol('\n', true))
.pipe(gulp.dest(config.paths.staticJS));
const jsAdmin = async () =>
(await rollupJS(config.paths.js.admin.name))
// .pipe(sourcemaps.write('.'))
.pipe(prepend())
.pipe(eol('\n', true))
.pipe(gulp.dest(config.paths.staticJS));
const jsMin = () =>
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/"'))
.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']}
})
)
.pipe(eol('\n', true))
.pipe(
size({
showFiles: true,
showTotal: false
})
)
.pipe(gulp.dest(config.paths.staticMinJS));
const jsLint = () =>
gulp
.src(config.paths.globjs)
.pipe(cache('eslint'))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
exports.jsLint = jsLint;
exports.js = gulp.series(
jsClean,
jsLint,
gulp.parallel(jsBoot, jsServiceWorker, jsOpenPGP, jsLibs, jsSieve, jsApp, jsAdmin),
jsMin
);