Skip to content

Commit ef88c24

Browse files
committed
feat: init get-bonus structure
1 parent 1ff2bc9 commit ef88c24

File tree

8 files changed

+117
-14
lines changed

8 files changed

+117
-14
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
node_modules
33

44
# Nuxt dev/build outputs
5+
.turbo
56
.output
67
.data
78
.nuxt

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "get-bonus",
2+
"name": "@get-bonus/monorepo",
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"build": "nuxt build",
6+
"build": "turbo run build && nuxt build",
77
"dev": "nuxt dev",
88
"generate": "nuxt generate",
99
"postinstall": "nuxt prepare",

packages/get-bonus/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@
3636
},
3737
"engines": {
3838
"node": ">=v20.10.0"
39+
},
40+
"dependencies": {
41+
"cheerio": "1.0.0-rc.12"
3942
}
4043
}

packages/get-bonus/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export function hello() {
2-
return 'world';
3-
}
1+
export * from './scraper';
2+
3+
export * from './melonbooks';
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Detail, SearchResult } from '../types';
2+
3+
import { Provider } from '../scraper';
4+
5+
export class Melonbooks extends Provider {
6+
constructor() {
7+
super('melonbooks');
8+
}
9+
10+
search(text: string): Promise<SearchResult[]> {
11+
throw new Error('Method not implemented.');
12+
}
13+
14+
detail(url: string): Promise<Detail> {
15+
throw new Error('Method not implemented.');
16+
}
17+
}

packages/get-bonus/src/scraper.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { SearchResult, Detail } from './types';
2+
3+
export class Scraper {
4+
private readonly providers: Provider[];
5+
6+
public constructor(...providers: Provider[]) {
7+
this.providers = providers;
8+
}
9+
10+
async search(text: string) {
11+
const results = await Promise.all(
12+
this.providers.map(async (provider) => {
13+
const resp = await provider.search(text);
14+
return resp;
15+
})
16+
);
17+
return results;
18+
}
19+
20+
async getDetail(platform: string, url: string) {
21+
const providers = this.providers.filter((p) => p.platform === platform);
22+
}
23+
24+
async getAllDetails(search: SearchResult[]) {}
25+
}
26+
27+
export abstract class Provider {
28+
public readonly platform: string;
29+
30+
constructor(name: string) {
31+
this.platform = name;
32+
}
33+
34+
abstract search(text: string): Promise<SearchResult[]>;
35+
36+
abstract detail(url: string): Promise<Detail>;
37+
}

packages/get-bonus/src/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface SearchResult {}
2+
3+
export interface Detail {}

pnpm-lock.yaml

+51-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)