Skip to content

Commit

Permalink
feat: more logging for checking for updates, added full length `--qui…
Browse files Browse the repository at this point in the history
…et` flag
  • Loading branch information
Mon4ik committed Sep 24, 2024
1 parent a3f5cd0 commit 73f3e03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ program
.version("1.0.0")

program.command('cleanup')
.description('Clean persist, or clean all app settings (by default cleans only cache)')
.description('Clean persist, logs or all app settings (by default cleans only cache)')
.argument("<entry>", "What to delete (persist, logs, all)")
.option("--all", "DELETES EVERYTHING (configs, cache)! Be careful!")
.option("-f, --force", "Delete without questions")
Expand All @@ -41,8 +41,6 @@ program.command('cleanup')
fs.rmSync(path, { recursive: true, force: true })
}



switch (entry) {
case "persist":
await promptDelete(Globals.persistPath());
Expand Down Expand Up @@ -86,14 +84,14 @@ program.command('oauth')

program.command('start')
.description('Starts bridge')
.option("-q", "Start quietly (no QRCodes, codes)")
.option("-q, --quiet", "Start quietly (no QRCodes, codes)")
.option("-U, --noUpdates", "Don't check updates")
.option("--debug", "Enables debug mode")
.action(async (options) => {
Globals.setDebug(options.debug ?? false)
Globals.setQuiet(options.q ?? false)
Globals.setQuiet(options.quiet ?? false)

if (!options.noUpdates) await checkForUpdates()
if (!(options.noUpdates ?? false) && !(options.quiet ?? false)) await checkForUpdates()

const bridge = new YandexBridge()

Expand All @@ -112,8 +110,6 @@ program.command('start')
}
)
})

// console.log("end?")
});

program.parse(process.argv);
8 changes: 7 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export const SERVICE_MAP = new Map<string, typeof Service>([
export async function checkForUpdates() {
const resp = await axios("https://api.github.com/repos/Mon4ik/yandex-homekit/releases", { validateStatus: () => true })
if (resp.data.message || !Array.isArray(resp.data) || resp.status >= 400) {
Globals.getLogger().error("Got error while checking for updates.")
Globals.getLogger().error("Couldn't check for updates. Ignoring updates...")

Globals.getLogger().debug(` Status : ${resp.status}`)
Globals.getLogger().debug(` Message: ${resp.data.message}`)

return
}

Expand All @@ -42,5 +46,7 @@ export async function checkForUpdates() {
chalk.green` $ ` + chalk.bold`npm i -g yandex-homekit@latest`
].join("\n"), { padding: 0.5, borderStyle: "round", dimBorder: true, textAlignment: "center" }));
console.info(chalk.grey`Additional information: ` + chalk.grey.bold.underline(latestRelease.html_url))
} else {
Globals.getLogger().debug(`Didn't find new updates. Latest: ${latestRelease.tag_name}`)
}
}

0 comments on commit 73f3e03

Please sign in to comment.