mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.4 KiB
TypeScript
100 lines
2.4 KiB
TypeScript
3 years ago
|
import path from 'path';
|
||
|
import fs from 'fs-extra';
|
||
|
import AdmZip from 'adm-zip';
|
||
|
import crypto from 'crypto';
|
||
|
import { version } from '../package.json';
|
||
|
import ghpages from 'gh-pages';
|
||
3 years ago
|
import os from 'os';
|
||
|
|
||
|
/**
|
||
|
* 发布asar
|
||
|
*/
|
||
3 years ago
|
|
||
|
const hash = (data: Buffer, type = 'sha256') => {
|
||
|
const hmac = crypto.createHmac(type, 'hk4e');
|
||
|
hmac.update(data);
|
||
|
return hmac.digest('hex');
|
||
|
};
|
||
|
|
||
3 years ago
|
function createZip(localFilePath: string, dest: string) {
|
||
3 years ago
|
const zip = new AdmZip();
|
||
3 years ago
|
zip.addLocalFile(localFilePath);
|
||
3 years ago
|
zip.toBuffer();
|
||
|
zip.writeZip(dest);
|
||
|
}
|
||
3 years ago
|
const outputDir = path.resolve(__dirname, '../out/');
|
||
|
|
||
|
function getAsarFilePath() {
|
||
|
if (os.platform() === 'win32') {
|
||
|
return path.resolve(
|
||
|
outputDir,
|
||
|
'./prod/tailchat-desktop-win32-x64/resources/app.asar'
|
||
|
);
|
||
|
} else if (os.platform() === 'darwin') {
|
||
|
return path.resolve(
|
||
|
outputDir,
|
||
|
'./prod/tailchat-desktop.app/Contents/Resources/app.asar'
|
||
|
);
|
||
|
}
|
||
|
|
||
|
throw new Error('Not support');
|
||
|
}
|
||
3 years ago
|
|
||
|
async function createUpdateZipAndDeploy() {
|
||
3 years ago
|
const asarPath = getAsarFilePath();
|
||
|
if (!(await fs.pathExists(asarPath))) {
|
||
|
throw new Error('asar 文件不存在');
|
||
3 years ago
|
}
|
||
3 years ago
|
const updateDir = path.resolve(outputDir, './update');
|
||
|
const outputPath = path.resolve(updateDir, './tmp.zip');
|
||
|
await fs.ensureDir(updateDir);
|
||
|
await fs.emptyDir(updateDir);
|
||
3 years ago
|
|
||
3 years ago
|
console.log('开始创建更新包');
|
||
|
createZip(asarPath, outputPath);
|
||
3 years ago
|
|
||
|
const buffer = await fs.readFile(outputPath);
|
||
|
const sha256 = hash(buffer);
|
||
|
const hashName = sha256.slice(7, 12);
|
||
3 years ago
|
await fs.move(outputPath, path.resolve(updateDir, `${hashName}.zip`));
|
||
3 years ago
|
|
||
3 years ago
|
console.log('正在输出更新文件...');
|
||
|
await fs.outputJSON(path.resolve(updateDir, 'manifest.json'), {
|
||
3 years ago
|
active: true,
|
||
|
version,
|
||
|
from: '0.0.0',
|
||
|
name: `${hashName}.zip`,
|
||
|
hash: sha256,
|
||
|
date: new Date().valueOf(),
|
||
3 years ago
|
size: buffer.byteLength,
|
||
3 years ago
|
});
|
||
|
|
||
3 years ago
|
console.log('正在部署到远程...');
|
||
3 years ago
|
// 部署到github pages
|
||
|
await new Promise<void>((resolve, reject) => {
|
||
|
ghpages.publish(
|
||
3 years ago
|
updateDir,
|
||
3 years ago
|
{
|
||
|
repo: 'git@github.com:msgbyte/tailchat-archive.git',
|
||
|
branch: 'gh-pages',
|
||
|
dest: './desktop/update',
|
||
|
push: true,
|
||
|
history: false,
|
||
|
},
|
||
|
(err) => {
|
||
|
if (err) {
|
||
|
reject(err);
|
||
|
} else {
|
||
|
resolve();
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
});
|
||
3 years ago
|
|
||
|
console.log('完成');
|
||
3 years ago
|
}
|
||
|
|
||
|
// async function
|
||
|
|
||
|
createUpdateZipAndDeploy();
|