mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-03-12 07:58:13 -04:00
📦 Chore(custom): update scripts
This commit is contained in:
parent
74c996bf94
commit
5c42690586
@ -1,17 +1,20 @@
|
||||
// different platform has different format
|
||||
|
||||
// macos
|
||||
const darwin = [{
|
||||
const darwin = [
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.dmg',
|
||||
arch: '-arm64',
|
||||
'version-file': 'latest-mac.yml'
|
||||
}, {
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.dmg',
|
||||
arch: '-x64',
|
||||
'version-file': 'latest-mac.yml'
|
||||
}, {
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.dmg',
|
||||
arch: '-universal',
|
||||
@ -19,35 +22,42 @@ const darwin = [{
|
||||
}
|
||||
]
|
||||
|
||||
const linux = [{
|
||||
const linux = [
|
||||
{
|
||||
appNameWithPrefix: 'PicList-',
|
||||
ext: '.AppImage',
|
||||
arch: '',
|
||||
'version-file': 'latest-linux.yml'
|
||||
}, {
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'piclist_',
|
||||
ext: '.snap',
|
||||
arch: '_amd64',
|
||||
'version-file': 'latest-linux.yml'
|
||||
}]
|
||||
}
|
||||
]
|
||||
|
||||
// windows
|
||||
const win32 = [{
|
||||
const win32 = [
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '-ia32',
|
||||
'version-file': 'latest.yml'
|
||||
}, {
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '-x64',
|
||||
'version-file': 'latest.yml'
|
||||
}, {
|
||||
},
|
||||
{
|
||||
appNameWithPrefix: 'PicList-Setup-',
|
||||
ext: '.exe',
|
||||
arch: '', // 32 & 64
|
||||
'version-file': 'latest.yml'
|
||||
}]
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
darwin,
|
||||
|
@ -12,8 +12,7 @@ const obj = yaml.load(langFile)
|
||||
|
||||
const keys = Object.keys(obj)
|
||||
|
||||
const types =
|
||||
`interface ILocales {
|
||||
const types = `interface ILocales {
|
||||
${keys.map(key => `${key}: string`).join('\n ')}
|
||||
}
|
||||
type ILocalesKey = keyof ILocales
|
||||
|
@ -4,55 +4,133 @@ const path = require('path')
|
||||
const axios = require('axios')
|
||||
const fs = require('fs-extra')
|
||||
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`
|
||||
const arm64URL = `https://release.piclist.cn/latest/PicList-${version}-arm64.dmg`
|
||||
const x64Path = path.join(os.homedir(), 'Downloads', 'PicList-x64.dmg')
|
||||
const arm64Path = path.join(os.homedir(), 'Downloads', 'PicList-arm64.dmg')
|
||||
// Configuration
|
||||
const BASE_URL = `https://github.com/Kuingsmile/PicList/releases/download/v${version}`
|
||||
const DOWNLOAD_DIR = process.argv[3] || path.join(os.homedir(), 'Downloads')
|
||||
// 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 {
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url,
|
||||
responseType: 'stream'
|
||||
})
|
||||
const writer = fs.createWriteStream(path)
|
||||
|
||||
const writer = fs.createWriteStream(filePath)
|
||||
response.data.pipe(writer)
|
||||
|
||||
const hash = crypto.createHash('sha256')
|
||||
const progressTotal = parseInt(response.headers['content-length'], 10)
|
||||
let progressCurrent = 0
|
||||
console.log('\n')
|
||||
|
||||
response.data.on('data', (chunk) => {
|
||||
response.data.on('data', chunk => {
|
||||
hash.update(chunk)
|
||||
progressCurrent += chunk.length
|
||||
const progressBar = Math.round(progressCurrent / progressTotal * 100)
|
||||
process.stdout.write(`\r${progressBar}% ${path}`)
|
||||
process.stdout.write(`\r${name}: ${getProgressBar(progressCurrent, progressTotal)}`)
|
||||
})
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
response.data.on('end', () => {
|
||||
resolve()
|
||||
})
|
||||
response.data.on('error', (err) => {
|
||||
reject(err)
|
||||
})
|
||||
writer.on('finish', resolve)
|
||||
writer.on('error', reject)
|
||||
response.data.on('error', reject)
|
||||
})
|
||||
|
||||
console.log(`\n${path} SHA256: ${hash.digest('hex')}`)
|
||||
const hashValue = hash.digest('hex')
|
||||
console.log(`\n✅ ${name} SHA256: ${hashValue}`)
|
||||
|
||||
await fs.remove(path)
|
||||
console.log(`Deleted ${path}`)
|
||||
// Write hash to a file for reference
|
||||
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) {
|
||||
console.error(`\nError downloading ${url}: ${err.message}`)
|
||||
console.error(`\n❌ Error processing ${name}: ${err.message}`)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
downloadAndHash(x64URL, x64Path).then(() => {
|
||||
downloadAndHash(arm64URL, arm64Path)
|
||||
}).catch(() => {
|
||||
downloadAndHash(arm64URL, arm64Path)
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
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()
|
||||
|
@ -3,12 +3,7 @@
|
||||
require('dotenv').config()
|
||||
|
||||
const { notarize } = require('@electron/notarize')
|
||||
const {
|
||||
ELECTRON_SKIP_NOTARIZATION,
|
||||
XCODE_APP_LOADER_EMAIL,
|
||||
XCODE_APP_LOADER_PASSWORD,
|
||||
XCODE_TEAM_ID
|
||||
} = process.env
|
||||
const { ELECTRON_SKIP_NOTARIZATION, XCODE_APP_LOADER_EMAIL, XCODE_APP_LOADER_PASSWORD, XCODE_TEAM_ID } = process.env
|
||||
|
||||
async function main(context) {
|
||||
const { electronPlatformName, appOutDir } = context
|
||||
|
@ -45,7 +45,7 @@ const uploadFile = async () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
parallelUploads3.on('httpUploadProgress', (progress) => {
|
||||
parallelUploads3.on('httpUploadProgress', progress => {
|
||||
const progressBar = Math.round((progress.loaded / progress.total) * 100)
|
||||
process.stdout.write(`\r${progressBar}% ${fileName}`)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user