forked from nuxt/modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
27 lines (21 loc) · 815 Bytes
/
Copy pathutils.ts
File metadata and controls
27 lines (21 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { resolve } from 'node:path'
import { ofetch } from 'ofetch'
export const rootDir = resolve(__dirname, '..')
export const modulesDir = resolve(rootDir, 'modules')
export const distDir = resolve(rootDir)
export const distFile = resolve(distDir, 'modules.json')
export function fetchPKG(name: string) {
return ofetch('http://registry.npmjs.org/' + name)
}
export function fetchRawGithub(path: string) {
return ofetch('https://raw.githubusercontent.com/' + path, { responseType: 'json' })
}
export function fetchGithubPkg(repo: string) {
let path: string
// HEAD will be the default branch
[repo, path = 'HEAD'] = repo.split('#') as [string, string?]
return fetchRawGithub(repo + '/' + path + '/' + 'package.json')
}
export function uniq<T>(items: T[]) {
return Array.from(new Set(items))
}