84 lines
2.6 KiB
JavaScript
84 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* dist-desktop/updates → latest.json (Tauri updater v2)
|
|
*
|
|
* Usage:
|
|
* node scripts/generate-desktop-latest-json.mjs \
|
|
* --version 0.1.0 \
|
|
* --dir dist-desktop/updates \
|
|
* --base-url https://exdev.co.kr/desktop/updates \
|
|
* --notes "Release notes"
|
|
*/
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
function arg(name, fallback) {
|
|
const i = process.argv.indexOf(name);
|
|
return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : fallback;
|
|
}
|
|
|
|
const version = arg('--version', '0.1.0');
|
|
const dir = path.resolve(arg('--dir', 'dist-desktop/updates'));
|
|
const baseUrl = (arg('--base-url', 'https://exdev.co.kr/desktop/updates')).replace(/\/$/, '');
|
|
const notes = arg('--notes', `GoldenChart Desktop ${version}`);
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
console.error('Directory not found:', dir);
|
|
process.exit(1);
|
|
}
|
|
|
|
const files = fs.readdirSync(dir);
|
|
|
|
/** @type {Record<string, { url: string; signature: string }>} */
|
|
const platforms = {};
|
|
|
|
function addPlatform(platformKey, bundleName) {
|
|
const bundlePath = path.join(dir, bundleName);
|
|
if (!fs.existsSync(bundlePath)) return;
|
|
const sigPath = `${bundlePath}.sig`;
|
|
let signature = '';
|
|
if (fs.existsSync(sigPath)) {
|
|
signature = fs.readFileSync(sigPath, 'utf8').trim();
|
|
} else {
|
|
console.warn(`[warn] missing signature: ${sigPath}`);
|
|
return;
|
|
}
|
|
platforms[platformKey] = {
|
|
url: `${baseUrl}/${encodeURIComponent(bundleName)}`,
|
|
signature,
|
|
};
|
|
}
|
|
|
|
for (const f of files) {
|
|
if (f.endsWith('.sig')) continue;
|
|
const lower = f.toLowerCase();
|
|
if (lower.includes('aarch64') && (lower.endsWith('.tar.gz') || lower.endsWith('.app.tar.gz'))) {
|
|
addPlatform('darwin-aarch64', f);
|
|
} else if ((lower.includes('x64') || lower.includes('x86_64')) && lower.endsWith('.tar.gz')) {
|
|
addPlatform('darwin-x86_64', f);
|
|
} else if (lower.includes('aarch64') && lower.endsWith('.app.tar.gz')) {
|
|
addPlatform('darwin-aarch64', f);
|
|
} else if (lower.endsWith('.nsis.zip') || (lower.includes('setup') && lower.endsWith('.zip'))) {
|
|
addPlatform('windows-x86_64', f);
|
|
} else if (lower.endsWith('.app.tar.gz')) {
|
|
// universal mac fallback
|
|
if (!platforms['darwin-aarch64']) addPlatform('darwin-aarch64', f);
|
|
}
|
|
}
|
|
|
|
const manifest = {
|
|
version,
|
|
notes,
|
|
pub_date: new Date().toISOString(),
|
|
platforms,
|
|
};
|
|
|
|
const outPath = path.join(dir, 'latest.json');
|
|
fs.writeFileSync(outPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
console.log('Wrote', outPath);
|
|
console.log('Platforms:', Object.keys(platforms).join(', ') || '(none — sign updater bundles first)');
|
|
|
|
if (Object.keys(platforms).length === 0) {
|
|
process.exit(2);
|
|
}
|