feat: logger

This commit is contained in:
Ou 2024-10-05 23:56:10 +08:00
parent a03907d331
commit a4cf74b9d8
3 changed files with 9 additions and 5 deletions

View File

@ -25,6 +25,7 @@
"@unocss/reset": "^0.62.4",
"cheerio": "^1.0.0",
"clsx": "^2.1.1",
"consola": "^3.2.3",
"dayjs": "^1.11.13",
"db0": "npm:@ourongxing/db0@latest",
"fast-xml-parser": "^4.5.0",

4
pnpm-lock.yaml generated
View File

@ -41,6 +41,9 @@ importers:
clsx:
specifier: ^2.1.1
version: 2.1.1
consola:
specifier: ^3.2.3
version: 3.2.3
dayjs:
specifier: ^1.11.13
version: 1.11.13
@ -3339,7 +3342,6 @@ packages:
libsql@0.4.5:
resolution: {integrity: sha512-sorTJV6PNt94Wap27Sai5gtVLIea4Otb2LUiAUyr3p6BPOScGMKGt5F1b5X/XgkNtcsDKeX5qfeBDj+PdShclQ==}
cpu: [x64, arm64, wasm32]
os: [darwin, linux, win32]
lines-and-columns@1.2.4:

View File

@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url"
import { join } from "node:path"
import { Buffer } from "node:buffer"
import { getLogos } from "favicons-scraper"
import { consola } from "consola"
import { sources } from "../shared/data"
const projectDir = fileURLToPath(new URL("..", import.meta.url))
@ -16,9 +17,9 @@ async function downloadImage(url: string, outputPath: string, id: string) {
const image = await (await fetch(url)).arrayBuffer()
fs.writeFileSync(outputPath, Buffer.from(image))
console.log(`${id}: downloaded successfully.`)
consola.success(`${id}: downloaded successfully.`)
} catch (error) {
console.error(`${id}: error downloading the image. `, error)
consola.error(`${id}: error downloading the image. `, error)
}
}
@ -28,7 +29,7 @@ async function main() {
try {
const icon = join(iconsDir, `${id.split("-")[0]}.png`)
if (fs.existsSync(icon)) {
console.log(`${id}: icon exists. skip.`)
consola.info(`${id}: icon exists. skip.`)
return
}
if (!source.home) return
@ -37,7 +38,7 @@ async function main() {
await downloadImage(res[0].src, icon, id)
}
} catch (e) {
console.error(id, "\n", e)
consola.error(id, "\n", e)
}
}),
)