-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathhelper.ts
More file actions
33 lines (27 loc) · 927 Bytes
/
helper.ts
File metadata and controls
33 lines (27 loc) · 927 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
28
29
30
31
32
33
// Importing JSON directly
import pkg from "@/package.json";
import { generatePort } from "@examples/e2e";
const BASE_PATH = process.env.BASE_PATH || "";
const BASE_URL = process.env.BASE_URL;
const host =
process.env.NODE_ENV === "development"
? (port: number) => `http://localhost:${port}`
: () => (BASE_URL ? new URL(BASE_URL).origin : "");
export function getDemos() {
return Object.keys(pkg.dependencies)
.filter((dep) => dep.startsWith("@demo/"))
.map((pkgname) => {
const demoname = pkgname.split("@demo/")[1];
const port = generatePort(demoname);
const h = host(port);
const embed_url = `${h}${BASE_PATH}/${demoname}`;
const website_url = `${h}${BASE_PATH}/demos/${demoname}`;
return {
name: demoname,
thumb: `${embed_url}/thumbnail.png`,
snap: `${embed_url}/snapshot.png`,
embed_url,
website_url,
};
});
}