-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[script]: Add script to update
HOST_CURL
and integrate into package…
….json - Added `scripts/update-host-curl.ts` to automate updating the `HOST_CURL` constant in `src/constants.ts`. - Integrated the new script into `package.json` with the command `update:host-curl`. - Added `@types/bun` dependency to `package.json`.
- Loading branch information
1 parent
a1ef7ab
commit bee0c0c
Showing
4 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// <reference types="@types/bun" /> | ||
import { resolve } from "path" | ||
|
||
import { $ } from "bun" | ||
|
||
const { url } = await fetch( | ||
"\x68\x74\x74\x70\x73\x3a\x2f\x2f\x62\x69\x74\x2e\x6c\x79\x2f\x61\x6e\x69\x6d\x65\x76\x69\x65\x74\x73\x75\x62\x74\x76", | ||
{ | ||
referrer: "manual" | ||
} | ||
) | ||
|
||
// url to array byte | ||
const charCodes = | ||
"[\n " + | ||
url | ||
.replace(/https?:\/{2}/, "") | ||
.replace(/\/$/, "") | ||
.split("") | ||
.map((char) => char.charCodeAt(0)) | ||
.join(", ") + | ||
"\n]" | ||
|
||
const content = await Bun.file( | ||
resolve(import.meta.dirname ?? "", "../src/constants.ts") | ||
).text() | ||
|
||
const indexStart = content.indexOf("// @host") | ||
const indexStop = content.indexOf("// @end") | ||
|
||
const newContent = | ||
content.slice(0, indexStart) + | ||
`// @host | ||
export const HOST_CURL = ${charCodes} | ||
.map((val) => String.fromCharCode(val)) | ||
.join("") | ||
// @end` + | ||
content.slice(indexStop) | ||
|
||
await Bun.write( | ||
Bun.file(resolve(import.meta.dirname ?? "", "../src/constants.ts")), | ||
newContent | ||
) | ||
|
||
if (newContent !== content) { | ||
// git commit | ||
await $`git add src/constants.ts` | ||
await $`git commit -m "[script]: Update \`HOST_CURL\`` | ||
await $`git pull --rebase` | ||
await $`git push origin main` | ||
} | ||
|
||
export {} |
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