-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.ts
34 lines (31 loc) · 885 Bytes
/
generate.ts
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
28
29
30
31
32
33
34
import type { PackageInfo } from "./get_package_info.ts";
interface SimpleImportMap {
imports: { [key: string]: string };
}
export function generateImportMap(
packages: { [key: string]: PackageInfo },
): SimpleImportMap {
const imports = Object.fromEntries(
Object.entries(packages).map(
([
name,
{ version, module },
]) => [name, `https://cdn.jsdelivr.net/npm/${name}@${version}/${module}`],
),
);
return { imports };
}
export function generateTypedImports(
packages: { [key: string]: PackageInfo },
): string {
return Object.entries(packages).map(
([
name,
{ version, module, types },
]) =>
[
`// @deno-types="https://cdn.jsdelivr.net/npm/${name}@${version}/${types}"`,
`import "https://cdn.jsdelivr.net/npm/${name}@${version}/${module}";`,
].join("\n"),
).join("\n\n") + "\n";
}