Commit 5eaae6c3ff8dce6e0ab3fc74afefbb090277cf8f

Authored by ww
1 parent fa6e14fc

chore: app.min.js use cache file after release version

@@ -4,13 +4,21 @@ const removeUseStrict = require('gulp-remove-use-strict') @@ -4,13 +4,21 @@ const removeUseStrict = require('gulp-remove-use-strict')
4 const exec = require('gulp-exec') 4 const exec = require('gulp-exec')
5 const del = require('del') 5 const del = require('del')
6 const path = require('path') 6 const path = require('path')
  7 +const { readFileSync, writeFileSync } = require('fs')
7 8
8 - 9 +/**
  10 + * @descritpion 清除dist 文件夹
  11 + * @param {*} cb
  12 + */
9 async function clean(cb) { 13 async function clean(cb) {
10 await del(['dist']) 14 await del(['dist'])
11 await cb() 15 await cb()
12 } 16 }
13 17
  18 +/**
  19 + * @description 编译文件
  20 + * @param {*} cb
  21 + */
14 function complieFormat(cb) { 22 function complieFormat(cb) {
15 src('./src/main/webapp/js/grapheditor/Format.js') 23 src('./src/main/webapp/js/grapheditor/Format.js')
16 .pipe(babel({ presets: ['@babel/env'] })) 24 .pipe(babel({ presets: ['@babel/env'] }))
@@ -20,6 +28,10 @@ function complieFormat(cb) { @@ -20,6 +28,10 @@ function complieFormat(cb) {
20 cb() 28 cb()
21 } 29 }
22 30
  31 +/**
  32 + * @description 复制文件
  33 + * @param {*} cb
  34 + */
23 function copyFile(cb) { 35 function copyFile(cb) {
24 src('./src/main/webapp/js/grapheditor/Format.js') 36 src('./src/main/webapp/js/grapheditor/Format.js')
25 .pipe(dest('./dist/Format_before_compile.js')) 37 .pipe(dest('./dist/Format_before_compile.js'))
@@ -27,6 +39,10 @@ function copyFile(cb) { @@ -27,6 +39,10 @@ function copyFile(cb) {
27 cb() 39 cb()
28 } 40 }
29 41
  42 +/**
  43 + * @description 构建war包
  44 + * @param {*} cb
  45 + */
30 async function buildWar(cb) { 46 async function buildWar(cb) {
31 await new Promise((resolve) => { 47 await new Promise((resolve) => {
32 src(path.resolve(__dirname, './')) 48 src(path.resolve(__dirname, './'))
@@ -36,10 +52,26 @@ async function buildWar(cb) { @@ -36,10 +52,26 @@ async function buildWar(cb) {
36 }) 52 })
37 } 53 }
38 54
  55 +/**
  56 + * @description 还原文件
  57 + * @param {*} cb
  58 + */
39 function reductionFile(cb) { 59 function reductionFile(cb) {
40 src(path.resolve(__dirname, './dist/Format_before_compile.js/Format.js')) 60 src(path.resolve(__dirname, './dist/Format_before_compile.js/Format.js'))
41 .pipe(dest('./src/main/webapp/js/grapheditor')) 61 .pipe(dest('./src/main/webapp/js/grapheditor'))
42 cb() 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,8 +305,9 @@
305 var supportedDomain = (hostName.substring(hostName.length - 8, hostName.length) === '.draw.io') || 305 var supportedDomain = (hostName.substring(hostName.length - 8, hostName.length) === '.draw.io') ||
306 (hostName.substring(hostName.length - 13, hostName.length) === '.diagrams.net'); 306 (hostName.substring(hostName.length - 13, hostName.length) === '.diagrams.net');
307 307
  308 + const releaseVersion = '1658199639348'
308 function loadAppJS() { 309 function loadAppJS() {
309 - mxscript('js/app.min.js', function () { 310 + mxscript(`js/app.min.js?v=${releaseVersion}`, function () {
310 mxScriptsLoaded = true; 311 mxScriptsLoaded = true;
311 checkAllLoaded(); 312 checkAllLoaded();
312 313