Commit 5eaae6c3ff8dce6e0ab3fc74afefbb090277cf8f
1 parent
fa6e14fc
chore: app.min.js use cache file after release version
Showing
2 changed files
with
36 additions
and
3 deletions
... | ... | @@ -4,13 +4,21 @@ const removeUseStrict = require('gulp-remove-use-strict') |
4 | 4 | const exec = require('gulp-exec') |
5 | 5 | const del = require('del') |
6 | 6 | const path = require('path') |
7 | +const { readFileSync, writeFileSync } = require('fs') | |
7 | 8 | |
8 | - | |
9 | +/** | |
10 | + * @descritpion 清除dist 文件夹 | |
11 | + * @param {*} cb | |
12 | + */ | |
9 | 13 | async function clean(cb) { |
10 | 14 | await del(['dist']) |
11 | 15 | await cb() |
12 | 16 | } |
13 | 17 | |
18 | +/** | |
19 | + * @description 编译文件 | |
20 | + * @param {*} cb | |
21 | + */ | |
14 | 22 | function complieFormat(cb) { |
15 | 23 | src('./src/main/webapp/js/grapheditor/Format.js') |
16 | 24 | .pipe(babel({ presets: ['@babel/env'] })) |
... | ... | @@ -20,6 +28,10 @@ function complieFormat(cb) { |
20 | 28 | cb() |
21 | 29 | } |
22 | 30 | |
31 | +/** | |
32 | + * @description 复制文件 | |
33 | + * @param {*} cb | |
34 | + */ | |
23 | 35 | function copyFile(cb) { |
24 | 36 | src('./src/main/webapp/js/grapheditor/Format.js') |
25 | 37 | .pipe(dest('./dist/Format_before_compile.js')) |
... | ... | @@ -27,6 +39,10 @@ function copyFile(cb) { |
27 | 39 | cb() |
28 | 40 | } |
29 | 41 | |
42 | +/** | |
43 | + * @description 构建war包 | |
44 | + * @param {*} cb | |
45 | + */ | |
30 | 46 | async function buildWar(cb) { |
31 | 47 | await new Promise((resolve) => { |
32 | 48 | src(path.resolve(__dirname, './')) |
... | ... | @@ -36,10 +52,26 @@ async function buildWar(cb) { |
36 | 52 | }) |
37 | 53 | } |
38 | 54 | |
55 | +/** | |
56 | + * @description 还原文件 | |
57 | + * @param {*} cb | |
58 | + */ | |
39 | 59 | function reductionFile(cb) { |
40 | 60 | src(path.resolve(__dirname, './dist/Format_before_compile.js/Format.js')) |
41 | 61 | .pipe(dest('./src/main/webapp/js/grapheditor')) |
42 | 62 | cb() |
43 | 63 | } |
44 | 64 | |
45 | -exports.default = series(copyFile, complieFormat, buildWar, reductionFile, clean) | |
65 | +function generatoreVersion(cb) { | |
66 | + const reg = /const\s+releaseVersion\s?=\s?.*/g | |
67 | + const string = readFileSync(path.resolve(__dirname, './src/main/webapp/index.html'), { encoding: 'utf-8' }) | |
68 | + // const oldVersion = Number(reg.exec(string)[0].split('=')[1]) | |
69 | + // const newVersion = oldVersion + 1 | |
70 | + const newString = string.replace(reg, `const releaseVersion = '${encodeURIComponent(Date.now())}'`) | |
71 | + writeFileSync(path.resolve(__dirname, './src/main/webapp/index.html'), newString, { encoding: 'utf-8' }) | |
72 | + cb() | |
73 | +} | |
74 | + | |
75 | +// exports.default = series(generatoreVersion) | |
76 | + | |
77 | +exports.default = series(copyFile, complieFormat, generatoreVersion, buildWar, reductionFile, clean) | ... | ... |
... | ... | @@ -305,8 +305,9 @@ |
305 | 305 | var supportedDomain = (hostName.substring(hostName.length - 8, hostName.length) === '.draw.io') || |
306 | 306 | (hostName.substring(hostName.length - 13, hostName.length) === '.diagrams.net'); |
307 | 307 | |
308 | + const releaseVersion = '1658199639348' | |
308 | 309 | function loadAppJS() { |
309 | - mxscript('js/app.min.js', function () { | |
310 | + mxscript(`js/app.min.js?v=${releaseVersion}`, function () { | |
310 | 311 | mxScriptsLoaded = true; |
311 | 312 | checkAllLoaded(); |
312 | 313 | ... | ... |