MCPcopy Create free account
hub / github.com/csskit/csskit / ensureBinary

Function ensureBinary

packages/csskit_vscode/src/main.js:86–109  ·  view source on GitHub ↗

* @param {string} storageDir * @returns {Promise }

(storageDir)

Source from the content-addressed store, hash-verified

84 * @returns {Promise<string>}
85 */
86async function ensureBinary(storageDir) {
87 const { platform, arch, exe } = platformInfo();
88 const binaryPath = path.join(storageDir, `csskit${exe}`);
89 const versionPath = path.join(storageDir, "version.txt");
90 const assetName = `csskit-${platform}-${arch}`;
91
92 const release = await fetchLatestRelease();
93 const installedVersion = await readVersion(versionPath);
94
95 if (installedVersion === release.tag_name && fs.existsSync(binaryPath)) {
96 return binaryPath;
97 }
98
99 const asset = release.assets.find((a) => a.name === assetName);
100 if (!asset) {
101 throw new Error(`No asset found matching ${assetName}`);
102 }
103
104 await downloadFile(asset.browser_download_url, binaryPath);
105 await fsp.chmod(binaryPath, 0o755);
106 await fsp.writeFile(versionPath, release.tag_name, "utf-8");
107
108 return binaryPath;
109}
110
111/**
112 * @param {string} versionPath

Callers 1

activateFunction · 0.85

Calls 4

platformInfoFunction · 0.85
fetchLatestReleaseFunction · 0.85
readVersionFunction · 0.85
downloadFileFunction · 0.85

Tested by

no test coverage detected