Skip to content

Commit 97bf0df

Browse files
committed
feat: implement getTemplatesList function to fetch template configurations
1 parent 5f20107 commit 97bf0df

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import helloWorld from './modules/helloWorld'
2+
import { getTemplatesList } from './modules/repo'
23

3-
console.log(helloWorld('typescript!'))
4+
console.log(await getTemplatesList())

src/modules/repo.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { fetch } from 'undici'
2+
3+
export interface TemplateMeta {
4+
name: string
5+
description: string
6+
author?: string
7+
repository:
8+
| string
9+
| {
10+
url: string
11+
}
12+
}
13+
14+
type TemplatesJson = { templates: TemplateMeta[] }
15+
16+
export const getTemplatesList = async (templatesFileUrl?: string) => {
17+
if (!templatesFileUrl) {
18+
templatesFileUrl =
19+
'https://raw.githubusercontent.com/pkgtoolsjs/pkgtools/refs/heads/main/templates.json'
20+
}
21+
22+
const res = await fetch(templatesFileUrl)
23+
const json = res.json() as unknown as TemplatesJson
24+
25+
return json
26+
}

0 commit comments

Comments
 (0)