gulpfile.js
2.86 KB
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
const { series, src, dest, } = require('gulp')
const babel = require('gulp-babel')
const removeUseStrict = require('gulp-remove-use-strict')
const exec = require('gulp-exec')
const del = require('del')
const path = require('path')
const { readFileSync, writeFileSync } = require('fs')
let oldTimespan = '?v=1659335275728'
/**
* @descritpion 清除dist 文件夹
* @param {*} cb
*/
async function clean(cb) {
await del(['dist'])
await cb()
}
/**
* @description 编译文件
* @param {*} cb
*/
function complieFormat(cb) {
src('./src/main/webapp/js/grapheditor/Format.js')
.pipe(babel({ presets: ['@babel/env'] }))
.pipe(removeUseStrict())
.pipe(dest('./src/main/webapp/js/grapheditor'))
cb()
}
/**
* @description 复制文件
* @param {*} cb
*/
function copyFile(cb) {
src('./src/main/webapp/js/grapheditor/Format.js')
.pipe(dest('./dist/'))
cb()
}
/**
* @description 构建war包
* @param {*} cb
*/
async function buildWar(cb) {
await new Promise((resolve) => {
src(path.resolve(__dirname, './'))
.pipe(exec('cd etc/build && ant war', function (err) {
resolve()
}))
.on('error', (error) => {
console.log('on build war package happend error', error.message)
})
})
}
/**
* @description 还原文件
* @param {*} cb
*/
function reductionFile(cb) {
src(path.resolve(__dirname, './dist/Format.js'))
.pipe(dest('./src/main/webapp/js/grapheditor'))
cb()
}
function generatoreVersion(cb) {
const reg = /const\s+releaseVersion\s?=\s?.*/g
const regTimespan = /\?v=(\d+)/g
const timespan = Date.now()
const string = readFileSync(path.resolve(__dirname, './src/main/webapp/index.html'), { encoding: 'utf-8' })
let newString = string.replace(reg, `const releaseVersion = '${encodeURIComponent(timespan)}'`)
newString = newString.replace(regTimespan, `?v=${timespan}`)
writeFileSync(path.resolve(__dirname, './src/main/webapp/index.html'), newString, { encoding: 'utf-8' })
cb()
}
function copyFileUsageOssServer(cb) {
const copyFileList = [
'./src/main/webapp/js/app.min.js',
'./src/main/webapp/js/shapes-14-6-5.min.js',
'./src/main/webapp/js/stencils.min.js',
'./src/main/webapp/js/extensions.min.js',
'./src/main/webapp/js/plugin/echarts/echarts.js',
'./src/main/webapp/js/plugin/crypto-js/crypto-js.js',
'./src/main/webapp/js/plugin/ace/ace.js',
'./src/main/webapp/js/plugin/ace/mode-json.js',
'./src/main/webapp/js/plugin/ace/worker-json.js',
'./src/main/webapp/js/plugin/video/video-js.min.css',
'./src/main/webapp/js/plugin/video/video.min.js',
]
const outPath = './build/oss'
for (const filePath of copyFileList) {
src(path.resolve(__dirname, filePath), { allowEmpty: true })
.pipe((dest(outPath)))
}
cb()
}
exports.default = series(copyFile, complieFormat, generatoreVersion, buildWar, copyFileUsageOssServer, reductionFile, clean)