diff --git a/package.json b/package.json index 2ec212088..50eb8ecaf 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "copy:assets:tauri": "cpx \"pre-install/*.tgz\" \"src-tauri/resources/pre-install/\" && cpx \"LICENSE\" \"src-tauri/resources/\"", "download:lib": "node ./scripts/download-lib.mjs", "download:bin": "node ./scripts/download-bin.mjs", - "build:tauri:win32": "yarn download:bin && yarn download:lib && yarn tauri build", + "download:windows-installer": "node ./scripts/download-win-installer-deps.mjs", + "build:tauri:win32": "yarn download:bin && yarn download:lib && yarn download:windows-installer && yarn tauri build", "build:tauri:linux": "yarn download:bin && yarn download:lib && NO_STRIP=1 ./src-tauri/build-utils/shim-linuxdeploy.sh yarn tauri build && ./src-tauri/build-utils/buildAppImage.sh", "build:tauri:darwin": "yarn download:bin && yarn tauri build --target universal-apple-darwin", "build:tauri": "yarn build:icon && yarn copy:assets:tauri && run-script-os", diff --git a/scripts/download-lib.mjs b/scripts/download-lib.mjs index 6075a18d1..d2086b36e 100644 --- a/scripts/download-lib.mjs +++ b/scripts/download-lib.mjs @@ -77,25 +77,6 @@ async function main() { // Expect EEXIST error } - // Download VC++ Redistributable 17 - if (platform == 'win32') { - const vcFilename = 'vc_redist.x64.exe' - const vcUrl = 'https://aka.ms/vs/17/release/vc_redist.x64.exe' - - console.log(`Downloading VC++ Redistributable...`) - const vcSavePath = path.join(tempDir, vcFilename) - if (!fs.existsSync(vcSavePath)) { - await download(vcUrl, vcSavePath) - } - - // copy to tauri resources - try { - copySync(vcSavePath, libDir) - } catch (err) { - // Expect EEXIST error - } - } - console.log('Downloads completed.') } diff --git a/scripts/download-win-installer-deps.mjs b/scripts/download-win-installer-deps.mjs new file mode 100644 index 000000000..33bbbe04b --- /dev/null +++ b/scripts/download-win-installer-deps.mjs @@ -0,0 +1,83 @@ +console.log('Downloading Windows installer dependencies...') +// scripts/download-win-installer-deps.mjs +import https from 'https' +import fs, { mkdirSync } from 'fs' +import os from 'os' +import path from 'path' +import { copySync } from 'cpx' + +function download(url, dest) { + return new Promise((resolve, reject) => { + console.log(`Downloading ${url} to ${dest}`) + const file = fs.createWriteStream(dest) + https + .get(url, (response) => { + console.log(`Response status code: ${response.statusCode}`) + if ( + response.statusCode >= 300 && + response.statusCode < 400 && + response.headers.location + ) { + // Handle redirect + const redirectURL = response.headers.location + console.log(`Redirecting to ${redirectURL}`) + download(redirectURL, dest).then(resolve, reject) // Recursive call + return + } else if (response.statusCode !== 200) { + reject(`Failed to get '${url}' (${response.statusCode})`) + return + } + response.pipe(file) + file.on('finish', () => { + file.close(resolve) + }) + }) + .on('error', (err) => { + fs.unlink(dest, () => reject(err.message)) + }) + }) +} + +async function main() { + console.log('Starting Windows installer dependencies download') + const platform = os.platform() // 'darwin', 'linux', 'win32' + const arch = os.arch() // 'x64', 'arm64', etc. + + if (arch != 'x64') return + + + const libDir = 'src-tauri/resources/lib' + const tempDir = 'scripts/dist' + + try { + mkdirSync('scripts/dist') + } catch (err) { + // Expect EEXIST error if the directory already exists + } + + // Download VC++ Redistributable 17 + if (platform == 'win32') { + const vcFilename = 'vc_redist.x64.exe' + const vcUrl = 'https://aka.ms/vs/17/release/vc_redist.x64.exe' + + console.log(`Downloading VC++ Redistributable...`) + const vcSavePath = path.join(tempDir, vcFilename) + if (!fs.existsSync(vcSavePath)) { + await download(vcUrl, vcSavePath) + } + + // copy to tauri resources + try { + copySync(vcSavePath, libDir) + } catch (err) { + // Expect EEXIST error + } + } + + console.log('Windows installer dependencies downloads completed.') +} + +main().catch((err) => { + console.error('Error:', err) + process.exit(1) +})