@seed-design/cli 1.2.2 → 1.4.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.mjs +12 -11
- package/package.json +1 -1
- package/src/commands/add-all.ts +9 -3
- package/src/commands/add.ts +9 -3
- package/src/commands/compat.ts +15 -7
- package/src/commands/docs.ts +312 -0
- package/src/commands/init.ts +9 -2
- package/src/index.ts +2 -0
- package/src/schema.ts +46 -10
- package/src/tests/resolve-dependencies.test.ts +13 -13
- package/src/utils/analytics.ts +1 -2
- package/src/utils/compatibility.ts +38 -11
- package/src/utils/fetch.ts +39 -6
- package/src/utils/get-config.ts +1 -0
- package/src/utils/init-config.ts +29 -1
- package/src/utils/write.ts +3 -0
package/src/utils/fetch.ts
CHANGED
|
@@ -7,15 +7,38 @@ import {
|
|
|
7
7
|
publicRegistryItemSchema,
|
|
8
8
|
type PublicAvailableRegistries,
|
|
9
9
|
publicAvailableRegistriesSchema,
|
|
10
|
+
type DocsIndex,
|
|
11
|
+
docsIndexSchema,
|
|
10
12
|
} from "@/src/schema";
|
|
13
|
+
import { CliError } from "@/src/utils/error";
|
|
14
|
+
|
|
15
|
+
export async function fetchDocsIndex({ baseUrl }: { baseUrl: string }): Promise<DocsIndex> {
|
|
16
|
+
const response = await fetch(`${baseUrl}/__docs__/index.json`);
|
|
17
|
+
|
|
18
|
+
if (!response.ok)
|
|
19
|
+
throw new CliError({
|
|
20
|
+
message: `문서 목록을 가져오지 못했어요: ${response.status} ${response.statusText}`,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const data = await response.json();
|
|
24
|
+
const { success, data: parsed, error } = docsIndexSchema.safeParse(data);
|
|
25
|
+
|
|
26
|
+
if (!success)
|
|
27
|
+
throw new CliError({
|
|
28
|
+
message: `문서 목록 파싱에 실패했어요: ${error?.message}`,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return parsed;
|
|
32
|
+
}
|
|
11
33
|
|
|
12
34
|
export async function fetchAvailableRegistries({
|
|
13
35
|
baseUrl,
|
|
36
|
+
framework,
|
|
14
37
|
}: {
|
|
15
38
|
baseUrl: string;
|
|
39
|
+
framework: string;
|
|
16
40
|
}): Promise<PublicAvailableRegistries> {
|
|
17
|
-
|
|
18
|
-
const response = await fetch(`${baseUrl}/__registry__/index.json`);
|
|
41
|
+
const response = await fetch(`${baseUrl}/__registry__/${framework}/index.json`);
|
|
19
42
|
|
|
20
43
|
if (!response.ok)
|
|
21
44
|
throw new Error(`Failed to fetch registries: ${response.status} ${response.statusText}`);
|
|
@@ -34,12 +57,14 @@ export async function fetchAvailableRegistries({
|
|
|
34
57
|
|
|
35
58
|
export async function fetchRegistry({
|
|
36
59
|
baseUrl,
|
|
60
|
+
framework,
|
|
37
61
|
registryId,
|
|
38
62
|
}: {
|
|
39
63
|
baseUrl: string;
|
|
64
|
+
framework: string;
|
|
40
65
|
registryId: PublicRegistry["id"];
|
|
41
66
|
}): Promise<PublicRegistry> {
|
|
42
|
-
const response = await fetch(`${baseUrl}/__registry__/${registryId}/index.json`);
|
|
67
|
+
const response = await fetch(`${baseUrl}/__registry__/${framework}/${registryId}/index.json`);
|
|
43
68
|
|
|
44
69
|
if (!response.ok)
|
|
45
70
|
throw new Error(
|
|
@@ -56,14 +81,18 @@ export async function fetchRegistry({
|
|
|
56
81
|
|
|
57
82
|
async function fetchRegistryItem({
|
|
58
83
|
baseUrl,
|
|
84
|
+
framework,
|
|
59
85
|
registryId,
|
|
60
86
|
registryItemId,
|
|
61
87
|
}: {
|
|
62
88
|
baseUrl: string;
|
|
89
|
+
framework: string;
|
|
63
90
|
registryId: PublicRegistry["id"];
|
|
64
91
|
registryItemId: PublicRegistryItem["id"];
|
|
65
92
|
}): Promise<PublicRegistryItem> {
|
|
66
|
-
const response = await fetch(
|
|
93
|
+
const response = await fetch(
|
|
94
|
+
`${baseUrl}/__registry__/${framework}/${registryId}/${registryItemId}.json`,
|
|
95
|
+
);
|
|
67
96
|
|
|
68
97
|
if (!response.ok) {
|
|
69
98
|
throw new Error(`Failed to fetch ${registryItemId}: ${response.status} ${response.statusText}`);
|
|
@@ -81,20 +110,24 @@ async function fetchRegistryItem({
|
|
|
81
110
|
|
|
82
111
|
export async function fetchRegistryItems({
|
|
83
112
|
baseUrl,
|
|
113
|
+
framework,
|
|
84
114
|
registryId,
|
|
85
115
|
registryItemIds,
|
|
86
116
|
}: {
|
|
87
117
|
baseUrl: string;
|
|
118
|
+
framework: string;
|
|
88
119
|
registryId: PublicRegistry["id"];
|
|
89
120
|
registryItemIds: PublicRegistryItem["id"][];
|
|
90
121
|
}): Promise<PublicRegistryItem[]> {
|
|
91
122
|
return await Promise.all(
|
|
92
123
|
registryItemIds.map(async (itemId) => {
|
|
93
124
|
try {
|
|
94
|
-
return await fetchRegistryItem({ baseUrl, registryId, registryItemId: itemId });
|
|
125
|
+
return await fetchRegistryItem({ baseUrl, framework, registryId, registryItemId: itemId });
|
|
95
126
|
} catch (error) {
|
|
96
127
|
// show available registry items in the registry
|
|
97
|
-
const response = await fetch(
|
|
128
|
+
const response = await fetch(
|
|
129
|
+
`${baseUrl}/__registry__/${framework}/${registryId}/index.json`,
|
|
130
|
+
);
|
|
98
131
|
|
|
99
132
|
if (!response.ok)
|
|
100
133
|
throw new Error(
|
package/src/utils/get-config.ts
CHANGED
|
@@ -15,6 +15,7 @@ export const configSchema = z
|
|
|
15
15
|
$schema: z.string().optional(),
|
|
16
16
|
rsc: z.coerce.boolean().default(false),
|
|
17
17
|
tsx: z.coerce.boolean().default(true),
|
|
18
|
+
framework: z.enum(["react", "lynx"]).default("react"),
|
|
18
19
|
path: z.string(),
|
|
19
20
|
telemetry: z.coerce.boolean().optional().default(true),
|
|
20
21
|
})
|
package/src/utils/init-config.ts
CHANGED
|
@@ -3,17 +3,36 @@ import fs from "fs-extra";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { highlight } from "./color";
|
|
5
5
|
import { CliCancelError } from "./error";
|
|
6
|
+
import { getPackageInfo } from "./get-package-info";
|
|
6
7
|
|
|
7
8
|
import type { Config } from "./get-config";
|
|
8
9
|
|
|
9
10
|
export const DEFAULT_INIT_CONFIG: Config = {
|
|
10
11
|
rsc: false,
|
|
11
12
|
tsx: true,
|
|
13
|
+
framework: "react",
|
|
12
14
|
path: "./seed-design",
|
|
13
15
|
telemetry: true,
|
|
14
16
|
};
|
|
15
17
|
|
|
16
|
-
export
|
|
18
|
+
export function detectFramework(cwd: string): "react" | "lynx" {
|
|
19
|
+
try {
|
|
20
|
+
const pkg = getPackageInfo(cwd);
|
|
21
|
+
const allDeps = {
|
|
22
|
+
...pkg.dependencies,
|
|
23
|
+
...pkg.devDependencies,
|
|
24
|
+
...pkg.peerDependencies,
|
|
25
|
+
};
|
|
26
|
+
if ("@lynx-js/react" in allDeps || "@seed-design/lynx-react" in allDeps) {
|
|
27
|
+
return "lynx";
|
|
28
|
+
}
|
|
29
|
+
} catch {}
|
|
30
|
+
return "react";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function promptInitConfig(cwd: string): Promise<Config> {
|
|
34
|
+
const detectedFramework = detectFramework(cwd);
|
|
35
|
+
|
|
17
36
|
const group = await p.group(
|
|
18
37
|
{
|
|
19
38
|
tsx: () =>
|
|
@@ -26,6 +45,15 @@ export async function promptInitConfig(): Promise<Config> {
|
|
|
26
45
|
message: `${highlight("React Server Components")}를 사용중이신가요?`,
|
|
27
46
|
initialValue: DEFAULT_INIT_CONFIG.rsc,
|
|
28
47
|
}),
|
|
48
|
+
framework: () =>
|
|
49
|
+
p.select({
|
|
50
|
+
message: `어떤 ${highlight("프레임워크")}를 사용하시나요?`,
|
|
51
|
+
initialValue: detectedFramework,
|
|
52
|
+
options: [
|
|
53
|
+
{ value: "react" as const, label: "React" },
|
|
54
|
+
{ value: "lynx" as const, label: "Lynx" },
|
|
55
|
+
],
|
|
56
|
+
}),
|
|
29
57
|
path: () =>
|
|
30
58
|
p.text({
|
|
31
59
|
message: `${highlight("seed-design 폴더")} 경로를 입력해주세요. (기본값은 프로젝트 루트에 생성됩니다.)`,
|
package/src/utils/write.ts
CHANGED
|
@@ -14,6 +14,7 @@ export async function writeRegistryItemSnippets({
|
|
|
14
14
|
rootPath,
|
|
15
15
|
cwd,
|
|
16
16
|
baseUrl,
|
|
17
|
+
framework,
|
|
17
18
|
config,
|
|
18
19
|
onDiff,
|
|
19
20
|
}: {
|
|
@@ -21,6 +22,7 @@ export async function writeRegistryItemSnippets({
|
|
|
21
22
|
rootPath: string;
|
|
22
23
|
cwd: string;
|
|
23
24
|
baseUrl: string;
|
|
25
|
+
framework: string;
|
|
24
26
|
config: Config;
|
|
25
27
|
onDiff?: "overwrite" | "backup";
|
|
26
28
|
}) {
|
|
@@ -33,6 +35,7 @@ export async function writeRegistryItemSnippets({
|
|
|
33
35
|
|
|
34
36
|
const registryItems = await fetchRegistryItems({
|
|
35
37
|
baseUrl,
|
|
38
|
+
framework,
|
|
36
39
|
registryId,
|
|
37
40
|
registryItemIds: items.map((i) => i.id),
|
|
38
41
|
});
|