feat: 插件补充

This commit is contained in:
陶林 2024-12-17 09:23:24 +08:00
parent cb0e9763f0
commit 8a443720fa
4 changed files with 408 additions and 31 deletions

BIN
logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 KiB

After

Width:  |  Height:  |  Size: 930 KiB

327
package-lock.json generated
View File

@ -19,20 +19,30 @@
"consola": "^3.2.3",
"cordova": "^12.0.0",
"cordova-android": "^13.0.0",
"cordova-plugin-androidx-adapter": "^1.1.3",
"cordova-plugin-app-version": "^0.1.14",
"cordova-plugin-battery-status": "^2.0.3",
"cordova-plugin-camera": "^2.4.1",
"cordova-plugin-compat": "^1.2.0",
"cordova-plugin-device": "^2.1.0",
"cordova-plugin-dialogs": "^2.0.2",
"cordova-plugin-file": "^4.3.3",
"cordova-plugin-file-opener2": "^4.0.0",
"cordova-plugin-file-transfer-jsg": "^2.0.0",
"cordova-plugin-geolocation": "^2.4.3",
"cordova-plugin-inappbrowser": "^4.1.0",
"cordova-plugin-jbprint-jsg": "^1.0.3",
"cordova-plugin-media": "^2.4.1",
"cordova-plugin-media-capture": "^1.4.3",
"cordova-plugin-network-information": "^3.0.0",
"cordova-plugin-screen-orientation": "^3.0.4",
"cordova-plugin-statusbar": "^3.0.0",
"cordova-plugin-vibration": "^3.1.1",
"es6-promise-plugin": "^4.2.2",
"eslint": "^9.17.0",
"fast-xml-parser": "^4.5.1",
"phonegap-plugin-barcodescanner-fix": "^8.1.1",
"phonegap-plugin-barcodescanner-jsg": "^8.1.2",
"picocolors": "^1.1.1",
"tsx": "^4.19.2",
"typeorm": "^0.3.20",
@ -2837,6 +2847,17 @@
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
}
},
"node_modules/cordova-plugin-androidx-adapter": {
"version": "1.1.3",
"resolved": "https://registry.npmmirror.com/cordova-plugin-androidx-adapter/-/cordova-plugin-androidx-adapter-1.1.3.tgz",
"integrity": "sha512-W1SImn0cCCvOSTSfWWp5TnanIQrSuh2Bch+dcZXIzEn0km3Qb7VryeAqHhgBQYwwzC5Ollk1DtUAk/AJSojuZA==",
"dev": true,
"license": "MIT",
"dependencies": {
"q": "^1.5.1",
"recursive-readdir": "^2.2.2"
}
},
"node_modules/cordova-plugin-app-version": {
"version": "0.1.14",
"resolved": "https://registry.npmmirror.com/cordova-plugin-app-version/-/cordova-plugin-app-version-0.1.14.tgz",
@ -2905,6 +2926,20 @@
}
}
},
"node_modules/cordova-plugin-dialogs": {
"version": "2.0.2",
"resolved": "https://registry.npmmirror.com/cordova-plugin-dialogs/-/cordova-plugin-dialogs-2.0.2.tgz",
"integrity": "sha512-FUHI6eEVeoz2VkxbF0P56QlUQLGzXcvw3i4xuXyM9gEct6Y+FA3Xzgl2pJTZcTg5wRqLWzN08kgNoHPkom15pw==",
"dev": true,
"license": "Apache-2.0",
"engines": {
"cordovaDependencies": {
"3.0.0": {
"cordova": ">100"
}
}
}
},
"node_modules/cordova-plugin-file": {
"version": "4.3.3",
"resolved": "https://registry.npmmirror.com/cordova-plugin-file/-/cordova-plugin-file-4.3.3.tgz",
@ -2919,6 +2954,40 @@
}
}
},
"node_modules/cordova-plugin-file-opener2": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/cordova-plugin-file-opener2/-/cordova-plugin-file-opener2-4.0.0.tgz",
"integrity": "sha512-+O+MMldI2k5Kjoa62KXYxnZQIGE4k5VfoCmmOUmaV5XM6U6euiiKMfCkuMrOrdAFb1C5Jsx+SuBHbWx1NEB5lw==",
"dev": true,
"license": "MIT",
"engines": {
"cordovaDependencies": {
"2.0.0": {
"cordova": ">=6.0.0"
},
"3.0.0": {
"cordova": ">=7.0.0"
},
"4.0.0": {
"cordova-android": ">=10.0.0"
}
}
}
},
"node_modules/cordova-plugin-file-transfer-jsg": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/cordova-plugin-file-transfer-jsg/-/cordova-plugin-file-transfer-jsg-2.0.0.tgz",
"integrity": "sha512-BoUVD6CtRpGKTy2M+qESHM2Fd7QYSfjXWLkmR+BXkU/II/XsIE1sHzcv6QJNznSPiZ9FDGoke3Y+BRWTsh9m+A==",
"dev": true,
"license": "Apache-2.0",
"engines": {
"cordovaDependencies": {
"3.0.0": {
"cordova": ">100"
}
}
}
},
"node_modules/cordova-plugin-geolocation": {
"version": "2.4.3",
"resolved": "https://registry.npmmirror.com/cordova-plugin-geolocation/-/cordova-plugin-geolocation-2.4.3.tgz",
@ -2933,6 +3002,34 @@
}
}
},
"node_modules/cordova-plugin-inappbrowser": {
"version": "4.1.0",
"resolved": "https://registry.npmmirror.com/cordova-plugin-inappbrowser/-/cordova-plugin-inappbrowser-4.1.0.tgz",
"integrity": "sha512-jPvcwDx2/L5ZbVG69NT2xmlG1E+MljRxkdsFpgj/5aoaF4oPqxg44J/bYxJNWgQtGnRSRWoqCRmU7FgmmMNMxA==",
"dev": true,
"license": "Apache-2.0",
"engines": {
"cordovaDependencies": {
"0.2.3": {
"cordova": ">=3.1.0"
},
"4.0.0": {
"cordova": ">=3.1.0",
"cordova-ios": ">=4.0.0"
},
"5.0.0": {
"cordova": ">100"
}
}
}
},
"node_modules/cordova-plugin-jbprint-jsg": {
"version": "1.0.3",
"resolved": "https://registry.npmmirror.com/cordova-plugin-jbprint-jsg/-/cordova-plugin-jbprint-jsg-1.0.3.tgz",
"integrity": "sha512-zQukMsO1EzGUezZP5TPT2gwWrRVBpAqm4j+//1tOKvgksbceOweHB7u/jXO1Z2ehu9uBLAovtf9CseMBqU7iDg==",
"dev": true,
"license": "MIT"
},
"node_modules/cordova-plugin-media": {
"version": "2.4.1",
"resolved": "https://registry.npmmirror.com/cordova-plugin-media/-/cordova-plugin-media-2.4.1.tgz",
@ -2947,6 +3044,37 @@
}
}
},
"node_modules/cordova-plugin-media-capture": {
"version": "1.4.3",
"resolved": "https://registry.npmmirror.com/cordova-plugin-media-capture/-/cordova-plugin-media-capture-1.4.3.tgz",
"integrity": "sha512-3QI5Hd6sXR/q7uVSCnPwagIWk1yASl35pnV5oGe/K2BOAxvrLrZX76sMudAQpAhY3zs+L7pPTJi9OO9T8x5kmw==",
"dev": true,
"license": "Apache-2.0",
"engines": {
"cordovaDependencies": {
"2.0.0": {
"cordova": ">100"
}
}
}
},
"node_modules/cordova-plugin-network-information": {
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/cordova-plugin-network-information/-/cordova-plugin-network-information-3.0.0.tgz",
"integrity": "sha512-bBtP3PxIX8vshsfR0+F6co2e2cFLgjt18yKIdigzMwk6ANudWQ72RB3g2qMPyT6fBDWmUyE1Qd+bKQB/fZtQwQ==",
"dev": true,
"license": "Apache-2.0",
"engines": {
"cordovaDependencies": {
"3.0.0": {
"cordova": ">=9"
},
"4.0.0": {
"cordova": ">100"
}
}
}
},
"node_modules/cordova-plugin-screen-orientation": {
"version": "3.0.4",
"resolved": "https://registry.npmmirror.com/cordova-plugin-screen-orientation/-/cordova-plugin-screen-orientation-3.0.4.tgz",
@ -5221,6 +5349,16 @@
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/interpret": {
"version": "1.4.0",
"resolved": "https://registry.npmmirror.com/interpret/-/interpret-1.4.0.tgz",
"integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/ip-address": {
"version": "9.0.5",
"resolved": "https://registry.npmmirror.com/ip-address/-/ip-address-9.0.5.tgz",
@ -6833,6 +6971,16 @@
"node": ">= 0.8.0"
}
},
"node_modules/os-homedir": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/os-homedir/-/os-homedir-1.0.2.tgz",
"integrity": "sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/os-name": {
"version": "4.0.1",
"resolved": "https://registry.npmmirror.com/os-name/-/os-name-4.0.1.tgz",
@ -6860,6 +7008,18 @@
"node": ">=0.10.0"
}
},
"node_modules/osenv": {
"version": "0.1.5",
"resolved": "https://registry.npmmirror.com/osenv/-/osenv-0.1.5.tgz",
"integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==",
"deprecated": "This package is no longer supported.",
"dev": true,
"license": "ISC",
"dependencies": {
"os-homedir": "^1.0.0",
"os-tmpdir": "^1.0.0"
}
},
"node_modules/p-finally": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/p-finally/-/p-finally-1.0.0.tgz",
@ -7132,6 +7292,106 @@
"dev": true,
"license": "MIT"
},
"node_modules/phonegap-plugin-barcodescanner-fix": {
"version": "8.1.1",
"resolved": "https://registry.npmmirror.com/phonegap-plugin-barcodescanner-fix/-/phonegap-plugin-barcodescanner-fix-8.1.1.tgz",
"integrity": "sha512-m9eZmooxUqLEYGoP3+of5eNLZ2Wgh+4J7buUQPqM4XGDZMv/2bjK1MeGbBj8Aa8Py+DI/djtxySTCPvhGGCW0A==",
"dev": true,
"license": "MIT",
"dependencies": {
"nopt": "^4.0.1",
"shelljs": "^0.8.3"
},
"engines": {
"cordovaDependencies": {
"<7.0.0": {
"cordova-android": "<6.3.0"
},
"7.0.0": {
"cordova-android": ">=6.3.0"
},
"7.1.0": {
"cordova": ">=7.1.0",
"cordova-android": ">=6.3.0"
},
"8.0.0": {
"cordova": ">=7.1.0",
"cordova-android": ">=6.3.0"
}
}
}
},
"node_modules/phonegap-plugin-barcodescanner-fix/node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
"dev": true,
"license": "ISC"
},
"node_modules/phonegap-plugin-barcodescanner-fix/node_modules/nopt": {
"version": "4.0.3",
"resolved": "https://registry.npmmirror.com/nopt/-/nopt-4.0.3.tgz",
"integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==",
"dev": true,
"license": "ISC",
"dependencies": {
"abbrev": "1",
"osenv": "^0.1.4"
},
"bin": {
"nopt": "bin/nopt.js"
}
},
"node_modules/phonegap-plugin-barcodescanner-jsg": {
"version": "8.1.2",
"resolved": "https://registry.npmmirror.com/phonegap-plugin-barcodescanner-jsg/-/phonegap-plugin-barcodescanner-jsg-8.1.2.tgz",
"integrity": "sha512-nzUZjzMQXgTi6Lfh99ylub+ogEXn8uJWLLzDa/RNRP+dwnW/NazibGIsh4hmdrMT3glLb0b2wvM9zTQbFfQjQA==",
"dev": true,
"license": "MIT",
"dependencies": {
"nopt": "^4.0.1",
"shelljs": "^0.8.3"
},
"engines": {
"cordovaDependencies": {
"<7.0.0": {
"cordova-android": "<6.3.0"
},
"7.0.0": {
"cordova-android": ">=6.3.0"
},
"7.1.0": {
"cordova": ">=7.1.0",
"cordova-android": ">=6.3.0"
},
"8.0.0": {
"cordova": ">=7.1.0",
"cordova-android": ">=6.3.0"
}
}
}
},
"node_modules/phonegap-plugin-barcodescanner-jsg/node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
"dev": true,
"license": "ISC"
},
"node_modules/phonegap-plugin-barcodescanner-jsg/node_modules/nopt": {
"version": "4.0.3",
"resolved": "https://registry.npmmirror.com/nopt/-/nopt-4.0.3.tgz",
"integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==",
"dev": true,
"license": "ISC",
"dependencies": {
"abbrev": "1",
"osenv": "^0.1.4"
},
"bin": {
"nopt": "bin/nopt.js"
}
},
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz",
@ -7618,6 +7878,55 @@
"node": ">= 6"
}
},
"node_modules/rechoir": {
"version": "0.6.2",
"resolved": "https://registry.npmmirror.com/rechoir/-/rechoir-0.6.2.tgz",
"integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==",
"dev": true,
"dependencies": {
"resolve": "^1.1.6"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/recursive-readdir": {
"version": "2.2.3",
"resolved": "https://registry.npmmirror.com/recursive-readdir/-/recursive-readdir-2.2.3.tgz",
"integrity": "sha512-8HrF5ZsXk5FAH9dgsx3BlUer73nIhuj+9OrQwEbLTPOBzGkL1lsFCR01am+v+0m2Cmbs1nP12hLDl5FA7EszKA==",
"dev": true,
"license": "MIT",
"dependencies": {
"minimatch": "^3.0.5"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/recursive-readdir/node_modules/brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmmirror.com/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"license": "MIT",
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"node_modules/recursive-readdir/node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmmirror.com/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dev": true,
"license": "ISC",
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/reflect-metadata": {
"version": "0.2.2",
"resolved": "https://registry.npmmirror.com/reflect-metadata/-/reflect-metadata-0.2.2.tgz",
@ -8052,6 +8361,24 @@
"node": ">=8"
}
},
"node_modules/shelljs": {
"version": "0.8.5",
"resolved": "https://registry.npmmirror.com/shelljs/-/shelljs-0.8.5.tgz",
"integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==",
"dev": true,
"license": "BSD-3-Clause",
"dependencies": {
"glob": "^7.0.0",
"interpret": "^1.0.0",
"rechoir": "^0.6.2"
},
"bin": {
"shjs": "bin/shjs"
},
"engines": {
"node": ">=4"
}
},
"node_modules/side-channel": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/side-channel/-/side-channel-1.1.0.tgz",

View File

@ -26,20 +26,30 @@
"consola": "^3.2.3",
"cordova": "^12.0.0",
"cordova-android": "^13.0.0",
"cordova-plugin-androidx-adapter": "^1.1.3",
"cordova-plugin-app-version": "^0.1.14",
"cordova-plugin-battery-status": "^2.0.3",
"cordova-plugin-camera": "^2.4.1",
"cordova-plugin-compat": "^1.2.0",
"cordova-plugin-device": "^2.1.0",
"cordova-plugin-dialogs": "^2.0.2",
"cordova-plugin-file": "^4.3.3",
"cordova-plugin-file-opener2": "^4.0.0",
"cordova-plugin-file-transfer-jsg": "^2.0.0",
"cordova-plugin-geolocation": "^2.4.3",
"cordova-plugin-inappbrowser": "^4.1.0",
"cordova-plugin-jbprint-jsg": "^1.0.3",
"cordova-plugin-media": "^2.4.1",
"cordova-plugin-media-capture": "^1.4.3",
"cordova-plugin-network-information": "^3.0.0",
"cordova-plugin-screen-orientation": "^3.0.4",
"cordova-plugin-statusbar": "^3.0.0",
"cordova-plugin-vibration": "^3.1.1",
"es6-promise-plugin": "^4.2.2",
"eslint": "^9.17.0",
"fast-xml-parser": "^4.5.1",
"phonegap-plugin-barcodescanner-fix": "^8.1.1",
"phonegap-plugin-barcodescanner-jsg": "^8.1.2",
"picocolors": "^1.1.1",
"tsx": "^4.19.2",
"typeorm": "^0.3.20",
@ -58,7 +68,13 @@
"cordova-plugin-media": {},
"cordova-plugin-vibration": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-screen-orientation": {}
"cordova-plugin-screen-orientation": {},
"cordova-plugin-dialogs": {},
"cordova-plugin-jbprint-jsg": {},
"cordova-plugin-media-capture": {},
"cordova-plugin-network-information": {},
"cordova-plugin-androidx-adapter": {},
"cordova-plugin-inappbrowser": {}
}
},
"dependencies": {

View File

@ -13,9 +13,17 @@ const ErrorMessages = {
FILE_NOT_EXIST: '源文件不存在',
DOWNLOAD_FAILED: '文件下载失败:',
COPY_FAILED: '文件复制失败:',
CONVERT_FAILED: '文件转换失败:',
UNEXPECTED_ERROR: '发生意外错误:',
};
// 配置常量
const CONFIG = {
ALLOWED_EXTENSIONS: ['.png', '.jpg', '.jpeg', '.gif'],
OUTPUT_FILENAME: 'logo.png',
TEMP_PREFIX: 'temp-logo-'
};
/**
* URL下载文件到指定目录
* @param url URL地址
@ -26,7 +34,8 @@ async function downloadFile(url: string, destination: string): Promise<void> {
const response = await axios({
url,
method: 'GET',
responseType: 'stream'
responseType: 'stream',
timeout: 10000 // 10秒超时
});
const writer = fs.createWriteStream(destination);
@ -43,22 +52,22 @@ async function downloadFile(url: string, destination: string): Promise<void> {
}
/**
*
* PNG格式
* @param source
* @param destination
* @param destination
*/
function copy(source: string, destination: string): void {
function convertToPng(source: string, destination: string): void {
try {
execSync(`cp ${source} ${destination}`);
// 使用 ImageMagick 转换图片格式
execSync(`convert "${source}" "${destination}"`);
} catch (error) {
throw new Error(`${ErrorMessages.COPY_FAILED} ${error.message}`);
throw new Error(`${ErrorMessages.CONVERT_FAILED} ${error.message}`);
}
}
/**
* URL
* @param string
* @returns boolean URL
*/
function isValidUrl(string: string): boolean {
try {
@ -72,18 +81,32 @@ function isValidUrl(string: string): boolean {
/**
*
* @param filePath
* @returns boolean
*/
function isValidImageFile(filePath: string): boolean {
const validExtensions = ['.png', '.jpg', '.jpeg', '.gif'];
const ext = path.extname(filePath).toLowerCase();
return validExtensions.includes(ext);
return CONFIG.ALLOWED_EXTENSIONS.includes(ext);
}
/**
*
* @param filePath
*/
function cleanupTempFile(filePath: string): void {
if (fs.existsSync(filePath)) {
try {
fs.unlinkSync(filePath);
} catch (error) {
consola.warn('清理临时文件失败:', error.message);
}
}
}
/**
* - Logo替换逻辑
*/
async function main(): Promise<void> {
const tempFiles: string[] = [];
try {
// 获取命令行参数中的源文件路径
const sourcePath = process.argv[2];
@ -93,33 +116,34 @@ async function main(): Promise<void> {
}
const baseDir: string = resolve('./');
const destinationPath = './res/icon/android/logo.png';
const finalDestination = path.join(baseDir, CONFIG.OUTPUT_FILENAME);
// 打印初始信息
consola.info('开始替换Logo');
consola.info('当前目录: ' + baseDir);
consola.info('源文件: ' + sourcePath);
consola.info('开始处理Logo');
consola.info('源文件:', sourcePath);
consola.info('目标位置:', finalDestination);
// 验证文件类型
if (!isValidImageFile(sourcePath)) {
throw new Error(ErrorMessages.INVALID_FILE_TYPE);
}
// 根据源文件类型处理URL或本地文件
// 处理URL或本地文件
if (isValidUrl(sourcePath)) {
consola.info('正在从URL下载文件...');
const tempFile = path.join(baseDir, 'temp-logo' + path.extname(sourcePath));
const tempFile = path.join(baseDir, CONFIG.TEMP_PREFIX + Date.now() + path.extname(sourcePath));
tempFiles.push(tempFile);
try {
// 下载并替换文件
await downloadFile(sourcePath, tempFile);
copy(tempFile, destinationPath);
consola.success('Logo替换成功');
} finally {
// 清理临时文件
if (fs.existsSync(tempFile)) {
fs.unlinkSync(tempFile);
}
// 下载文件
await downloadFile(sourcePath, tempFile);
consola.success('文件下载完成');
// 转换为PNG如果需要
if (path.extname(tempFile).toLowerCase() !== '.png') {
consola.info('正在转换为PNG格式...');
convertToPng(tempFile, finalDestination);
} else {
fs.copyFileSync(tempFile, finalDestination);
}
} else {
// 处理本地文件
@ -128,14 +152,24 @@ async function main(): Promise<void> {
throw new Error(ErrorMessages.FILE_NOT_EXIST);
}
// 复制文件
copy(localPath, destinationPath);
consola.success('Logo替换成功');
// 转换为PNG如果需要
if (path.extname(localPath).toLowerCase() !== '.png') {
consola.info('正在转换为PNG格式...');
convertToPng(localPath, finalDestination);
} else {
fs.copyFileSync(localPath, finalDestination);
}
}
consola.success('Logo处理完成');
consola.info(`文件已保存至: ${finalDestination}`);
} catch (error) {
consola.error('Logo替换失败:', error.message);
consola.error('Logo处理失败:', error.message);
process.exit(1);
} finally {
// 清理所有临时文件
tempFiles.forEach(cleanupTempFile);
}
}