From c644d5006defd4d88ce599e2624f46d07d8e6147 Mon Sep 17 00:00:00 2001 From: jjavierdguezas Date: Thu, 15 Sep 2022 11:21:32 +0200 Subject: [PATCH] Improve chocolatey script - download installer file from github automatically --- .../scripts/chocolatey/generateChocoPkg.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/desktop-app/scripts/chocolatey/generateChocoPkg.js b/desktop-app/scripts/chocolatey/generateChocoPkg.js index 089ee247..e2f35b19 100644 --- a/desktop-app/scripts/chocolatey/generateChocoPkg.js +++ b/desktop-app/scripts/chocolatey/generateChocoPkg.js @@ -5,6 +5,7 @@ const crypto = require('crypto'); const replaceInFiles = require('replace-in-file'); const {spawn} = require('child_process'); const {ncp} = require('ncp'); +const https = require('https'); ncp.limit = 16; @@ -75,6 +76,36 @@ const execChocoPack = () => }); }); +const ensureInstallerFile = async () => { + console.log('\nEnsure installer file'); + return new Promise((resolve, reject) => { + const installerPath = path.resolve(releasePath, checksumFileName); + if (fs.existsSync(installerPath)) { + console.log('Removing existing installer file'); + fs.rmdirSync(installerPath, {recursive: true}); + } + + const url = `https://github.com/responsively-org/responsively-app/releases/download/v${version}/ResponsivelyApp-Setup-${version}.exe`; + console.log(`Downloading '${checksumFileName}' file from github`); + const file = fs.createWriteStream(installerPath); + https + .get(url, response => { + response.pipe(file); + file.on('finish', () => { + file.close(() => { + console.log('Download finished'); + resolve(); + }); + }); + }) + .on('error', err => { + fs.unlink(dest); + console.log('Download error!'); + reject(err.message); + }); + }); +}; + const generateChocoPkg = async () => { console.log( `\nGenerating Chocolatey package folder for responsively v${version}` @@ -98,6 +129,7 @@ const generateChocoPkg = async () => { } console.log('done!'); try { + await ensureInstallerFile(); const checksum = await getSha512(); await replaceTokensInTemplates(checksum); await execChocoPack();