| 40 | ); |
| 41 | |
| 42 | export function getJson(url) { |
| 43 | const tmpFile = path.join( |
| 44 | os.tmpdir(), |
| 45 | `anus-cli-releases-${Date.now()}.json`, |
| 46 | ); |
| 47 | try { |
| 48 | execSync( |
| 49 | `curl -sL -H "User-Agent: anus-cli-dev-script" -o "${tmpFile}" "${url}"`, |
| 50 | { stdio: 'pipe' }, |
| 51 | ); |
| 52 | const content = fs.readFileSync(tmpFile, 'utf-8'); |
| 53 | return JSON.parse(content); |
| 54 | } catch (e) { |
| 55 | console.error(`Failed to fetch or parse JSON from ${url}`); |
| 56 | throw e; |
| 57 | } finally { |
| 58 | if (fs.existsSync(tmpFile)) { |
| 59 | fs.unlinkSync(tmpFile); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | export function downloadFile(url, dest) { |
| 65 | try { |