修复依赖版本声明
This commit is contained in:
parent
943bff539f
commit
a211a1ab6a
|
|
@ -0,0 +1,140 @@
|
||||||
|
const axios = require('axios').default
|
||||||
|
const fs = require('fs')
|
||||||
|
const Path = require('path')
|
||||||
|
|
||||||
|
function mkdirsSync(dirname) {
|
||||||
|
if (fs.existsSync(dirname)) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
if (mkdirsSync(Path.dirname(dirname))) {
|
||||||
|
fs.mkdirSync(dirname)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const fileTemplate = `/**
|
||||||
|
* 该文件由插件根据doc.html在启动项目时自动生成,请勿修改(修改了也会被覆盖
|
||||||
|
*/
|
||||||
|
|
||||||
|
import request from '@/utils/request'
|
||||||
|
`
|
||||||
|
const functionCodeGener = function(meta) {
|
||||||
|
const functionParams = []
|
||||||
|
if (Array.isArray(meta.params) && meta.params.length > 0) {
|
||||||
|
functionParams.push('params')
|
||||||
|
}
|
||||||
|
if (Array.isArray(meta.data) && meta.data.length > 0) {
|
||||||
|
functionParams.push('data')
|
||||||
|
}
|
||||||
|
if (Array.isArray(meta.formData) && meta.formData.length > 0) {
|
||||||
|
functionParams.push('formData')
|
||||||
|
}
|
||||||
|
return `
|
||||||
|
/**
|
||||||
|
* ${meta.comment}
|
||||||
|
*/
|
||||||
|
export function ${meta.name}(${functionParams.join(', ')}) {
|
||||||
|
return request({
|
||||||
|
method: '${meta.method}',
|
||||||
|
url: '${meta.url}'${meta.requestType ? ',\n requestType: \'' + meta.requestType + '\'' : ''}${functionParams.includes('params') ? ',\n params' : ''}${functionParams.includes('data') || functionParams.includes('formData') ? ',\n data' + (functionParams.includes('formData') ? ': formData' : '') : ''}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
module.exports = class Genapi {
|
||||||
|
constructor(apiUrl, output = 'build') {
|
||||||
|
this.apiUrl = apiUrl[apiUrl.length - 1] === '/' ? apiUrl.slice(0, apiUrl.length - 1) : apiUrl
|
||||||
|
this.output = output
|
||||||
|
}
|
||||||
|
apply(compiler) {
|
||||||
|
compiler.hooks.environment.tap('Genapi', async(compilation, callback) => {
|
||||||
|
const projectPath = Path.join(__dirname, '../')
|
||||||
|
const apiPath = Path.join(projectPath, 'src/api/', this.output)
|
||||||
|
axios({
|
||||||
|
url: this.apiUrl + '/swagger-resources',
|
||||||
|
method: 'get'
|
||||||
|
}).then(({ data }) => {
|
||||||
|
const resultFile = {}
|
||||||
|
Promise.all(data.map((apiScope) => {
|
||||||
|
return axios({
|
||||||
|
url: this.apiUrl + '/v2/api-docs',
|
||||||
|
params: {
|
||||||
|
group: apiScope.name
|
||||||
|
},
|
||||||
|
method: 'get'
|
||||||
|
}).then(({ data }) => {
|
||||||
|
const {
|
||||||
|
basePath,
|
||||||
|
paths
|
||||||
|
} = data
|
||||||
|
for (const _path in paths) {
|
||||||
|
const path = _path.replace(new RegExp('^' + basePath, 'g'), '')
|
||||||
|
const pathSplit = path.split('/').slice('/')
|
||||||
|
const apiName = pathSplit[pathSplit.length - 1]
|
||||||
|
const fileName = pathSplit.length > 2 ? pathSplit[pathSplit.length - 2] : ''
|
||||||
|
const mkdirPath = pathSplit.slice(0, pathSplit.length - 2).join('/') || '/'
|
||||||
|
const fileApiSet = new Set()
|
||||||
|
const filePath = Path.join(mkdirPath, fileName)
|
||||||
|
if (!resultFile[filePath]) {
|
||||||
|
resultFile[filePath] = fileTemplate
|
||||||
|
}
|
||||||
|
for (const method in paths[_path]) {
|
||||||
|
const apiMeta = paths[_path][method]
|
||||||
|
const parameters = apiMeta.parameters || []
|
||||||
|
const formData = parameters.filter((item) => {
|
||||||
|
return item.in === 'formData'
|
||||||
|
})
|
||||||
|
const data = parameters.filter((item) => {
|
||||||
|
return item.in === 'body'
|
||||||
|
})
|
||||||
|
const params = parameters.filter((item) => {
|
||||||
|
return item.in === 'query'
|
||||||
|
})
|
||||||
|
resultFile[filePath] += functionCodeGener({
|
||||||
|
name: (() => {
|
||||||
|
const filterApiName = apiName.replace(/\.do$/g, '')
|
||||||
|
let result = Object.keys(paths[_path]).length > 1 ? `${method}_${filterApiName}` : filterApiName
|
||||||
|
if (fileApiSet.has(result)) {
|
||||||
|
let i = 1
|
||||||
|
while (fileApiSet.has(`${result}_${i}`)) {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
result = `${result}_${i}`
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
})(),
|
||||||
|
method,
|
||||||
|
url: path,
|
||||||
|
comment: apiMeta.summary,
|
||||||
|
data,
|
||||||
|
params,
|
||||||
|
formData,
|
||||||
|
requestType: (() => {
|
||||||
|
if (method !== 'get') {
|
||||||
|
if (formData.length > 0) {
|
||||||
|
return 'formdata'
|
||||||
|
} else {
|
||||||
|
return 'json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).catch((e) => {
|
||||||
|
console.warn(`无法读取api文档: ${apiScope.name}`)
|
||||||
|
console.warn(e.message)
|
||||||
|
})
|
||||||
|
})).then(() => {
|
||||||
|
for (const path in resultFile) {
|
||||||
|
mkdirsSync(Path.join(apiPath, path))
|
||||||
|
const filepath = Path.join(apiPath, path, 'index.js')
|
||||||
|
if (fs.existsSync(filepath) && fs.readFileSync(filepath).toString() !== resultFile[path]) {
|
||||||
|
fs.writeFileSync(filepath, resultFile[path])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}).catch((e) => { })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
var compressing = require('compressing')
|
const compressing = require('compressing')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const child_process = require('child_process')
|
const child_process = require('child_process')
|
||||||
|
const packageJson = require('../package.json')
|
||||||
function parseTime(time, format = 'yyyy-MM-dd hh:mm:ss') {
|
function parseTime(time, format = 'yyyy-MM-dd hh:mm:ss') {
|
||||||
const date = time instanceof Date ? time : new Date(time)
|
const date = time instanceof Date ? time : new Date(time)
|
||||||
|
|
||||||
|
|
@ -32,17 +32,72 @@ function parseTime(time, format = 'yyyy-MM-dd hh:mm:ss') {
|
||||||
* youfool
|
* youfool
|
||||||
*/
|
*/
|
||||||
class IncrePack {
|
class IncrePack {
|
||||||
constructor(options) {
|
|
||||||
this.options = options
|
|
||||||
}
|
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
|
if (process.env.VUE_APP_WEBPACK_CMD !== 'build') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const date = new Date()
|
||||||
const projectPath = path.join(__dirname, '../')
|
const projectPath = path.join(__dirname, '../')
|
||||||
const distPath = projectPath + 'dist'
|
const distPath = projectPath + 'dist'
|
||||||
compiler.hooks.done.tap('IncrePack', async (compilation, callback) => {
|
const versionPath = `${projectPath}src/version.js`
|
||||||
// 排除开发环境
|
let hash = '000000'
|
||||||
if (process.env.ENV !== 'development') {
|
try {
|
||||||
|
hash = child_process.execSync('git rev-parse HEAD').slice(0, 6)
|
||||||
const increName = `${this.options.name}.zip`
|
} catch (e) {
|
||||||
|
console.log('------------------读取版本Hash失败---------------')
|
||||||
|
console.warn(e)
|
||||||
|
}
|
||||||
|
const codeVersion = `${parseTime(date, 'yyyy-MM-dd hh:mm:ss')} ${hash} ${process.env.VUE_APP_ENVIRONMENT}`
|
||||||
|
compiler.hooks.beforeRun.tapAsync('SetVersion', async(compilation, callback) => {
|
||||||
|
const data = `/** 本文件由打包插件自动生成和修改 */\nexport default '${codeVersion}'\n`
|
||||||
|
fs.writeFileSync(versionPath, data)
|
||||||
|
callback()
|
||||||
|
})
|
||||||
|
compiler.hooks.done.tap('SetVersion', async(compilation) => {
|
||||||
|
const data = `/** 本文件由打包插件自动生成和修改 */\nexport default ''\n`
|
||||||
|
fs.writeFileSync(versionPath, data)
|
||||||
|
})
|
||||||
|
compiler.hooks.done.tap('IncrePack', async(compilation) => {
|
||||||
|
let versionJson = {
|
||||||
|
artifactId: packageJson.name,
|
||||||
|
version: packageJson.version,
|
||||||
|
appId: packageJson.appId,
|
||||||
|
codeId: packageJson.codeId,
|
||||||
|
codeVersion
|
||||||
|
}
|
||||||
|
if (packageJson.increApi) {
|
||||||
|
// 获取版本信息
|
||||||
|
try {
|
||||||
|
console.log('------------------正在写入升级记录---------------')
|
||||||
|
const res = await axios.default({
|
||||||
|
url: packageJson.increApi + '?appId=' + packageJson.appId + '&codeId=' + packageJson.codeId,
|
||||||
|
method: 'get',
|
||||||
|
timeout: 5000
|
||||||
|
})
|
||||||
|
const { code, data } = res.data
|
||||||
|
if (code === 0 && data) {
|
||||||
|
versionJson = {
|
||||||
|
...versionJson,
|
||||||
|
artifactId: packageJson.name,
|
||||||
|
upgradeId: data.upgradeId,
|
||||||
|
version: data.version,
|
||||||
|
releaseTime: data.releaseTime,
|
||||||
|
fromCommit: data.fromCommit,
|
||||||
|
untilCommit: data.untilCommit,
|
||||||
|
newFeatures: data.newFeatures,
|
||||||
|
repair: data.repair,
|
||||||
|
other: data.other
|
||||||
|
}
|
||||||
|
console.log('------------------写入升级记录成功---------------')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message)
|
||||||
|
console.log('------------------提交升级记录到远端失败---------------')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs.mkdirSync(distPath + '/increpack-config')
|
||||||
|
fs.writeFileSync(distPath + '/increpack-config/version.json', JSON.stringify(versionJson), 'utf8')
|
||||||
|
const increName = `${packageJson.name}-${process.env.VUE_APP_ENVIRONMENT}-${parseTime(date, 'yyyy-MM-dd')}-${hash}.zip`
|
||||||
// 打包压缩
|
// 打包压缩
|
||||||
const tempFile = projectPath + '/' + increName
|
const tempFile = projectPath + '/' + increName
|
||||||
compressing.zip.compressDir(distPath, tempFile, { ignoreBase: true })
|
compressing.zip.compressDir(distPath, tempFile, { ignoreBase: true })
|
||||||
|
|
@ -54,7 +109,6 @@ class IncrePack {
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
})
|
})
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@amap/amap-jsapi-loader": "^1.0.1",
|
"@amap/amap-jsapi-loader": "^1.0.1",
|
||||||
"@geoscene/core": "^4.29.10",
|
"@geoscene/core": "4.29.10",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"babel-polyfill": "^6.26.0",
|
"babel-polyfill": "^6.26.0",
|
||||||
"echarts": "^4.8.0",
|
"echarts": "^4.8.0",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue