setup-cpp/src/check-updates.ts

24 lines
703 B
TypeScript
Raw Normal View History

import { warning } from "ci-log"
2023-05-24 12:26:47 +08:00
import { promises } from "fs"
const { readFile } = promises
import { join } from "path"
// auto self update notifier
export async function checkUpdates() {
try {
2023-05-24 12:37:34 +08:00
const [un, packageJsonString] = await Promise.all([
import("update-notifier"),
readFile(join(__dirname, "..", "package.json"), "utf8"),
])
const packageJson = JSON.parse(packageJsonString)
2023-05-24 12:37:34 +08:00
// the types do not match the actual export
const updateNotifier = un as unknown as (typeof un)["default"]
updateNotifier({ pkg: packageJson }).notify()
} catch (err) {
2023-05-24 12:37:34 +08:00
warning(`Failed to check for updates: ${err instanceof Error ? err.message + err.stack : err}`)
}
}