-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffad173
commit a1813fc
Showing
6 changed files
with
249 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env node | ||
|
||
const CLI_VERSION = '0.25.1'; | ||
|
||
const fs = require('node:fs/promises'); | ||
const extractZip = require('extract-zip'); | ||
const tar = require('tar'); | ||
const { tmpdir } = require('node:os'); | ||
const path = require('node:path'); | ||
|
||
const download = async (url, dest) => { | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`unexpected response ${response.statusText}`); | ||
} | ||
|
||
const buffer = await response.arrayBuffer(); | ||
await fs.writeFile(dest, Buffer.from(buffer)); | ||
}; | ||
|
||
const downloadAndExtract = async (url, file, dest, archiveSuffix, extract) => { | ||
const tmpDir = await fs.mkdtemp(path.join(tmpdir(), 'vscode-humanitec-')); | ||
try { | ||
const archiveFile = `${tmpDir}/archive${archiveSuffix}`; | ||
await download(url, archiveFile); | ||
await extract(archiveFile, tmpDir); | ||
await fs.copyFile(`${tmpDir}/${file}`, dest); | ||
} finally { | ||
await fs.rm(tmpDir, { recursive: true, force: true }); | ||
} | ||
}; | ||
|
||
const downloadAndExtractGzip = (url, file, dest) => { | ||
return downloadAndExtract(url, file, dest, '.tar.gz', (archiveFile, tmpDir) => | ||
tar.extract({ | ||
file: archiveFile, | ||
cwd: tmpDir, | ||
}) | ||
); | ||
}; | ||
|
||
const downloadAndExtractZip = async (url, file, dest) => { | ||
return downloadAndExtract(url, file, dest, '.zip', (archiveFile, tmpDir) => | ||
extractZip(archiveFile, { dir: tmpDir }) | ||
); | ||
}; | ||
|
||
const main = async () => { | ||
const humctlDir = './humctl'; | ||
await fs.rm(humctlDir, { recursive: true, force: true }); | ||
await fs.mkdir(humctlDir, { recursive: true }); | ||
|
||
const prefix = `https://github.com/humanitec/cli/releases/download/v${CLI_VERSION}/cli_${CLI_VERSION}`; | ||
|
||
await Promise.all([ | ||
downloadAndExtractGzip( | ||
`${prefix}_darwin_amd64.tar.gz`, | ||
'humctl', | ||
`${humctlDir}/cli_${CLI_VERSION}_darwin_x64` | ||
), | ||
downloadAndExtractGzip( | ||
`${prefix}_darwin_arm64.tar.gz`, | ||
'humctl', | ||
`${humctlDir}/cli_${CLI_VERSION}_darwin_arm64` | ||
), | ||
downloadAndExtractGzip( | ||
`${prefix}_linux_amd64.tar.gz`, | ||
'humctl', | ||
`${humctlDir}/cli_${CLI_VERSION}_linux_x64` | ||
), | ||
downloadAndExtractGzip( | ||
`${prefix}_linux_arm64.tar.gz`, | ||
'humctl', | ||
`${humctlDir}/cli_${CLI_VERSION}_linux_arm64` | ||
), | ||
downloadAndExtractZip( | ||
`${prefix}_windows_amd64.zip`, | ||
'humctl.exe', | ||
`${humctlDir}/cli_${CLI_VERSION}_win32_x64.exe` | ||
), | ||
]); | ||
}; | ||
|
||
main().catch(err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.