From 92803d4c75c3b4c09ef38e6c57842d70030d5c45 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Wed, 19 Jun 2024 18:38:00 +0530 Subject: [PATCH] chore(js): add more tasks + apply fmt --- package/js/bin/lune.ts | 14 ++-- package/js/build.ts | 62 ++++++++-------- package/js/consts.ts | 8 +-- package/js/deno.json | 10 +-- package/js/deno.lock | 156 ++++++++++++++++++++++++++++++++++++++++- package/js/github.ts | 64 ++++++++--------- package/js/install.ts | 128 +++++++++++++++++---------------- 7 files changed, 301 insertions(+), 141 deletions(-) diff --git a/package/js/bin/lune.ts b/package/js/bin/lune.ts index 3560bf8..04ee0eb 100644 --- a/package/js/bin/lune.ts +++ b/package/js/bin/lune.ts @@ -19,13 +19,13 @@ await checkAndInstallLune(); */ // deno-lint-ignore no-deprecated-deno-api const luneStatus = await Deno.run({ - cmd: [ - path.join(BASE_PATH, consts.version, "lune" + EXE_EXTENSION), - ...Deno.args, - ], - stdout: "inherit", - stderr: "inherit", - stdin: "inherit", + cmd: [ + path.join(BASE_PATH, consts.version, "lune" + EXE_EXTENSION), + ...Deno.args, + ], + stdout: "inherit", + stderr: "inherit", + stdin: "inherit", }).status(); Deno.exit(luneStatus.signal); diff --git a/package/js/build.ts b/package/js/build.ts index 8a65f6d..45a4b45 100644 --- a/package/js/build.ts +++ b/package/js/build.ts @@ -4,35 +4,35 @@ import consts from "./consts.ts"; await emptyDir("./npm"); await build({ - scriptModule: false, - packageManager: "pnpm", - entryPoints: [{ - kind: "bin", - name: consts.name, - path: "./bin/lune.ts", - }], - outDir: "./npm", - shims: { - deno: true, - undici: true, - }, - package: { - name: consts.name, - version: consts.version, - description: "", - license: "MPL-2.0", - repository: { - type: "git", - url: "git+https://github.com/CompeyDev/lune-packaging.git", - }, - bugs: { - url: "https://github.com/CompeyDev/lune-packaging/issues", - }, - }, - postBuild() { - Deno.copyFileSync("LICENSE.md", "npm/LICENSE.md"); - Deno.copyFileSync("README.md", "npm/README.md"); - Deno.copyFileSync("consts.toml", "npm/consts.toml"); - }, - typeCheck: false, // FIXME: This is a problem on dnt's end while importing things + scriptModule: false, + packageManager: "pnpm", + entryPoints: [{ + kind: "bin", + name: consts.name, + path: "./bin/lune.ts", + }], + outDir: "./npm", + shims: { + deno: true, + undici: true, + }, + package: { + name: consts.name, + version: consts.version, + description: "", + license: "MPL-2.0", + repository: { + type: "git", + url: "git+https://github.com/CompeyDev/lune-packaging.git", + }, + bugs: { + url: "https://github.com/CompeyDev/lune-packaging/issues", + }, + }, + postBuild() { + Deno.copyFileSync("LICENSE.md", "npm/LICENSE.md"); + Deno.copyFileSync("README.md", "npm/README.md"); + Deno.copyFileSync("consts.toml", "npm/esm/consts.toml"); + }, + typeCheck: false, // FIXME: This is a problem on dnt's end while importing things }); diff --git a/package/js/consts.ts b/package/js/consts.ts index edfc9f0..b924a1a 100644 --- a/package/js/consts.ts +++ b/package/js/consts.ts @@ -4,9 +4,9 @@ import * as path from "jsr:@std/path"; export const BASE_PATH = path.dirname(path.fromFileUrl(import.meta.url)); export default parseToml( - Deno.readTextFileSync(path.join(BASE_PATH, "consts.toml")), + Deno.readTextFileSync(path.join(BASE_PATH, "consts.toml")), ) as { - name: string; - api_url: string; - version: string; + name: string; + api_url: string; + version: string; }; diff --git a/package/js/deno.json b/package/js/deno.json index 002e0a2..e97436a 100644 --- a/package/js/deno.json +++ b/package/js/deno.json @@ -1,6 +1,8 @@ { - "tasks": { - "lune": "deno run --allow-all bin/lune.ts", - "build": "deno run --allow-all build.ts" - } + "tasks": { + "lune": "deno run --allow-all bin/lune.ts", + "build": "deno run --allow-run --allow-write=npm/ --allow-read --allow-env --allow-sys build.ts", + "clean": "deno run --allow-write=npm/ --allow-read --allow-env npm:rimraf npm/", + "fmt": "deno fmt --use-tabs=true --ignore=LICENSE.md,npm/" + } } diff --git a/package/js/deno.lock b/package/js/deno.lock index 2da3bd8..e84996f 100644 --- a/package/js/deno.lock +++ b/package/js/deno.lock @@ -22,7 +22,8 @@ "npm:c12@1.5.1": "npm:c12@1.5.1", "npm:code-block-writer@^13.0.1": "npm:code-block-writer@13.0.1", "npm:iconv-lite@0.6.3": "npm:iconv-lite@0.6.3", - "npm:jschardet@3.0.0": "npm:jschardet@3.0.0" + "npm:jschardet@3.0.0": "npm:jschardet@3.0.0", + "npm:rimraf": "npm:rimraf@5.0.7" }, "jsr": { "@deno/cache-dir@0.8.0": { @@ -93,6 +94,17 @@ } }, "npm": { + "@isaacs/cliui@8.0.2": { + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dependencies": { + "string-width": "string-width@5.1.2", + "string-width-cjs": "string-width@4.2.3", + "strip-ansi": "strip-ansi@7.1.0", + "strip-ansi-cjs": "strip-ansi@6.0.1", + "wrap-ansi": "wrap-ansi@8.1.0", + "wrap-ansi-cjs": "wrap-ansi@7.0.0" + } + }, "@nodelib/fs.scandir@2.1.5": { "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", "dependencies": { @@ -111,6 +123,10 @@ "fastq": "fastq@1.17.1" } }, + "@pkgjs/parseargs@0.11.0": { + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dependencies": {} + }, "@ts-morph/bootstrap@0.22.0": { "integrity": "sha512-MI5q7pid4swAlE2lcHwHRa6rcjoIMyT6fy8uuZm8BGg7DHGi/H5bQ0GMZzbk3N0r/LfStMdOYPkl+3IwvfIQ2g==", "dependencies": { @@ -134,6 +150,24 @@ "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", "dependencies": {} }, + "ansi-regex@5.0.1": { + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dependencies": {} + }, + "ansi-regex@6.0.1": { + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dependencies": {} + }, + "ansi-styles@4.3.0": { + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "color-convert@2.0.1" + } + }, + "ansi-styles@6.2.1": { + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dependencies": {} + }, "anymatch@3.1.3": { "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", "dependencies": { @@ -204,6 +238,16 @@ "integrity": "sha512-c5or4P6erEA69TxaxTNcHUNcIn+oyxSRTOWV+pSYF+z4epXqNvwvJ70XPGjPNgue83oAFAPBRQYwpAJ/Hpe/Sg==", "dependencies": {} }, + "color-convert@2.0.1": { + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "color-name@1.1.4" + } + }, + "color-name@1.1.4": { + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dependencies": {} + }, "confbox@0.1.7": { "integrity": "sha512-uJcB/FKZtBMCJpK8MQji6bJHgu1tixKPxRLeGkNzBoOZzpnZUJm0jm2/sBDWcuBx1dYgxV4JU+g5hmNxCyAmdA==", "dependencies": {} @@ -232,6 +276,18 @@ "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", "dependencies": {} }, + "eastasianwidth@0.2.0": { + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dependencies": {} + }, + "emoji-regex@8.0.0": { + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dependencies": {} + }, + "emoji-regex@9.2.2": { + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dependencies": {} + }, "execa@8.0.1": { "integrity": "sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==", "dependencies": { @@ -268,6 +324,13 @@ "to-regex-range": "to-regex-range@5.0.1" } }, + "foreground-child@3.2.1": { + "integrity": "sha512-PXUUyLqrR2XCWICfv6ukppP96sdFwWbNEnfEMt7jNsISjMsvaLNinAHNDYyvkyU+SZG2BTSbT5NjG+vZslfGTA==", + "dependencies": { + "cross-spawn": "cross-spawn@7.0.3", + "signal-exit": "signal-exit@4.1.0" + } + }, "fs-minipass@2.1.0": { "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", "dependencies": { @@ -301,6 +364,17 @@ "is-glob": "is-glob@4.0.3" } }, + "glob@10.4.2": { + "integrity": "sha512-GwMlUF6PkPo3Gk21UxkCohOv0PLcIXVtKyLlpEI28R/cO/4eNOdmLk3CMW1wROV/WR/EsZOWAfBbBOqYvs88/w==", + "dependencies": { + "foreground-child": "foreground-child@3.2.1", + "jackspeak": "jackspeak@3.4.0", + "minimatch": "minimatch@9.0.4", + "minipass": "minipass@7.1.2", + "package-json-from-dist": "package-json-from-dist@1.0.0", + "path-scurry": "path-scurry@1.11.1" + } + }, "human-signals@5.0.0": { "integrity": "sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==", "dependencies": {} @@ -321,6 +395,10 @@ "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dependencies": {} }, + "is-fullwidth-code-point@3.0.0": { + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dependencies": {} + }, "is-glob@4.0.3": { "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dependencies": { @@ -339,6 +417,13 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dependencies": {} }, + "jackspeak@3.4.0": { + "integrity": "sha512-JVYhQnN59LVPFCEcVa2C3CrEKYacvjRfqIQl+h8oi91aLYQVWRYbxjPcv1bUiUy/kLmQaANrYfNMCO3kuEDHfw==", + "dependencies": { + "@isaacs/cliui": "@isaacs/cliui@8.0.2", + "@pkgjs/parseargs": "@pkgjs/parseargs@0.11.0" + } + }, "jiti@1.21.6": { "integrity": "sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==", "dependencies": {} @@ -347,6 +432,10 @@ "integrity": "sha512-lJH6tJ77V8Nzd5QWRkFYCLc13a3vADkh3r/Fi8HupZGWk2OVVDfnZP8V/VgQgZ+lzW0kG2UGb5hFgt3V3ndotQ==", "dependencies": {} }, + "lru-cache@10.2.2": { + "integrity": "sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==", + "dependencies": {} + }, "merge-stream@2.0.0": { "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dependencies": {} @@ -382,6 +471,10 @@ "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", "dependencies": {} }, + "minipass@7.1.2": { + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", + "dependencies": {} + }, "minizlib@2.1.2": { "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", "dependencies": { @@ -440,6 +533,10 @@ "mimic-fn": "mimic-fn@4.0.0" } }, + "package-json-from-dist@1.0.0": { + "integrity": "sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==", + "dependencies": {} + }, "path-browserify@1.0.1": { "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", "dependencies": {} @@ -452,6 +549,13 @@ "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", "dependencies": {} }, + "path-scurry@1.11.1": { + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", + "dependencies": { + "lru-cache": "lru-cache@10.2.2", + "minipass": "minipass@7.1.2" + } + }, "pathe@1.1.2": { "integrity": "sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==", "dependencies": {} @@ -493,6 +597,12 @@ "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", "dependencies": {} }, + "rimraf@5.0.7": { + "integrity": "sha512-nV6YcJo5wbLW77m+8KjH8aB/7/rxQy9SZ0HY5shnwULfS+9nmTtVXAJET5NdZmCzA4fPI/Hm1wo/Po/4mopOdg==", + "dependencies": { + "glob": "glob@10.4.2" + } + }, "run-parallel@1.2.0": { "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", "dependencies": { @@ -517,6 +627,34 @@ "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", "dependencies": {} }, + "string-width@4.2.3": { + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "emoji-regex@8.0.0", + "is-fullwidth-code-point": "is-fullwidth-code-point@3.0.0", + "strip-ansi": "strip-ansi@6.0.1" + } + }, + "string-width@5.1.2": { + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dependencies": { + "eastasianwidth": "eastasianwidth@0.2.0", + "emoji-regex": "emoji-regex@9.2.2", + "strip-ansi": "strip-ansi@7.1.0" + } + }, + "strip-ansi@6.0.1": { + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "ansi-regex@5.0.1" + } + }, + "strip-ansi@7.1.0": { + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dependencies": { + "ansi-regex": "ansi-regex@6.0.1" + } + }, "strip-final-newline@3.0.0": { "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", "dependencies": {} @@ -548,6 +686,22 @@ "isexe": "isexe@2.0.0" } }, + "wrap-ansi@7.0.0": { + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dependencies": { + "ansi-styles": "ansi-styles@4.3.0", + "string-width": "string-width@4.2.3", + "strip-ansi": "strip-ansi@6.0.1" + } + }, + "wrap-ansi@8.1.0": { + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dependencies": { + "ansi-styles": "ansi-styles@6.2.1", + "string-width": "string-width@5.1.2", + "strip-ansi": "strip-ansi@7.1.0" + } + }, "yallist@4.0.0": { "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dependencies": {} diff --git a/package/js/github.ts b/package/js/github.ts index db233b1..c91286d 100644 --- a/package/js/github.ts +++ b/package/js/github.ts @@ -3,45 +3,45 @@ import constants from "./consts.ts"; export const GITHUB_RELEASE_API_URL = constants.api_url; type RawGitHubRelease = { - url: string; - assets_url: string; - upload_url: string; - html_url: string; - id: number; - tag_name: string; - created_at: string; - published_at: string; - assets: RawGitHubReleaseAsset[]; + url: string; + assets_url: string; + upload_url: string; + html_url: string; + id: number; + tag_name: string; + created_at: string; + published_at: string; + assets: RawGitHubReleaseAsset[]; }; type RawGitHubReleaseAsset = { - url: string; - id: number; - node_id: string; - name: string; - label: string; - content_type: string; - state: string; - size: number; - download_count: number; - created_at: string; - published_at: string; - browser_download_url: string; + url: string; + id: number; + node_id: string; + name: string; + label: string; + content_type: string; + state: string; + size: number; + download_count: number; + created_at: string; + published_at: string; + browser_download_url: string; }; export async function fetchLuneReleases( - token?: string, + token?: string, ): Promise { - const headers: Record = token - ? { "Authorization": "Bearer " + token } - : {}; + const headers: Record = token + ? { "Authorization": "Bearer " + token } + : {}; - const resp: RawGitHubRelease[] = await fetch( - new Request(GITHUB_RELEASE_API_URL, { - headers, - method: "GET", - }), - ).then((resp) => resp.json()); + const resp: RawGitHubRelease[] = await fetch( + new Request(GITHUB_RELEASE_API_URL, { + headers, + method: "GET", + }), + ).then((resp) => resp.json()); - return resp; + return resp; } diff --git a/package/js/install.ts b/package/js/install.ts index 6b8590f..ddcb981 100644 --- a/package/js/install.ts +++ b/package/js/install.ts @@ -7,10 +7,10 @@ export const LUNE_VERSION = consts.version; export const EXE_EXTENSION = Deno.build.os == "windows" ? ".exe" : ""; async function installLune() { - let ghAuthToken: string | undefined; + let ghAuthToken: string | undefined; - try { - /* + try { + /* Ideally, this would look like this: new TextDecoder().decode( @@ -22,78 +22,82 @@ async function installLune() { However, dnt is yet to support Deno.command */ - ghAuthToken = new TextDecoder().decode( - // deno-lint-ignore no-deprecated-deno-api - await Deno.run({ - cmd: ["gh", "auth", "token"], - stdout: "piped", - }).output(), - ); - } catch (_) { - // Don't use an auth token, be subjected to GitHub ratelimit - } - const releases = await fetchLuneReleases(ghAuthToken); - const currentRelease = releases.find((release) => - release.tag_name === "v" + LUNE_VERSION - )!; - const platformRelease = currentRelease.assets.find((asset) => - asset.name == `lune-${LUNE_VERSION}-${Deno.build.os}-${Deno.build.arch}.zip` - ); + ghAuthToken = new TextDecoder().decode( + // deno-lint-ignore no-deprecated-deno-api + await Deno.run({ + cmd: ["gh", "auth", "token"], + stdout: "piped", + }).output(), + ); + } catch (_) { + // Don't use an auth token, be subjected to GitHub ratelimit + } + const releases = await fetchLuneReleases(ghAuthToken); + const currentRelease = releases.find((release) => + release.tag_name === "v" + LUNE_VERSION + )!; + const platformRelease = currentRelease.assets.find((asset) => + asset.name == `lune-${LUNE_VERSION}-${Deno.build.os}-${Deno.build.arch}.zip` + ); - if (!platformRelease) { - throw new Deno.errors.NotFound( - `UnsupportedPlatform: ${Deno.build.os}-${Deno.build.arch}`, - ); - } + if (!platformRelease) { + throw new Deno.errors.NotFound( + `UnsupportedPlatform: ${Deno.build.os}-${Deno.build.arch}`, + ); + } - const resp = await fetch(platformRelease.browser_download_url); - if (!resp.ok) { - throw new Deno.errors.NotFound( - `Failed to download Lune: ${resp.status}`, - ); - } + const resp = await fetch(platformRelease.browser_download_url); + if (!resp.ok) { + throw new Deno.errors.NotFound( + `Failed to download Lune: ${resp.status}`, + ); + } - const zipFile = await Deno.makeTempFile({ suffix: ".zip" }); - const finalDestDir = path.join(BASE_PATH, consts.version); + const zipFile = await Deno.makeTempFile({ suffix: ".zip" }); + const finalDestDir = path.join(BASE_PATH, consts.version); - const binaryBlob = resp.body!; - await binaryBlob.pipeTo( - (await Deno.open( - zipFile, - { write: true }, - )).writable, - ); + const binaryBlob = resp.body!; + await binaryBlob.pipeTo( + (await Deno.open( + zipFile, + { write: true }, + )).writable, + ); - const binaryPaths = await unzip(zipFile, finalDestDir, { - useWebWorkers: true, - }); + const binaryPaths = await unzip(zipFile, finalDestDir, { + useWebWorkers: true, + }); - if (Deno.build.os !== "windows") await Deno.chmod(binaryPaths[0], 0o777); + if (Deno.build.os !== "windows") await Deno.chmod(binaryPaths[0], 0o777); } export async function checkAndInstallLune() { - const luneExePath = path.join(BASE_PATH, consts.version, "lune" + EXE_EXTENSION); + const luneExePath = path.join( + BASE_PATH, + consts.version, + "lune" + EXE_EXTENSION, + ); - const luneExists = await Deno.lstat(luneExePath).then( - (stat) => { - if (stat.isDirectory) { - Deno.remove(luneExePath, { recursive: true }); - } else if (stat.isFile) { - return true; - } + const luneExists = await Deno.lstat(luneExePath).then( + (stat) => { + if (stat.isDirectory) { + Deno.remove(luneExePath, { recursive: true }); + } else if (stat.isFile) { + return true; + } - return false; - }, - (err) => { - if (err instanceof Deno.errors.NotFound) { - return false; - } + return false; + }, + (err) => { + if (err instanceof Deno.errors.NotFound) { + return false; + } - throw err; - }, - ); + throw err; + }, + ); - if (!luneExists) await installLune(); + if (!luneExists) await installLune(); } await checkAndInstallLune();