// Name: Download Script Kit (Win) // Description: Downloads and runs the latest Script Kit for Windows. // Author: JosXa /** * Interface defining the structure of a release asset from the GitHub API. */ interface ReleaseAsset { name: string; browser_download_url: string; } /** * Interface defining the structure of a release from the GitHub API. */ interface Release { assets: ReleaseAsset[]; tag_name: string;} const repo = 'script-kit/app'; const url = `https://api.github.com/repos/${repo}/releases/latest`; try { // Fetch the latest release information from GitHub API const response = await get(url); const release: Release = response.data; const version = release.tag_name; // Find the Windows x64 executable asset const asset = release.assets.find((asset) => asset.name.match(/Script-Kit-.*-x64\.exe$/)); if (!asset) { throw new Error('No matching asset found for Windows x64.'); } const downloadUrl = asset.browser_download_url; const fileName = `Script-Kit-Windows-${version}-x64.exe`; const downloadPath = home('Downloads', fileName); // Download the executable to the Downloads directory await download(downloadUrl, home('Downloads'), { filename: fileName }); // Execute the downloaded installer await exec(downloadPath); } catch (error) { console.error("An error occurred during the download or execution:", error); if (error instanceof Error) { // Improve error message for network or API issues if (error.message.startsWith('Request failed with status code')) { console.error(`GitHub API request failed. Status code: ${error.message.split(' ').pop()}`); } else { console.error(`Error details: ${error.message}`); } } else { console.error("Unknown error:", error); } }