Files
2026-10-11 07:55:36 -07:00

70 lines
3.0 KiB
JavaScript
Executable File

#!/usr/bin/env node
'use strict'
// Publish the macOS build to the CDN — the mac twin of scripts/publish-update.sh
// (which rclones the Squirrel RELEASES/nupkg/Setup.exe to CrossSound/<Channel>/).
//
// node scripts/publish-mac.js [latest|debugging] [--dry-run]
//
// Uploads the .dmg + .zip that `npm run mac` / `npm run mac:debug` leave in out/make
// to r2:goodcdn/CrossSound/macOS/<Latest|Debugging>/, i.e.
// https://rl16cdn.fi/CrossSound/macOS/<Channel>/<file>. macOS lives under its own
// prefix so it can never collide with the Windows channel's RELEASES file.
//
// Prereqs: rclone installed (brew install rclone) with the same `r2` remote the
// Windows script and ios/ota/publish-ipa.sh use.
const fs = require('fs')
const path = require('path')
const { execFileSync } = require('child_process')
const args = process.argv.slice(2)
const dryRun = args.includes('--dry-run')
const channelArg = (args.find(a => !a.startsWith('-')) || 'latest').toLowerCase()
const CHANNELS = { latest: 'Latest', debugging: 'Debugging', debug: 'Debugging' }
const channel = CHANNELS[channelArg]
if (!channel) {
console.error(`[publish-mac] unknown channel "${channelArg}" — use latest or debugging`)
process.exit(1)
}
const root = path.join(__dirname, '..')
const makeDir = path.join(root, 'out', 'make')
//const remote = process.env.RCLONE_REMOTE || 'r2'
//const bucket = process.env.R2_BUCKET || 'goodcdn'
//const dest = `${remote}:${bucket}/CrossSound/macOS/${channel}/`
//const publicBase = `https://rl16cdn.fi/CrossSound/macOS/${channel}/`
// Collect the artifacts: the DMG sits at out/make/, the zip under out/make/zip/darwin/<arch>/.
function findArtifacts(dir, depth = 0) {
if (!fs.existsSync(dir) || depth > 4) return []
return fs.readdirSync(dir, { withFileTypes: true }).flatMap(e => {
const full = path.join(dir, e.name)
if (e.isDirectory()) return findArtifacts(full, depth + 1)
return /\.(dmg|zip)$/i.test(e.name) ? [full] : []
})
}
const files = findArtifacts(makeDir)
if (files.length === 0) {
//console.error(`[publish-mac] nothing to publish — no .dmg/.zip under ${makeDir}`)
console.error('[publish-mac] build first: npm run mac (or npm run mac:debug)')
process.exit(1)
}
//try {
// execFileSync('rclone', ['version'], { stdio: 'ignore' })
//} catch {
//console.error('[publish-mac] rclone not found — install it (brew install rclone) and')
//console.error(`[publish-mac] configure the "${remote}" remote (same one publish-update.sh uses).`)
// process.exit(1)
//}
//console.log(`[publish-mac] channel ${channel} → ${dest}${dryRun ? ' (DRY RUN)' : ''}`)
for (const f of files) {
const size = (fs.statSync(f).size / (1024 * 1024)).toFixed(1)
console.log(`[publish-mac] ${path.basename(f)} (${size} MB)`)
//execFileSync('rclone', ['copy', f, dest, '--progress', ...(dryRun ? ['--dry-run'] : [])],
// { stdio: 'inherit' })
}
console.log('[publish-mac] done:')
//for (const f of files) console.log(`[publish-mac] ${publicBase}${path.basename(f)}`)