📦 Chore(custom): add prepare scripts and update action

This commit is contained in:
Kuingsmile
2026-01-15 22:15:53 +08:00
parent 235dbee40d
commit 41f8a5dca1
3 changed files with 118 additions and 17 deletions

View File

@@ -152,6 +152,21 @@ jobs:
yarn config set ignore-engines true yarn config set ignore-engines true
rm -rf node_modules dist_electron && yarn install --frozen-lockfile rm -rf node_modules dist_electron && yarn install --frozen-lockfile
yarn global add xvfb-maybe yarn global add xvfb-maybe
if [[ "${{ matrix.format }}" == "zip" || "${{ matrix.format }}" == "7z" ]]; then
echo "Target format is ${{ matrix.format }}, downloading all resources..."
yarn run prepare
else
echo "Target format is other, downloading themes only..."
yarn run prepare:themes
fi
echo "Checking resources directory:"
ls -alh ./resources/theme || echo "Theme directory not found"
# check 7za.exe and theme dir
if [[ -f "./resources/7za.exe" ]]; then
echo "✅ 7za.exe exists"
else
echo "❌ 7za.exe does not exist"
fi
- name: Generate release notes - name: Generate release notes
if: github.event.inputs.build_os == matrix.filter || github.event.inputs.build_os == 'All' if: github.event.inputs.build_os == matrix.filter || github.event.inputs.build_os == 'All'
@@ -183,27 +198,10 @@ jobs:
fi fi
echo "Publishing argument: $PUBLISH_ARG" echo "Publishing argument: $PUBLISH_ARG"
if [[ "${{ matrix.os }}" == windows* ]]; then if [[ "${{ matrix.os }}" == windows* ]]; then
if [[ "${{ matrix.format }}" == "nsis" ]]; then
rm -f ./resources/7za.exe
if [ -f ./resources/7za.exe ]; then
echo "Error: 7za.exe was not removed from resources."
exit 1
fi
fi
yarn run build:win ${{ matrix.format}} --${{ matrix.arch }} --publish $PUBLISH_ARG yarn run build:win ${{ matrix.format}} --${{ matrix.arch }} --publish $PUBLISH_ARG
elif [[ "${{ matrix.os }}" == macos* ]]; then elif [[ "${{ matrix.os }}" == macos* ]]; then
rm -f ./resources/7za.exe
if [ -f ./resources/7za.exe ]; then
echo "Error: 7za.exe was not removed from resources."
exit 1
fi
yarn run build:mac ${{ matrix.format}} --${{ matrix.arch }} --publish $PUBLISH_ARG yarn run build:mac ${{ matrix.format}} --${{ matrix.arch }} --publish $PUBLISH_ARG
elif [[ "${{ matrix.os }}" == ubuntu* ]]; then elif [[ "${{ matrix.os }}" == ubuntu* ]]; then
rm -f ./resources/7za.exe
if [ -f ./resources/7za.exe ]; then
echo "Error: 7za.exe was not removed from resources."
exit 1
fi
yarn run build:linux ${{ matrix.format}} --${{ matrix.arch }} --publish $PUBLISH_ARG yarn run build:linux ${{ matrix.format}} --${{ matrix.arch }} --publish $PUBLISH_ARG
else else
echo "Unsupported OS: ${{ matrix.os }}" echo "Unsupported OS: ${{ matrix.os }}"

View File

@@ -35,6 +35,9 @@
"postinstall": "electron-builder install-app-deps", "postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps", "postuninstall": "electron-builder install-app-deps",
"prebuild": "electron-vite build", "prebuild": "electron-vite build",
"prepare": "node ./scripts/prepare.js --all",
"prepare:7zaip": "node ./scripts/prepare.js --type=7zip",
"prepare:themes": "node ./scripts/prepare.js --type=themes",
"preview": "electron-vite preview", "preview": "electron-vite preview",
"release": "electron-vite build && electron-builder", "release": "electron-vite build && electron-builder",
"sha256": "node ./scripts/gen-sha256.js", "sha256": "node ./scripts/gen-sha256.js",

100
scripts/prepare.js Normal file
View File

@@ -0,0 +1,100 @@
import { execSync } from 'node:child_process'
import fs from 'fs-extra'
import path from 'node:path'
import axios from 'axios'
import AdmZip from 'adm-zip'
const cwd = process.cwd()
let arch = process.arch
const platform = process.platform
const args = process.argv.slice(2)
const params = Object.fromEntries(
args.map(arg => {
const [key, value] = arg.replace(/^--/, '').split('=')
return [key, value || true]
}),
)
const resolve7zip = () =>
resolveResource({
file: '7za.exe',
downloadURL: `https://github.com/develar/7zip-bin/raw/master/win/${arch}/7za.exe`,
})
async function fetchThemes() {
try {
const zipUrl = 'https://github.com/Kuingsmile/piclist-themeHub/releases/download/latest/themes.zip'
const zipData = await axios.get(zipUrl, {
responseType: 'arraybuffer',
headers: { 'Content-Type': 'application/octet-stream' },
})
const zip = new AdmZip(zipData.data)
zip.extractAllTo(path.join(cwd, 'resources', 'theme'), true)
console.log('[INFO]: themes downloaded and extracted')
return true
} catch (e) {
console.log('[WARN]: failed to download themes', e)
return false
}
}
async function downloadFile(url, path) {
const response = await fetch(url, {
method: 'GET',
headers: { 'Content-Type': 'application/octet-stream' },
})
const buffer = await response.arrayBuffer()
fs.writeFileSync(path, new Uint8Array(buffer))
console.log(`[INFO]: download finished "${url}"`)
}
async function resolveResource(binInfo) {
const { file, downloadURL, needExecutable = false } = binInfo
const resDir = path.join(cwd, 'resources')
const targetPath = path.join(resDir, file)
if (fs.existsSync(targetPath)) {
fs.removeSync(targetPath)
}
fs.mkdirSync(resDir, { recursive: true })
await downloadFile(downloadURL, targetPath)
if (needExecutable && platform !== 'win32') {
execSync(`chmod 755 ${targetPath}`)
console.log(`[INFO]: ${file} chmod finished`)
}
console.log(`[INFO]: ${file} finished`)
}
async function main() {
const tasks = []
if (params.type === '7zip' || params.all) {
console.log('[INFO]: Resolving 7zip...')
tasks.push(resolve7zip())
}
if (params.type === 'themes' || params.all) {
console.log('[INFO]: Resolving themes...')
tasks.push(fetchThemes())
}
if (tasks.length === 0) {
console.log('请提供参数,例如: node script.js --type=7zip 或 --all')
return
}
try {
await Promise.all(tasks)
console.log('Selected resources have been resolved.')
} catch (err) {
console.error('Error:', err)
}
}
main()