gulpfile.js
1.98 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
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')
/**
* @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/Format_before_compile.js'))
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()
}))
})
}
/**
* @description 还原文件
* @param {*} cb
*/
function reductionFile(cb) {
src(path.resolve(__dirname, './dist/Format_before_compile.js/Format.js'))
.pipe(dest('./src/main/webapp/js/grapheditor'))
cb()
}
function generatoreVersion(cb) {
const reg = /const\s+releaseVersion\s?=\s?.*/g
const string = readFileSync(path.resolve(__dirname, './src/main/webapp/index.html'), { encoding: 'utf-8' })
// const oldVersion = Number(reg.exec(string)[0].split('=')[1])
// const newVersion = oldVersion + 1
const newString = string.replace(reg, `const releaseVersion = '${encodeURIComponent(Date.now())}'`)
writeFileSync(path.resolve(__dirname, './src/main/webapp/index.html'), newString, { encoding: 'utf-8' })
cb()
}
// exports.default = series(generatoreVersion)
exports.default = series(copyFile, complieFormat, generatoreVersion, buildWar, reductionFile, clean)