refactor: 增量更新

pull/67/head
xiaojunnuo 4 years ago
parent 52c07106b9
commit 3396664443

@ -0,0 +1,21 @@
const path = require('path')
const pkg = require('../package.json')
const fs = require('fs')
function appendIntro (context, systemType, latest) {
const partUpdateFile = `update-${systemType}-${pkg.version}.zip`
const partUpdateUrl = context.configuration.publish.url + partUpdateFile
const latestFilePath = path.join(context.outDir, latest)
fs.appendFile(latestFilePath, `\npartPackage: ${partUpdateUrl}\nreleaseNotes: \n - 升级日志`, (err) => {
if (err) {
console.log('修改latest 失败')
}
})
}
exports.default = async function (context) {
console.log('context222', context)
appendIntro(context, 'mac', 'latest-mac.yml')
appendIntro(context, 'win', 'latest.yml')
}

@ -1,29 +1,19 @@
const path = require('path')
const AdmZip = require('adm-zip')
const pkg = require('../package.json')
const fs = require('fs')
exports.default = async function (context) {
console.log('context', context)
let targetPath
let latest = null
let systemType = ''
if (context.packager.platform.nodeName === 'darwin') {
targetPath = path.join(context.appOutDir, `${context.packager.appInfo.productName}.app/Contents/Resources`)
latest = 'latest-mac.yml'
systemType = 'mac'
} else {
targetPath = path.join(context.appOutDir, './resources')
latest = 'latest.yml'
systemType = 'win'
}
const zip = new AdmZip()
zip.addLocalFolder(targetPath)
const partUpdateFile = `update-${pkg.version}.zip`
const partUpdateFile = `update-${systemType}-${pkg.version}.zip`
zip.writeZip(path.join(context.outDir, partUpdateFile))
const partUpdateUrl = 'http://dev-sidecar.docmirror.cn/update/' + partUpdateFile
const latestFilePath = path.join(context.outDir, latest)
fs.appendFile(latestFilePath, `\npartPackage: ${partUpdateUrl}\nreleaseNotes: \n - 升级日志`, (err) => {
if (err) {
console.log('修改latest 失败')
}
})
}

@ -210,7 +210,7 @@ if (!isFirstInstance) {
}
try {
createWindow()
const context = { win, app, beforeQuit, ipcMain, dialog, log }
const context = { win, app, beforeQuit, quit, ipcMain, dialog, log }
backend.install(context) // 模块安装
} catch (err) {
log.info('err', err)

@ -7,6 +7,7 @@ import progress from 'request-progress'
import fs from 'fs'
import AdmZip from 'adm-zip'
import logger from '../../utils/util.log'
import appPathUtil from '../../utils/util.apppath'
// eslint-disable-next-line no-unused-vars
const isMac = process.platform === 'darwin'
@ -33,7 +34,7 @@ function downloadFile (uri, filePath, onProgress, onSuccess, onError) {
}
// 检测更新在你想要检查更新的时候执行renderer事件触发后的操作自行编写
function updateHandle (app, win, beforeQuit, log) {
function updateHandle (app, win, beforeQuit, quit, log) {
// // 更新前,删除本地安装包 ↓
// const updaterCacheDirName = 'dev-sidecar-updater'
// const updatePendingPath = path.join(autoUpdater.app.baseCachePath, updaterCacheDirName, 'pending')
@ -58,9 +59,9 @@ function updateHandle (app, win, beforeQuit, log) {
let partPackagePath = null
function downloadPart (app, value) {
const appPath = app.getAppPath()
const appPath = appPathUtil.getAppRootPath()
const fileDir = path.join(appPath, 'update')
console.log('fileDir', fileDir)
logger.info('download dir', fileDir)
try {
fs.accessSync(fileDir, fs.constants.F_OK)
} catch (e) {
@ -84,8 +85,8 @@ function updateHandle (app, win, beforeQuit, log) {
})
}
function updatePart (app, value, partPackagePath) {
const appPath = app.getAppPath()
function updatePart (app, value, partPackagePath, quit) {
const appPath = appPathUtil.getAppRootPath()
const target = path.join(appPath, 'resources')
log.info('开始解压缩,安装升级包', partPackagePath, target)
// 解压缩
@ -93,7 +94,7 @@ function updateHandle (app, win, beforeQuit, log) {
zip.extractAllTo(target, true)
log.info('安装完成重启app')
app.relaunch()
app.quit()
quit()
}
autoUpdater.on('error', function (error) {
@ -169,7 +170,7 @@ function updateHandle (app, win, beforeQuit, log) {
export default {
install (context) {
const { app, win, beforeQuit, log } = context
const { app, win, beforeQuit, quit, log } = context
if (process.env.NODE_ENV === 'development') {
Object.defineProperty(app, 'isPackaged', {
get () {
@ -179,6 +180,6 @@ export default {
// updateUrl = 'http://dev-sidecar.docmirror.cn/update/'
// updateUrl = 'http://localhost/dev-sidecar/'
}
updateHandle(app, win, beforeQuit, log)
updateHandle(app, win, beforeQuit, quit, log)
}
}

@ -0,0 +1,13 @@
import path from 'path'
// const isDevelopment = process.env.NODE_ENV !== 'production'
export default {
getAppRootPath () {
// if (isDevelopment) {
// return app.getAppPath()
// } else {
// return path.join(app.getAppPath(), '../../')
// }
return path.resolve('.')
}
}

@ -36,7 +36,7 @@
</a-layout-content>
<a-layout-footer>
<div class="footer">
©2020-2021 docmirror.cn by Greper
©2020-2021 docmirror.cn by Greper <span>{{info.version}}</span>
</div>
</a-layout-footer>
</a-layout>
@ -52,6 +52,7 @@ export default {
},
data () {
return {
info: {},
menus: undefined
}
},
@ -59,6 +60,9 @@ export default {
},
created () {
this.menus = createMenus(this)
this.$api.info.get().then(ret => {
this.info = ret
})
},
methods: {
handleClick (e) {

@ -36,6 +36,7 @@ module.exports = {
mainProcessWatch: ['src/bridge', 'src/*.js', 'node_modules/dev-sidecar/src'],
builderOptions: {
afterPack: './pkg/after-pack.js',
afterAllArtifactBuild: './pkg/after-all-artifact-build.js',
// builderOptions: {
// publish: ['github']// 此处写入github 就好,不用添加其他内容
// },

Loading…
Cancel
Save