|
@@ -11,9 +11,10 @@ import OSS from 'ali-oss';
|
|
|
import cliProgress from 'cli-progress';
|
|
import cliProgress from 'cli-progress';
|
|
|
import { selectVersion } from './app.mjs';
|
|
import { selectVersion } from './app.mjs';
|
|
|
import { config } from './postConfig.mjs';
|
|
import { config } from './postConfig.mjs';
|
|
|
-import { readFileRange, compressZip, execAsync } from './utils.mjs';
|
|
|
|
|
|
|
+import { readFileRange, compressZip, execAsync, logError } from './utils.mjs';
|
|
|
import { dirname } from 'node:path';
|
|
import { dirname } from 'node:path';
|
|
|
import { fileURLToPath } from 'node:url';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
|
+import consola from 'consola';
|
|
|
|
|
|
|
|
//基础配置
|
|
//基础配置
|
|
|
//========================================
|
|
//========================================
|
|
@@ -46,17 +47,19 @@ async function saveConfig(postConfig) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function getUpdateInfo(postConfig) {
|
|
async function getUpdateInfo(postConfig) {
|
|
|
|
|
+ let lastUseGit = false;
|
|
|
let updateInfo = await input({ message: '输入更新信息', default: postConfig.lastUpdateInfo });
|
|
let updateInfo = await input({ message: '输入更新信息', default: postConfig.lastUpdateInfo });
|
|
|
if (updateInfo === 'git') {
|
|
if (updateInfo === 'git') {
|
|
|
- console.log('开始获取git提交信息');
|
|
|
|
|
|
|
+ consola.info('开始获取git提交信息');
|
|
|
|
|
+ lastUseGit = true;
|
|
|
updateInfo = await execAsync('git log -1 --pretty=format:"%h %s"');
|
|
updateInfo = await execAsync('git log -1 --pretty=format:"%h %s"');
|
|
|
- console.log('使用git提交信息 "' + updateInfo + '" 作为更新信息');
|
|
|
|
|
|
|
+ consola.info('使用git提交信息 "' + updateInfo + '" 作为更新信息');
|
|
|
}
|
|
}
|
|
|
- return updateInfo;
|
|
|
|
|
|
|
+ return { updateInfo, lastUseGit };
|
|
|
}
|
|
}
|
|
|
export async function uploadMulitPartLarge(axiosInstance, fileInfo, filePath) {
|
|
export async function uploadMulitPartLarge(axiosInstance, fileInfo, filePath) {
|
|
|
|
|
|
|
|
- console.log('开始分片上传');
|
|
|
|
|
|
|
+ consola.start('开始分片上传');
|
|
|
|
|
|
|
|
const multuploadInfo = (await axiosInstance.post('/update/update-large-token', {
|
|
const multuploadInfo = (await axiosInstance.post('/update/update-large-token', {
|
|
|
fileSize: fileInfo.size,
|
|
fileSize: fileInfo.size,
|
|
@@ -94,7 +97,7 @@ async function aliOSSMultipartUpload(client, fileName, uploadFile, progressCallb
|
|
|
const partSize = 10 * 1024 * 1024; // 分片大小,这里使用10MB
|
|
const partSize = 10 * 1024 * 1024; // 分片大小,这里使用10MB
|
|
|
const partCount = Math.ceil(fileInfo.size / partSize); // 计算总分片数
|
|
const partCount = Math.ceil(fileInfo.size / partSize); // 计算总分片数
|
|
|
|
|
|
|
|
- console.log(`开始分片上传到阿里OSS,文件大小: ${(fileInfo.size / 1024 / 1024).toFixed(2)}MB,分片数: ${partCount}`);
|
|
|
|
|
|
|
+ consola.start(`开始分片上传到阿里OSS,文件大小: ${(fileInfo.size / 1024 / 1024).toFixed(2)}MB,分片数: ${partCount}`);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
// 初始化分片上传
|
|
// 初始化分片上传
|
|
@@ -123,19 +126,19 @@ async function aliOSSMultipartUpload(client, fileName, uploadFile, progressCallb
|
|
|
progressCallback(progress);
|
|
progressCallback(progress);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- console.log(`已上传分片 ${i + 1}/${partCount} (${(progress * 100).toFixed(2)}%)`);
|
|
|
|
|
|
|
+ consola.info(`已上传分片 ${i + 1}/${partCount} (${(progress * 100).toFixed(2)}%)`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 完成分片上传
|
|
// 完成分片上传
|
|
|
await client.completeMultipartUpload(fileName, uploadId, parts);
|
|
await client.completeMultipartUpload(fileName, uploadId, parts);
|
|
|
|
|
|
|
|
- console.log('阿里OSS分片上传完成');
|
|
|
|
|
|
|
+ consola.success('阿里OSS分片上传完成');
|
|
|
|
|
|
|
|
// 获取上传后的文件URL
|
|
// 获取上传后的文件URL
|
|
|
const url = await client.generateObjectUrl(fileName);
|
|
const url = await client.generateObjectUrl(fileName);
|
|
|
return url;
|
|
return url;
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- console.error('阿里OSS分片上传失败:', error);
|
|
|
|
|
|
|
+ logError('阿里OSS分片上传失败:', error);
|
|
|
throw error;
|
|
throw error;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -146,7 +149,7 @@ async function aliOSSMultipartUpload(client, fileName, uploadFile, progressCallb
|
|
|
export async function postAppUpdate(axiosInstance, param) {
|
|
export async function postAppUpdate(axiosInstance, param) {
|
|
|
const postConfig = await getConfig();
|
|
const postConfig = await getConfig();
|
|
|
const { versionId, versionName } = await selectVersion(postConfig.lastVersion);
|
|
const { versionId, versionName } = await selectVersion(postConfig.lastVersion);
|
|
|
- const updateInfo = await getUpdateInfo(postConfig);
|
|
|
|
|
|
|
+ const { updateInfo, lastUseGit } = await getUpdateInfo(postConfig);
|
|
|
|
|
|
|
|
const serverConfig = await axiosInstance.post('/update/update-post', {
|
|
const serverConfig = await axiosInstance.post('/update/update-post', {
|
|
|
config: {
|
|
config: {
|
|
@@ -159,7 +162,7 @@ export async function postAppUpdate(axiosInstance, param) {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
postConfig.lastVersion = versionId;
|
|
postConfig.lastVersion = versionId;
|
|
|
- postConfig.lastUpdateInfo = updateInfo;
|
|
|
|
|
|
|
+ postConfig.lastUpdateInfo = lastUseGit ? 'git': updateInfo;
|
|
|
postConfig.lastTodaySubVersion++;
|
|
postConfig.lastTodaySubVersion++;
|
|
|
|
|
|
|
|
const updateSource = (await select({
|
|
const updateSource = (await select({
|
|
@@ -201,15 +204,15 @@ export async function postAppUpdate(axiosInstance, param) {
|
|
|
updateInfo,
|
|
updateInfo,
|
|
|
versionCode: versionCode
|
|
versionCode: versionCode
|
|
|
})).data;
|
|
})).data;
|
|
|
- console.log('上传成功');
|
|
|
|
|
- console.log('新更新ID: ' + result.updateId);
|
|
|
|
|
|
|
+ consola.success('上传成功');
|
|
|
|
|
+ consola.info('新更新ID: ' + result.updateId);
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
- console.error('上传失败', e);
|
|
|
|
|
|
|
+ logError('上传失败', e);
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- console.error('错误的选择');
|
|
|
|
|
|
|
+ logError('错误的选择');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -218,11 +221,11 @@ export async function postAppUpdate(axiosInstance, param) {
|
|
|
try {
|
|
try {
|
|
|
await access(uploadFile, constants.R_OK)
|
|
await access(uploadFile, constants.R_OK)
|
|
|
} catch {
|
|
} catch {
|
|
|
- console.error(`Failed to access ${uploadFile}, did you created it?`);
|
|
|
|
|
|
|
+ logError(`Failed to access ${uploadFile}, did you created it?`);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- console.log('开始上传');
|
|
|
|
|
|
|
+ consola.start('开始上传');
|
|
|
|
|
|
|
|
//小于8mb则小文件上传,否则使用阿里OSS上传
|
|
//小于8mb则小文件上传,否则使用阿里OSS上传
|
|
|
const fileInfo = await stat(uploadFile);
|
|
const fileInfo = await stat(uploadFile);
|
|
@@ -246,10 +249,10 @@ export async function postAppUpdate(axiosInstance, param) {
|
|
|
const result = (await axiosInstance.post('/update/update-post', formData, {
|
|
const result = (await axiosInstance.post('/update/update-post', formData, {
|
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
|
})).data;
|
|
})).data;
|
|
|
- console.log('上传成功');
|
|
|
|
|
- console.log('新更新ID: ' + result.updateId);
|
|
|
|
|
|
|
+ consola.success('上传成功');
|
|
|
|
|
+ consola.info('新更新ID: ' + result.updateId);
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
- console.error('上传失败', e);
|
|
|
|
|
|
|
+ logError('上传失败', e);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
@@ -281,7 +284,7 @@ export async function postAppUpdate(axiosInstance, param) {
|
|
|
|
|
|
|
|
//小于96mb则直接上传,否则分片上传
|
|
//小于96mb则直接上传,否则分片上传
|
|
|
|
|
|
|
|
- console.log('Start upload to ali oss');
|
|
|
|
|
|
|
+ consola.start('Start upload to ali oss');
|
|
|
|
|
|
|
|
let returnUrl = '';
|
|
let returnUrl = '';
|
|
|
if (fileInfo.size < 96 * 1024 * 1024) {
|
|
if (fileInfo.size < 96 * 1024 * 1024) {
|
|
@@ -302,9 +305,9 @@ export async function postAppUpdate(axiosInstance, param) {
|
|
|
ossPublic: returnUrl,
|
|
ossPublic: returnUrl,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- console.log('Upload to ali oss done');
|
|
|
|
|
|
|
+ consola.success('Upload to ali oss done');
|
|
|
} else {
|
|
} else {
|
|
|
- console.error('错误的 uploadAppType 配置 ' + serverConfig.uploadAppType);
|
|
|
|
|
|
|
+ logError('错误的 uploadAppType 配置 ' + serverConfig.uploadAppType);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -323,10 +326,10 @@ export async function postAppUpdate(axiosInstance, param) {
|
|
|
fileName
|
|
fileName
|
|
|
},
|
|
},
|
|
|
})).data;
|
|
})).data;
|
|
|
- console.log('上传成功');
|
|
|
|
|
- console.log('新更新ID: ' + result.updateId);
|
|
|
|
|
|
|
+ consola.success('上传成功');
|
|
|
|
|
+ consola.info('新更新ID: ' + result.updateId);
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
- console.error('上传失败', e);
|
|
|
|
|
|
|
+ logError('上传失败', e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -340,10 +343,10 @@ export async function postWebUpdate(axiosInstance, param) {
|
|
|
|
|
|
|
|
const postConfig = await getConfig();
|
|
const postConfig = await getConfig();
|
|
|
const { versionId, versionName } = await selectVersion(postConfig.lastVersion);
|
|
const { versionId, versionName } = await selectVersion(postConfig.lastVersion);
|
|
|
- const updateInfo = await getUpdateInfo(postConfig);
|
|
|
|
|
|
|
+ const { updateInfo, lastUseGit } = await getUpdateInfo(postConfig);
|
|
|
|
|
|
|
|
postConfig.lastVersion = versionId;
|
|
postConfig.lastVersion = versionId;
|
|
|
- postConfig.lastUpdateInfo = updateInfo;
|
|
|
|
|
|
|
+ postConfig.lastUpdateInfo = lastUseGit ? 'git': updateInfo;
|
|
|
postConfig.lastTodaySubVersion++;
|
|
postConfig.lastTodaySubVersion++;
|
|
|
|
|
|
|
|
await axiosInstance.post('/update/update-post', { config: { type: 1, test: true, versionId, uploadWebConfig: config.uploadWebConfig, submitKey: config.submitKey } });
|
|
await axiosInstance.post('/update/update-post', { config: { type: 1, test: true, versionId, uploadWebConfig: config.uploadWebConfig, submitKey: config.submitKey } });
|
|
@@ -357,9 +360,9 @@ export async function postWebUpdate(axiosInstance, param) {
|
|
|
await saveConfig(postConfig);
|
|
await saveConfig(postConfig);
|
|
|
|
|
|
|
|
if (!skipBuild && config.buildWebCommand) {
|
|
if (!skipBuild && config.buildWebCommand) {
|
|
|
- console.log('正在执行构建...');
|
|
|
|
|
|
|
+ consola.start('正在执行构建...');
|
|
|
await execAsync(config.buildWebCommand);
|
|
await execAsync(config.buildWebCommand);
|
|
|
- console.log('构建完成');
|
|
|
|
|
|
|
+ consola.success('构建完成');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const distDir = path.resolve(__dirname, config.buildWebOutDir);
|
|
const distDir = path.resolve(__dirname, config.buildWebOutDir);
|
|
@@ -367,7 +370,7 @@ export async function postWebUpdate(axiosInstance, param) {
|
|
|
try {
|
|
try {
|
|
|
await access(distDir, constants.R_OK)
|
|
await access(distDir, constants.R_OK)
|
|
|
} catch {
|
|
} catch {
|
|
|
- console.error(`Failed to access ${distDir}`);
|
|
|
|
|
|
|
+ logError(`Failed to access ${distDir}`);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -375,11 +378,11 @@ export async function postWebUpdate(axiosInstance, param) {
|
|
|
const skipFiles = config?.buildWebOptions?.skipFiles ?? [];
|
|
const skipFiles = config?.buildWebOptions?.skipFiles ?? [];
|
|
|
|
|
|
|
|
if (!skipBuild) {
|
|
if (!skipBuild) {
|
|
|
- console.log('开始压缩zip...');
|
|
|
|
|
|
|
+ consola.start('开始压缩zip...');
|
|
|
await compressZip(distDir, outputPath, skipFiles);
|
|
await compressZip(distDir, outputPath, skipFiles);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- console.log('开始上传zip');
|
|
|
|
|
|
|
+ consola.start('开始上传zip');
|
|
|
|
|
|
|
|
let success = false;
|
|
let success = false;
|
|
|
|
|
|
|
@@ -407,15 +410,15 @@ export async function postWebUpdate(axiosInstance, param) {
|
|
|
const result = (await axiosInstance.post('/update/update-post', formData, {
|
|
const result = (await axiosInstance.post('/update/update-post', formData, {
|
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
|
})).data;
|
|
})).data;
|
|
|
- console.log('上传成功');
|
|
|
|
|
- console.log('新更新ID: ' + result.updateId);
|
|
|
|
|
|
|
+ consola.success('上传成功');
|
|
|
|
|
+ consola.info('新更新ID: ' + result.updateId);
|
|
|
success = true;
|
|
success = true;
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
- console.error('上传失败', e);
|
|
|
|
|
|
|
+ logError('上传失败', e);
|
|
|
}
|
|
}
|
|
|
if (!success || noDelete)
|
|
if (!success || noDelete)
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
- console.log('删除zip');
|
|
|
|
|
|
|
+ consola.info('删除zip');
|
|
|
await unlink(outputPath);
|
|
await unlink(outputPath);
|
|
|
}
|
|
}
|