Skip to content

Commit

Permalink
🐛 Download correct name, and only --pkg arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed May 28, 2024
1 parent 214b29c commit f2dece5
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,27 +499,30 @@ release [options] <input>
}

for (const build of builds) {
const pkgPath = join(cwd(), `pkg-cache`)
const arch = `${build.options.platforms}-${build.options.archs}`
const pkgFiles = await glob(`${pkgPath}/fetched*-${arch}`) // ['node-v20.11.1-linux-x64']

if (pkgFiles.length === 0) {
console.log('Baixando Node.js Binary')
const { assets } = (await (await fetch('https://api.github.com/repos/yao-pkg/pkg-fetch/releases/latest')).json()) as { assets: Asset[] }
const versions = assets.filter((asset) => asset.name.includes(arch) && !asset.name.includes('sha256sum'))
console.log(versions)
const download = await fetch(versions[versions.length - 1].browser_download_url)
await new Promise<void>(async (resolve, reject) => {
if (download.ok && download.body) {
if (!await exists(pkgPath)) await mkdir(pkgPath)
const path = createWriteStream(`${pkgPath}/fetched-v${version}-${arch}`)
const wrile = Readable.fromWeb(download.body).pipe(path)
wrile.on('finish', () => resolve())
wrile.on('error', (err) => reject(err))
} else {
reject(download.statusText)
}
})
if (newArgs.filter((arg) => arg.command === 'pkg').length > 0) {
const pkgPath = join(cwd(), `pkg-cache`)
const arch = `${build.options.platforms}-${build.options.archs}`
const pkgFiles = await glob(`${pkgPath}/fetched*-${arch}`) // ['node-v20.11.1-linux-x64']

if (pkgFiles.length === 0) {
console.log('Baixando Node.js Binary')
const { assets } = (await (await fetch('https://api.github.com/repos/yao-pkg/pkg-fetch/releases/latest')).json()) as { assets: Asset[] }
const versions = assets.filter((asset) => asset.name.includes(arch) && !asset.name.includes('sha256sum'))
const version = versions[versions.length - 1]
console.log(versions)
const download = await fetch(version.browser_download_url)
await new Promise<void>(async (resolve, reject) => {
if (download.ok && download.body) {
if (!await exists(pkgPath)) await mkdir(pkgPath)
const path = createWriteStream(`${pkgPath}/${version.name}`)
const wrile = Readable.fromWeb(download.body).pipe(path)
wrile.on('finish', () => resolve())
wrile.on('error', (err) => reject(err))
} else {
reject(download.statusText)
}
})
}
}

if (newArgs.length === 0) {
Expand Down

0 comments on commit f2dece5

Please sign in to comment.