📦 Chore(custom): update scripts

This commit is contained in:
Kuingsmile 2025-03-05 13:19:03 +08:00
parent 74c996bf94
commit 5c42690586
6 changed files with 163 additions and 81 deletions

View File

@ -1,17 +1,20 @@
// different platform has different format // different platform has different format
// macos // macos
const darwin = [{ const darwin = [
{
appNameWithPrefix: 'PicList-', appNameWithPrefix: 'PicList-',
ext: '.dmg', ext: '.dmg',
arch: '-arm64', arch: '-arm64',
'version-file': 'latest-mac.yml' 'version-file': 'latest-mac.yml'
}, { },
{
appNameWithPrefix: 'PicList-', appNameWithPrefix: 'PicList-',
ext: '.dmg', ext: '.dmg',
arch: '-x64', arch: '-x64',
'version-file': 'latest-mac.yml' 'version-file': 'latest-mac.yml'
}, { },
{
appNameWithPrefix: 'PicList-', appNameWithPrefix: 'PicList-',
ext: '.dmg', ext: '.dmg',
arch: '-universal', arch: '-universal',
@ -19,35 +22,42 @@ const darwin = [{
} }
] ]
const linux = [{ const linux = [
{
appNameWithPrefix: 'PicList-', appNameWithPrefix: 'PicList-',
ext: '.AppImage', ext: '.AppImage',
arch: '', arch: '',
'version-file': 'latest-linux.yml' 'version-file': 'latest-linux.yml'
}, { },
{
appNameWithPrefix: 'piclist_', appNameWithPrefix: 'piclist_',
ext: '.snap', ext: '.snap',
arch: '_amd64', arch: '_amd64',
'version-file': 'latest-linux.yml' 'version-file': 'latest-linux.yml'
}] }
]
// windows // windows
const win32 = [{ const win32 = [
{
appNameWithPrefix: 'PicList-Setup-', appNameWithPrefix: 'PicList-Setup-',
ext: '.exe', ext: '.exe',
arch: '-ia32', arch: '-ia32',
'version-file': 'latest.yml' 'version-file': 'latest.yml'
}, { },
{
appNameWithPrefix: 'PicList-Setup-', appNameWithPrefix: 'PicList-Setup-',
ext: '.exe', ext: '.exe',
arch: '-x64', arch: '-x64',
'version-file': 'latest.yml' 'version-file': 'latest.yml'
}, { },
{
appNameWithPrefix: 'PicList-Setup-', appNameWithPrefix: 'PicList-Setup-',
ext: '.exe', ext: '.exe',
arch: '', // 32 & 64 arch: '', // 32 & 64
'version-file': 'latest.yml' 'version-file': 'latest.yml'
}] }
]
module.exports = { module.exports = {
darwin, darwin,

View File

@ -12,8 +12,7 @@ const obj = yaml.load(langFile)
const keys = Object.keys(obj) const keys = Object.keys(obj)
const types = const types = `interface ILocales {
`interface ILocales {
${keys.map(key => `${key}: string`).join('\n ')} ${keys.map(key => `${key}: string`).join('\n ')}
} }
type ILocalesKey = keyof ILocales type ILocalesKey = keyof ILocales

View File

@ -4,55 +4,133 @@ const path = require('path')
const axios = require('axios') const axios = require('axios')
const fs = require('fs-extra') const fs = require('fs-extra')
const pkg = require('../package.json') const pkg = require('../package.json')
const version = pkg.version const version = process.argv[2] || pkg.version
const x64URL = `https://release.piclist.cn/latest/PicList-${version}-x64.dmg` // Configuration
const arm64URL = `https://release.piclist.cn/latest/PicList-${version}-arm64.dmg` const BASE_URL = `https://github.com/Kuingsmile/PicList/releases/download/v${version}`
const x64Path = path.join(os.homedir(), 'Downloads', 'PicList-x64.dmg') const DOWNLOAD_DIR = process.argv[3] || path.join(os.homedir(), 'Downloads')
const arm64Path = path.join(os.homedir(), 'Downloads', 'PicList-arm64.dmg') // File information
const files = [
{
name: 'PicList-x64.dmg',
url: `${BASE_URL}/PicList-${version}-x64.dmg`
},
{
name: 'PicList-arm64.dmg',
url: `${BASE_URL}/PicList-${version}-arm64.dmg`
}
]
/**
* Create progress bar string
*/
function getProgressBar(current, total, length = 20) {
const progress = Math.round((current / total) * length)
const percentage = Math.round((current / total) * 100)
const bar = '█'.repeat(progress) + '░'.repeat(length - progress)
return `[${bar}] ${percentage}% (${formatBytes(current)}/${formatBytes(total)})`
}
/**
* Format bytes to human-readable format
*/
function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes'
const k = 1024
const sizes = ['Bytes', 'KB', 'MB', 'GB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i]
}
/**
* Download file and calculate SHA256 hash
*/
async function downloadAndHash(fileInfo) {
const { url, name } = fileInfo
const filePath = path.join(DOWNLOAD_DIR, name)
console.log(`\nStarting download: ${name} from ${url}`)
const downloadAndHash = async (url, path) => {
try { try {
const response = await axios({ const response = await axios({
method: 'get', method: 'get',
url, url,
responseType: 'stream' responseType: 'stream'
}) })
const writer = fs.createWriteStream(path)
const writer = fs.createWriteStream(filePath)
response.data.pipe(writer) response.data.pipe(writer)
const hash = crypto.createHash('sha256') const hash = crypto.createHash('sha256')
const progressTotal = parseInt(response.headers['content-length'], 10) const progressTotal = parseInt(response.headers['content-length'], 10)
let progressCurrent = 0 let progressCurrent = 0
console.log('\n')
response.data.on('data', (chunk) => { response.data.on('data', chunk => {
hash.update(chunk) hash.update(chunk)
progressCurrent += chunk.length progressCurrent += chunk.length
const progressBar = Math.round(progressCurrent / progressTotal * 100) process.stdout.write(`\r${name}: ${getProgressBar(progressCurrent, progressTotal)}`)
process.stdout.write(`\r${progressBar}% ${path}`)
}) })
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
response.data.on('end', () => { writer.on('finish', resolve)
resolve() writer.on('error', reject)
}) response.data.on('error', reject)
response.data.on('error', (err) => {
reject(err)
})
}) })
console.log(`\n${path} SHA256: ${hash.digest('hex')}`) const hashValue = hash.digest('hex')
console.log(`\n${name} SHA256: ${hashValue}`)
await fs.remove(path) // Write hash to a file for reference
console.log(`Deleted ${path}`) await fs.writeFile(`${filePath}.sha256`, hashValue)
console.log(`Hash saved to ${filePath}.sha256`)
if (process.argv.includes('--keep-files')) {
console.log(`Keeping file: ${filePath}`)
} else {
await fs.remove(filePath)
console.log(`Deleted: ${filePath}`)
}
return { name, hash: hashValue }
} catch (err) { } catch (err) {
console.error(`\nError downloading ${url}: ${err.message}`) console.error(`\n❌ Error processing ${name}: ${err.message}`)
throw err
} }
} }
downloadAndHash(x64URL, x64Path).then(() => { /**
downloadAndHash(arm64URL, arm64Path) * Main function
}).catch(() => { */
downloadAndHash(arm64URL, arm64Path) async function main() {
console.log(`Generating SHA256 hashes for PicList v${version}`)
console.log(`Download directory: ${DOWNLOAD_DIR}`)
try {
// Ensure download directory exists
await fs.ensureDir(DOWNLOAD_DIR)
// Start all downloads concurrently
const results = await Promise.allSettled(files.map(downloadAndHash))
// Output summary
console.log('\n===== SUMMARY =====')
results.forEach((result, index) => {
const fileName = files[index].name
if (result.status === 'fulfilled') {
console.log(`${fileName}: ${result.value.hash}`)
} else {
console.log(`${fileName}: Failed - ${result.reason.message}`)
}
}) })
// Check if all downloads were successful
if (results.some(r => r.status === 'rejected')) {
process.exit(1)
}
} catch (err) {
console.error(`\nCritical error: ${err.message}`)
process.exit(1)
}
}
main()

View File

@ -3,12 +3,7 @@
require('dotenv').config() require('dotenv').config()
const { notarize } = require('@electron/notarize') const { notarize } = require('@electron/notarize')
const { const { ELECTRON_SKIP_NOTARIZATION, XCODE_APP_LOADER_EMAIL, XCODE_APP_LOADER_PASSWORD, XCODE_TEAM_ID } = process.env
ELECTRON_SKIP_NOTARIZATION,
XCODE_APP_LOADER_EMAIL,
XCODE_APP_LOADER_PASSWORD,
XCODE_TEAM_ID
} = process.env
async function main(context) { async function main(context) {
const { electronPlatformName, appOutDir } = context const { electronPlatformName, appOutDir } = context

View File

@ -45,7 +45,7 @@ const uploadFile = async () => {
} }
} }
}) })
parallelUploads3.on('httpUploadProgress', (progress) => { parallelUploads3.on('httpUploadProgress', progress => {
const progressBar = Math.round((progress.loaded / progress.total) * 100) const progressBar = Math.round((progress.loaded / progress.total) * 100)
process.stdout.write(`\r${progressBar}% ${fileName}`) process.stdout.write(`\r${progressBar}% ${fileName}`)
}) })