1export interface RequiredDecodedPackageJson {
2 name: string;
3 private?: boolean;
4 version: string;
5 type?: string;
6 scripts: KeyStringObject;
7 dependencies: KeyStringObject;
8 devDependencies: KeyStringObject;
9 [key: string]: any | undefined;
10}
11export type TPkgType =
12 | "React+Vite"
13 | "React+Relay"
14 | "Rakkasjs"
15 | "Nextjs"
16 | "Nodejs"
17 | "Deno"
18 | "React-native"
19 | "Bun"
20 | "Others";
21
22export function pkgTypeCondition(pkg: RequiredDecodedPackageJson): {
23 pkg_type: TPkgType;
24 condition: boolean;
25} {
26 const pkgs_string = JSON.stringify({
27 ...pkg.dependencies,
28 ...pkg.devDependencies,
29 });
30 if (pkgs_string.includes("rakkas")) {
31 return { pkg_type: "Rakkasjs", condition: true };
32 }
33 if (pkgs_string.includes("react-native")) {
34 return { pkg_type: "React-native", condition: true };
35 }
36
37 if (pkg.dependencies?.next) {
38 return { pkg_type: "Nextjs", condition: true };
39 }
40
41 if (pkg.dependencies?.react && pkg.dependencies?.["react-relay"]) {
42 return { pkg_type: "React+Relay", condition: true };
43 }
44
45 if (pkg.devDependencies?.vite && pkg.dependencies?.react) {
46 return { pkg_type: "React+Vite", condition: true };
47 }
48
49 if (
50 pkgs_string.includes("nodemon") ||
51 pkgs_string.includes("tsup") ||
52 pkgs_string.includes("fastify") ||
53 pkgs_string.includes("express") ||
54 pkgs_string.includes("nestjs") ||
55 pkgs_string.includes("mongoose")
56 ) {
57 return { pkg_type: "Nodejs", condition: true };
58 }
59 return { pkg_type: "Others", condition: false };
60}