Skip to content

Commit 676c032

Browse files
committed
chore: dont remove downloaded tgz
1 parent a8601fe commit 676c032

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
node_modules
3-
.DS_store
3+
.DS_store
4+
*.tgz

download.mjs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import { x } from 'tar'
55
// Read GitHub proxy from environment variable
66
const githubProxy = process.env.GITHUB || 'github.com'
77
const REPO = 'subframe7536/sqwab'
8-
8+
const cliTag = process.argv[2]
99
async function getLatestTag() {
10+
if (cliTag) {
11+
if (!cliTag.startsWith('v')) {
12+
return `v${cliTag}`
13+
}
14+
return cliTag
15+
}
1016
const apiURL = `https://api.github.com/repos/${REPO}/tags`
1117
try {
1218
const response = await fetch(apiURL)
@@ -40,42 +46,39 @@ async function downloadAndExtractRelease(tag, outputDir) {
4046
const releaseUrl = `https://github.com/${REPO}/releases/${tag}`
4147
const downloadUrl = `https://${githubProxy}/${REPO}/releases/download/${tag}/wa-sqlite.dist.tgz`
4248
const target = `wasqlite-fts5-${tag}.tgz`
43-
try {
44-
if (!existsSync(target)) {
45-
console.log(`Downloading from ${downloadUrl}`)
46-
const resp = await fetch(downloadUrl, {
47-
method: 'GET',
48-
headers: {
49-
'Accept': 'application/gzip',
50-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
51-
},
52-
})
53-
54-
if (!resp.ok) {
55-
throw new Error(`Download fail: ${resp.statusText}`)
56-
}
49+
if (existsSync(target)) {
50+
rmSync(target)
51+
}
52+
if (!existsSync(target)) {
53+
console.log(`Downloading from ${downloadUrl}`)
54+
const resp = await fetch(downloadUrl, {
55+
method: 'GET',
56+
headers: {
57+
'Accept': 'application/gzip',
58+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
59+
},
60+
})
5761

58-
writeFileSync(target, new Uint8Array(await resp.arrayBuffer()))
62+
if (!resp.ok) {
63+
throw new Error(`Download fail: ${resp.statusText}`)
5964
}
6065

61-
console.log('Extracting...')
62-
await x({
63-
file: target,
64-
cwd: outputDir,
65-
})
66+
writeFileSync(target, new Uint8Array(await resp.arrayBuffer()))
67+
}
6668

67-
console.log('Updating README.md')
69+
console.log('Extracting...')
70+
await x({
71+
file: target,
72+
cwd: outputDir,
73+
})
6874

69-
writeFileSync(
70-
`${outputDir}/README.md`,
71-
`# wa-sqlite fts5\n\nDownload from https://github.com/${REPO}\n\nTag [\`${tag}\`](${releaseUrl})\n`,
72-
'utf-8',
73-
)
74-
} finally {
75-
if (existsSync(target)) {
76-
rmSync(target)
77-
}
78-
}
75+
console.log('Updating README.md')
76+
77+
writeFileSync(
78+
`${outputDir}/README.md`,
79+
`# wa-sqlite fts5\n\nDownload from https://github.com/${REPO}\n\nTag [\`${tag}\`](${releaseUrl})\n`,
80+
'utf-8',
81+
)
7982
}
8083

8184
getLatestTag()

0 commit comments

Comments
 (0)