UNPKG

syntax-scribe

Version:

Effortless code documentation generator for JavaScript, TypeScript, Vue, and TSX projects with MkDocs integration.

80 lines (65 loc) 2.25 kB
const fs = require("fs"); const path = require("path"); const os = require("os"); const https = require("https"); const { chmodSync } = require("fs"); const version = "v0.1.0"; // Update as needed const baseUrl = "https://d1gyju62sjco0e.cloudfront.net/binaries"; // Your CloudFront URL const platformMap = { "darwin-arm64": "syntax-scribe-arm64", "darwin-x64": "syntax-scribe-x64", "linux-x64": "syntax-scribe-linux", "win32-x64": "syntax-scribe-win.exe", }; const platformKey = `${os.platform()}-${os.arch()}`; const binaryName = platformMap[platformKey]; if (!binaryName) { console.error(`Unsupported platform: ${platformKey}`); process.exit(1); } const downloadUrl = `${baseUrl}/${version}/${binaryName}`; const destDir = path.resolve(__dirname, "bin"); const destPath = path.join( destDir, os.platform() === "win32" ? "syntax-scribe.exe" : "syntax-scribe" ); const launcherDir = path.resolve(__dirname, "launcher"); const launcherPath = path.join(launcherDir, "syntax-scribe"); if (os.platform() !== "win32") { try { chmodSync(launcherPath, 0o755); console.log(`✅ Made launcher executable: ${launcherPath}`); } catch (error) { console.error(`❌ Could not make launcher executable: ${error.message}`); console.error("You may need to run: chmod +x " + launcherPath); } } // Create destination directory if it doesn't exist if (!fs.existsSync(destDir)) { fs.mkdirSync(destDir, { recursive: true }); } console.log(`Downloading ${downloadUrl}`); // Download binary using https instead of fetch const file = fs.createWriteStream(destPath); https .get(downloadUrl, (response) => { if (response.statusCode !== 200) { fs.unlinkSync(destPath); console.error(`Failed to download binary: HTTP ${response.statusCode}`); process.exit(1); } response.pipe(file); file.on("finish", () => { file.close(); // Make binary executable on non-Windows platforms if (os.platform() !== "win32") { chmodSync(destPath, 0o755); } console.log(`✅ SyntaxScribe installed successfully!`); }); }) .on("error", (err) => { fs.unlinkSync(destPath); console.error(`Error downloading binary: ${err.message}`); process.exit(1); });