Skip to content

Commit e4d390e

Browse files
committed
chore: biome format
1 parent 616c126 commit e4d390e

File tree

6 files changed

+111
-53
lines changed

6 files changed

+111
-53
lines changed

.vscode/settings.json

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
{
22
"yaml.schemas": {
3-
"src/raw-books.schema.json": [
4-
"src/books.yml"
5-
]
3+
"src/raw-books.schema.json": ["src/books.yml"]
4+
},
5+
"[javascript]": {
6+
"editor.defaultFormatter": "biomejs.biome",
7+
"editor.codeActionsOnSave": {
8+
"source.fixAll": "always",
9+
"quickfix.biome": "always",
10+
"source.organizeImports.biome": "always"
11+
}
12+
},
13+
"[json]": {
14+
"editor.defaultFormatter": "biomejs.biome",
15+
"editor.codeActionsOnSave": {
16+
"source.fixAll": "always",
17+
"quickfix.biome": "always",
18+
"source.organizeImports.biome": "always"
19+
}
20+
},
21+
"[typescript]": {
22+
"editor.defaultFormatter": "biomejs.biome",
23+
"editor.codeActionsOnSave": {
24+
"source.fixAll": "always",
25+
"quickfix.biome": "always",
26+
"source.organizeImports.biome": "always"
27+
}
628
}
7-
}
29+
}

biome.json

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
3-
"organizeImports": {
4-
"enabled": true
5-
},
6-
"linter": {
7-
"enabled": true,
8-
"rules": {
9-
"recommended": true
10-
}
11-
}
2+
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
3+
"organizeImports": {
4+
"enabled": true
5+
},
6+
"linter": {
7+
"enabled": true,
8+
"rules": {
9+
"recommended": true,
10+
"nursery": {
11+
"all": true,
12+
"noNodejsModules": "off",
13+
"useImportRestrictions": "off",
14+
"noConsole": "off"
15+
},
16+
"correctness": {
17+
"all": true
18+
}
19+
},
20+
"ignore": ["coverage/", "dist/", "node_modules/", "docs/"]
21+
},
22+
"formatter": {
23+
"enabled": true,
24+
"formatWithErrors": false,
25+
"indentStyle": "space",
26+
"indentWidth": 2,
27+
"lineWidth": 80,
28+
"ignore": ["coverage/", "dist/", "node_modules/", "docs/"]
29+
},
30+
"javascript": {
31+
"formatter": {
32+
"semicolons": "asNeeded",
33+
"quoteStyle": "single"
34+
}
35+
}
1236
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
"turndown": "^7.1.3",
2323
"yaml": "^2.4.1"
2424
}
25-
}
25+
}

scripts/importFromAmazon.ts

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import path from 'node:path'
21
import fs from 'node:fs'
3-
import {readFile} from 'node:fs/promises'
4-
import {Writable} from 'node:stream';
5-
import * as cheerio from 'cheerio'
2+
import { readFile } from 'node:fs/promises'
3+
import path from 'node:path'
4+
import { Writable } from 'node:stream'
5+
import { load } from 'cheerio'
66
import slugify from 'slugify'
77
import TurndownService from 'turndown'
8-
import * as yaml from 'yaml'
8+
import { parse, stringify } from 'yaml'
99

1010
const __dirname = path.dirname(new URL(import.meta.url).pathname)
1111
const srcDir = path.join(__dirname, '..', 'src')
@@ -14,8 +14,10 @@ const slug = slugify.default
1414
const turndownService = new TurndownService()
1515

1616
const rawBooksContent = await readFile(path.join(srcDir, 'books.yml'), 'utf8')
17-
const rawBooks = yaml.parse(rawBooksContent)
18-
const rawBooksSlugs = new Set((rawBooks || []).map((book: {slug: string}) => book.slug))
17+
const rawBooks = parse(rawBooksContent)
18+
const rawBooksSlugs = new Set(
19+
(rawBooks || []).map((book: { slug: string }) => book.slug),
20+
)
1921

2022
const [, , ...ids] = process.argv
2123

@@ -24,7 +26,8 @@ for (const id of ids) {
2426
const amazon_uk = `https://www.amazon.co.uk/dp/${id}`
2527
const req = await fetch(amazon_us, {
2628
headers: {
27-
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
29+
Accept:
30+
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
2831
'Accept-Encoding': 'gzip, deflate, br, zstd',
2932
'Accept-Language': 'en-US,en;q=0.9',
3033
'Cache-Control': 'no-cache',
@@ -35,7 +38,8 @@ for (const id of ids) {
3538
Rtt: '0',
3639
'Sec-Ch-Device-Memory': '8',
3740
'Sec-Ch-Dpr': '2.2',
38-
'Sec-Ch-Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
41+
'Sec-Ch-Ua':
42+
'"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
3943
'Sec-Ch-Ua-Mobile': '?0',
4044
'Sec-Ch-Ua-Platform': '"macOS"',
4145
'Sec-Ch-Ua-Platform-Version': '"14.3.1"',
@@ -45,9 +49,10 @@ for (const id of ids) {
4549
'Sec-Fetch-Site': 'none',
4650
'Sec-Fetch-User': '?1',
4751
'Upgrade-Insecure-Requests': '1',
48-
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
49-
'Viewport-Width': '336'
50-
}
52+
'User-Agent':
53+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
54+
'Viewport-Width': '336',
55+
},
5156
})
5257
const content = await req.text()
5358

@@ -56,32 +61,44 @@ for (const id of ids) {
5661
continue
5762
}
5863

59-
const $ = cheerio.load(content)
60-
const [title, subtitle] = $('#productTitle').text().trim().split(':', 2).map(s => s?.trim())
64+
const $ = load(content)
65+
const [title, subtitle] = $('#productTitle')
66+
.text()
67+
.trim()
68+
.split(':', 2)
69+
.map((s) => s?.trim())
6170

62-
const edition = Number.parseInt($('#productSubtitle').text().trim().substring(0,1) || '1') || 1
71+
const edition =
72+
Number.parseInt(
73+
$('#productSubtitle').text().trim().substring(0, 1) || '1',
74+
) || 1
6375
const authors = $('#bylineInfo .author')
6476
.filter((_i, el) => $(el).text().trim().includes('(Author)'))
6577
.map((_i, el) => $(el).find('.a-link-normal').text().trim())
6678
.toArray()
67-
const description = $('#bookDescription_feature_div .a-expander-content')?.html()?.trim() || ''
79+
const description =
80+
$('#bookDescription_feature_div .a-expander-content')?.html()?.trim() || ''
6881

69-
const descriptionMd = turndownService.turndown(description)
82+
const descriptionMd = turndownService
83+
.turndown(description)
7084
.split('\n')
71-
.map(l => l.trimEnd())
85+
.map((l) => l.trimEnd())
7286
.join('\n')
7387
.replace(/\n\r?(\n\r?)+/g, '\n')
74-
.replace(//g, '\'')
88+
.replace(//g, "'")
7589
.replace(/ /g, ' ')
7690
.replace(//g, '-')
77-
91+
7892
const coverUrl = $('#imgTagWrapperId img').attr('src')
7993
const links = {
8094
amazon_us,
8195
amazon_uk,
8296
}
8397

84-
const bookSlug = slug(`${title}-${edition}-${authors.join('-')}`, {lower: true, strict: true})
98+
const bookSlug = slug(`${title}-${edition}-${authors.join('-')}`, {
99+
lower: true,
100+
strict: true,
101+
})
85102
if (rawBooksSlugs.has(bookSlug)) {
86103
console.error(`Skipping "${title}" (already exists)`)
87104
continue
@@ -105,5 +122,5 @@ for (const id of ids) {
105122
}
106123

107124
console.error(`Imported ${title}`)
108-
console.log(yaml.stringify([data]))
109-
}
125+
console.log(stringify([data]))
126+
}

src/raw-books.schema.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
"type": "string"
4646
}
4747
},
48-
"required": [
49-
"title",
50-
"authors",
51-
"links",
52-
"description"
53-
]
48+
"required": ["title", "authors", "links", "description"]
5449
}
55-
}
50+
}

tsconfig.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"compilerOptions": {
33
"allowJs": true,
4-
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
5-
"module": "NodeNext", /* Specify what module code is generated. */
6-
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
7-
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
8-
"strict": true, /* Enable all strict type-checking options. */
9-
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
4+
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
5+
"module": "NodeNext" /* Specify what module code is generated. */,
6+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
7+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
8+
"strict": true /* Enable all strict type-checking options. */,
9+
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
1010
"rootDir": ".",
11-
"outDir": "lib",
11+
"outDir": "lib"
1212
}
13-
}
13+
}

0 commit comments

Comments
 (0)