Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace fs-extra #62

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"dependencies": {
"consola": "^3.2.3",
"dotenv": "^16.3.1",
"fs-extra": "^11.2.0",
"image-data-uri": "^2.0.1",
"node-html-parser": "^6.1.11",
"ofetch": "^1.3.3",
Expand All @@ -61,7 +60,6 @@
"@antfu/eslint-config": "^2.4.6",
"@antfu/ni": "^0.21.12",
"@antfu/utils": "^0.7.7",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.10.4",
"@types/yargs": "^17.0.32",
"bumpp": "^9.2.1",
Expand Down
22 changes: 3 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { dirname, join, relative, resolve } from 'node:path'
import process from 'node:process'
import fs from 'fs-extra'
import fs from 'node:fs'
import fsp from 'node:fs/promises'
import { consola } from 'consola'
import c from 'picocolors'
import { version } from '../package.json'
Expand Down Expand Up @@ -39,11 +40,11 @@ export async function run(inlineConfig?: SponsorkitConfig, t = consola) {
await resolveAvatars(allSponsors, config.fallbackAvatar, t)
t.success('Avatars resolved')

await fs.ensureDir(dirname(cacheFile))
await fs.writeJSON(cacheFile, allSponsors, { spaces: 2 })
await fsp.mkdir(dirname(cacheFile), { recursive: true })
await fsp.writeFile(cacheFile, JSON.stringify(allSponsors, null, 2))
}
else {
allSponsors = await fs.readJSON(cacheFile)
allSponsors = JSON.parse(await fsp.readFile(cacheFile, 'utf-8'))
t.success(`Loaded from cache ${r(cacheFile)}`)
}

Expand All @@ -54,10 +55,10 @@ export async function run(inlineConfig?: SponsorkitConfig, t = consola) {
|| (b.sponsor.login || b.sponsor.name).localeCompare(a.sponsor.login || a.sponsor.name), // ASC name
)

await fs.ensureDir(dir)
await fsp.mkdir(dir, { recursive: true })
if (config.formats?.includes('json')) {
const path = join(dir, `${config.name}.json`)
await fs.writeJSON(path, allSponsors, { spaces: 2 })
await fsp.writeFile(cacheFile, JSON.stringify(allSponsors, null, 2))
t.success(`Wrote to ${r(path)}`)
}

Expand All @@ -76,13 +77,13 @@ export async function run(inlineConfig?: SponsorkitConfig, t = consola) {

if (config.formats?.includes('svg')) {
const path = join(dir, `${config.name}.svg`)
await fs.writeFile(path, svg, 'utf-8')
await fsp.writeFile(path, svg, 'utf-8')
t.success(`Wrote to ${r(path)}`)
}

if (config.formats?.includes('png')) {
const path = join(dir, `${config.name}.png`)
await fs.writeFile(path, await svgToPng(svg))
await fsp.writeFile(path, await svgToPng(svg))
t.success(`Wrote to ${r(path)}`)
}
}
Expand Down
Loading