UNPKG

appxloop

Version:

AppXLoop The Future of Continuous App Deployment & Management

84 lines (68 loc) 2.63 kB
const https = require('https'); const fs = require('fs'); const path = require('path'); const AdmZip = require('adm-zip'); const os = require('os'); const platform = os.platform(); const releaseTag = 'v1.0.0'; // The release version you want to download const downloadUrl = 'https://github.com/byteronz/app-distribute-release/releases/download/v1.0.0.0/Publish.zip'; const filePath = path.join(__dirname, 'appxloop.zip'); const extractDir = path.join(__dirname, 'appxloop'); // Function to download and extract the file function downloadFile(url, filePath) { https.get(url, (response) => { // Check for redirect status (301/302) if (response.statusCode === 302 || response.statusCode === 301) { const redirectUrl = response.headers.location; console.log(`Redirecting to: ${redirectUrl}`); downloadFile(redirectUrl, filePath); // Recursively follow the redirect } else if (response.statusCode === 200) { // If status is 200 (OK), start downloading const file = fs.createWriteStream(filePath); response.pipe(file); file.on('finish', () => { file.close(); console.log('Download complete!'); extractFile(filePath); // Call extract function after download }); } else { console.error(`Failed to download file. Status code: ${response.statusCode}`); } }).on('error', (err) => { console.error('Error downloading file: ', err.message); }); } // Function to extract the ZIP file function extractFile(zipPath) { try { console.log('Extracting file...'); // Create a new AdmZip object and load the ZIP file const zip = new AdmZip(zipPath); // Extract to the target directory zip.extractAllTo(extractDir, true); pathToExec(); console.log(`File extracted to ${extractDir}`); } catch (error) { console.error('Error extracting the file:', error.message); } } function pathToExec() { try { // Defi// Resolve the global install directory const globalBinDir = path.resolve(__dirname, "index.js"); // Apply permissions only on Linux/macOS if (os.platform() !== "win32") { try { fs.chmodSync(globalBinDir, 0o755); // Set execute permissions console.log("✅ Permissions set for:", globalBinDir); } catch (err) { console.error("❌ Failed to set executable permissions:", err); } } } catch (error) { console.error('Error extracting the file:', error.message); } } // Start the download process downloadFile(downloadUrl, filePath);