ui-thing 0.2.9 → 0.3.1
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/.claude/settings.local.json +5 -0
- package/.github/workflows/main.yml +7 -4
- package/.github/workflows/test.yml +7 -4
- package/.prettierrc +1 -1
- package/CHANGELOG.md +52 -0
- package/README.md +208 -21
- package/bun.lock +171 -134
- package/dist/index.js +28 -25
- package/dist/index.js.map +1 -1
- package/package.json +15 -14
- package/src/commands/add.ts +41 -12
- package/src/commands/block.ts +5 -3
- package/src/commands/list.ts +48 -0
- package/src/commands/prose.ts +7 -3
- package/src/commands/remove.ts +109 -0
- package/src/commands/theme.ts +5 -14
- package/src/commands/update.ts +81 -0
- package/src/index.ts +6 -0
- package/src/types.ts +12 -0
- package/src/utils/config.ts +9 -16
- package/src/utils/constants.ts +1 -0
- package/src/utils/fetchBlockCategories.ts +13 -11
- package/src/utils/fetchBlocks.ts +13 -11
- package/src/utils/fetchComponents.ts +13 -11
- package/src/utils/fetchProseComponents.ts +13 -11
- package/src/utils/installPackages.ts +30 -4
- package/src/utils/installValidator.ts +3 -3
- package/src/utils/logger.ts +9 -0
- package/src/utils/uiConfigPrompt.ts +3 -6
- package/tests/commands/add.test.ts +136 -0
- package/tests/commands/list.test.ts +111 -0
- package/tests/commands/remove.test.ts +151 -0
- package/tests/commands/update.test.ts +127 -0
- package/tests/utils/fetchBlockCategories.test.ts +14 -2
- package/tests/utils/fetchBlocks.test.ts +14 -2
- package/tests/utils/fetchComponents.test.ts +10 -4
- package/tests/utils/fetchProseComponents.test.ts +14 -2
- package/tests/utils/installPackages.test.ts +36 -3
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { runUpdateCommand } from "../../src/commands/update";
|
|
4
|
+
import { Component } from "../../src/types";
|
|
5
|
+
|
|
6
|
+
vi.mock("../../src/utils/fetchComponents");
|
|
7
|
+
vi.mock("../../src/utils/config");
|
|
8
|
+
vi.mock("../../src/utils/fileExists");
|
|
9
|
+
vi.mock("../../src/utils/writeFile");
|
|
10
|
+
vi.mock("../../src/utils/logger");
|
|
11
|
+
vi.mock("../../src/utils/printFancyBoxMessage");
|
|
12
|
+
vi.mock("prompts");
|
|
13
|
+
|
|
14
|
+
const mockComponents: Component[] = [
|
|
15
|
+
{
|
|
16
|
+
name: "Button",
|
|
17
|
+
value: "button",
|
|
18
|
+
files: [{ fileName: "Button.vue", dirPath: "app/components/Ui", fileContent: "<button />" }],
|
|
19
|
+
utils: [],
|
|
20
|
+
composables: [],
|
|
21
|
+
plugins: [],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "Input",
|
|
25
|
+
value: "input",
|
|
26
|
+
files: [{ fileName: "Input.vue", dirPath: "app/components/Ui", fileContent: "<input />" }],
|
|
27
|
+
utils: [],
|
|
28
|
+
composables: [],
|
|
29
|
+
plugins: [],
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
describe("commands/update", () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
vi.clearAllMocks();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
vi.restoreAllMocks();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should update a named component and overwrite its files", async () => {
|
|
43
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
44
|
+
const { getUIConfig } = await import("../../src/utils/config");
|
|
45
|
+
const { writeFile } = await import("../../src/utils/writeFile");
|
|
46
|
+
const { logger } = await import("../../src/utils/logger");
|
|
47
|
+
|
|
48
|
+
vi.mocked(getUIConfig).mockResolvedValue({ componentsLocation: "app/components/Ui" } as any);
|
|
49
|
+
vi.mocked(fetchComponents).mockResolvedValue(mockComponents);
|
|
50
|
+
|
|
51
|
+
await runUpdateCommand(["button"]);
|
|
52
|
+
|
|
53
|
+
expect(vi.mocked(writeFile)).toHaveBeenCalledWith(
|
|
54
|
+
expect.stringContaining("Button.vue"),
|
|
55
|
+
"<button />"
|
|
56
|
+
);
|
|
57
|
+
expect(vi.mocked(logger.success)).toHaveBeenCalledWith("Updated: Button.vue");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should warn for unknown component names", async () => {
|
|
61
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
62
|
+
const { getUIConfig } = await import("../../src/utils/config");
|
|
63
|
+
const { logger } = await import("../../src/utils/logger");
|
|
64
|
+
|
|
65
|
+
vi.mocked(getUIConfig).mockResolvedValue({ componentsLocation: "app/components/Ui" } as any);
|
|
66
|
+
vi.mocked(fetchComponents).mockResolvedValue(mockComponents);
|
|
67
|
+
|
|
68
|
+
await runUpdateCommand(["nonexistent"]);
|
|
69
|
+
|
|
70
|
+
expect(vi.mocked(logger.warn)).toHaveBeenCalledWith(expect.stringContaining("nonexistent"));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should prompt for selection when no names given and components are installed", async () => {
|
|
74
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
75
|
+
const { getUIConfig } = await import("../../src/utils/config");
|
|
76
|
+
const { fileExists } = await import("../../src/utils/fileExists");
|
|
77
|
+
const { writeFile } = await import("../../src/utils/writeFile");
|
|
78
|
+
const prompts = await import("prompts");
|
|
79
|
+
|
|
80
|
+
vi.mocked(getUIConfig).mockResolvedValue({ componentsLocation: "app/components/Ui" } as any);
|
|
81
|
+
vi.mocked(fetchComponents).mockResolvedValue(mockComponents);
|
|
82
|
+
vi.mocked(fileExists).mockResolvedValueOnce(true).mockResolvedValueOnce(false);
|
|
83
|
+
vi.mocked(prompts.default).mockResolvedValue({ selected: ["button"] });
|
|
84
|
+
|
|
85
|
+
await runUpdateCommand([]);
|
|
86
|
+
|
|
87
|
+
expect(vi.mocked(writeFile)).toHaveBeenCalledWith(
|
|
88
|
+
expect.stringContaining("Button.vue"),
|
|
89
|
+
"<button />"
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should exit cleanly when user cancels the prompt", async () => {
|
|
94
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
95
|
+
const { getUIConfig } = await import("../../src/utils/config");
|
|
96
|
+
const { fileExists } = await import("../../src/utils/fileExists");
|
|
97
|
+
const { writeFile } = await import("../../src/utils/writeFile");
|
|
98
|
+
const prompts = await import("prompts");
|
|
99
|
+
|
|
100
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => {}) as any);
|
|
101
|
+
|
|
102
|
+
vi.mocked(getUIConfig).mockResolvedValue({ componentsLocation: "app/components/Ui" } as any);
|
|
103
|
+
vi.mocked(fetchComponents).mockResolvedValue(mockComponents);
|
|
104
|
+
vi.mocked(fileExists).mockResolvedValue(true);
|
|
105
|
+
vi.mocked(prompts.default).mockResolvedValue({ selected: [] });
|
|
106
|
+
|
|
107
|
+
await runUpdateCommand([]);
|
|
108
|
+
|
|
109
|
+
expect(exitSpy).toHaveBeenCalledWith(0);
|
|
110
|
+
expect(vi.mocked(writeFile)).not.toHaveBeenCalled();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("should show info message when no installed components found", async () => {
|
|
114
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
115
|
+
const { getUIConfig } = await import("../../src/utils/config");
|
|
116
|
+
const { fileExists } = await import("../../src/utils/fileExists");
|
|
117
|
+
const { logger } = await import("../../src/utils/logger");
|
|
118
|
+
|
|
119
|
+
vi.mocked(getUIConfig).mockResolvedValue({ componentsLocation: "app/components/Ui" } as any);
|
|
120
|
+
vi.mocked(fetchComponents).mockResolvedValue(mockComponents);
|
|
121
|
+
vi.mocked(fileExists).mockResolvedValue(false);
|
|
122
|
+
|
|
123
|
+
await runUpdateCommand([]);
|
|
124
|
+
|
|
125
|
+
expect(vi.mocked(logger.info)).toHaveBeenCalledWith("No installed components found.");
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -42,10 +42,22 @@ describe("utils/fetchBlockCategories", () => {
|
|
|
42
42
|
delete process.env.BLOCK_CATEGORIES_API;
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
it("should
|
|
45
|
+
it("should call process.exit(1) on API error", async () => {
|
|
46
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => {}) as any);
|
|
46
47
|
mockAxios.onGet("https://uithing.com/api/blocks/categories").reply(404);
|
|
47
48
|
|
|
48
|
-
await
|
|
49
|
+
await fetchBlockCategories();
|
|
50
|
+
|
|
51
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should call process.exit(1) on network error", async () => {
|
|
55
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => {}) as any);
|
|
56
|
+
mockAxios.onGet("https://uithing.com/api/blocks/categories").networkError();
|
|
57
|
+
|
|
58
|
+
await fetchBlockCategories();
|
|
59
|
+
|
|
60
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
49
61
|
});
|
|
50
62
|
|
|
51
63
|
it("should return empty array when no categories exist", async () => {
|
|
@@ -51,9 +51,21 @@ describe("utils/fetchBlocks", () => {
|
|
|
51
51
|
delete process.env.BLOCKS_API;
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it("should
|
|
54
|
+
it("should call process.exit(1) on API error", async () => {
|
|
55
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => {}) as any);
|
|
55
56
|
mockAxios.onGet("https://uithing.com/api/blocks").reply(500);
|
|
56
57
|
|
|
57
|
-
await
|
|
58
|
+
await fetchBlocks();
|
|
59
|
+
|
|
60
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should call process.exit(1) on network error", async () => {
|
|
64
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => {}) as any);
|
|
65
|
+
mockAxios.onGet("https://uithing.com/api/blocks").networkError();
|
|
66
|
+
|
|
67
|
+
await fetchBlocks();
|
|
68
|
+
|
|
69
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
58
70
|
});
|
|
59
71
|
});
|
|
@@ -69,16 +69,22 @@ describe("utils/fetchComponents", () => {
|
|
|
69
69
|
delete process.env.COMPONENTS_API;
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
it("should
|
|
72
|
+
it("should call process.exit(1) on API error", async () => {
|
|
73
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => {}) as any);
|
|
73
74
|
mockAxios.onGet("https://uithing.com/api/components").reply(500);
|
|
74
75
|
|
|
75
|
-
await
|
|
76
|
+
await fetchComponents();
|
|
77
|
+
|
|
78
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
76
79
|
});
|
|
77
80
|
|
|
78
|
-
it("should
|
|
81
|
+
it("should call process.exit(1) on network error", async () => {
|
|
82
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => {}) as any);
|
|
79
83
|
mockAxios.onGet("https://uithing.com/api/components").networkError();
|
|
80
84
|
|
|
81
|
-
await
|
|
85
|
+
await fetchComponents();
|
|
86
|
+
|
|
87
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
82
88
|
});
|
|
83
89
|
|
|
84
90
|
it("should return empty array when API returns no data", async () => {
|
|
@@ -54,9 +54,21 @@ describe("utils/fetchProseComponents", () => {
|
|
|
54
54
|
delete process.env.PROSE_COMPONENTS_API;
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
it("should
|
|
57
|
+
it("should call process.exit(1) on API error", async () => {
|
|
58
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => {}) as any);
|
|
58
59
|
mockAxios.onGet("https://uithing.com/api/prose").reply(500);
|
|
59
60
|
|
|
60
|
-
await
|
|
61
|
+
await fetchProseComponents();
|
|
62
|
+
|
|
63
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should call process.exit(1) on network error", async () => {
|
|
67
|
+
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => {}) as any);
|
|
68
|
+
mockAxios.onGet("https://uithing.com/api/prose").networkError();
|
|
69
|
+
|
|
70
|
+
await fetchProseComponents();
|
|
71
|
+
|
|
72
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
61
73
|
});
|
|
62
74
|
});
|
|
@@ -79,15 +79,48 @@ describe("utils/installPackages", () => {
|
|
|
79
79
|
expect(mockExeca).toHaveBeenCalledWith("npm", ["install", "-D", "typescript"]);
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
it("should
|
|
82
|
+
it("should use pnpm add instead of install", async () => {
|
|
83
83
|
const { execa } = await import("execa");
|
|
84
84
|
const mockExeca = vi.mocked(execa);
|
|
85
85
|
mockExeca.mockResolvedValue({} as any);
|
|
86
86
|
|
|
87
87
|
await installPackages("pnpm", ["vue"], ["typescript"]);
|
|
88
88
|
|
|
89
|
-
expect(mockExeca).toHaveBeenCalledWith("pnpm", ["
|
|
90
|
-
expect(mockExeca).toHaveBeenCalledWith("pnpm", ["
|
|
89
|
+
expect(mockExeca).toHaveBeenCalledWith("pnpm", ["add", "vue"]);
|
|
90
|
+
expect(mockExeca).toHaveBeenCalledWith("pnpm", ["add", "-D", "typescript"]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should use bun add instead of install", async () => {
|
|
94
|
+
const { execa } = await import("execa");
|
|
95
|
+
const mockExeca = vi.mocked(execa);
|
|
96
|
+
mockExeca.mockResolvedValue({} as any);
|
|
97
|
+
|
|
98
|
+
await installPackages("bun", ["vue"], ["typescript"]);
|
|
99
|
+
|
|
100
|
+
expect(mockExeca).toHaveBeenCalledWith("bun", ["add", "vue"]);
|
|
101
|
+
expect(mockExeca).toHaveBeenCalledWith("bun", ["add", "-D", "typescript"]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should use deno add with npm: prefix", async () => {
|
|
105
|
+
const { execa } = await import("execa");
|
|
106
|
+
const mockExeca = vi.mocked(execa);
|
|
107
|
+
mockExeca.mockResolvedValue({} as any);
|
|
108
|
+
|
|
109
|
+
await installPackages("deno", ["vue"], ["typescript"]);
|
|
110
|
+
|
|
111
|
+
expect(mockExeca).toHaveBeenCalledWith("deno", ["add", "npm:vue"]);
|
|
112
|
+
expect(mockExeca).toHaveBeenCalledWith("deno", ["add", "--dev", "npm:typescript"]);
|
|
113
|
+
expect(mockExeca).toHaveBeenCalledWith("deno", ["run", "-A", "npm:nuxt", "prepare"]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("should not double-prefix packages already starting with npm:", async () => {
|
|
117
|
+
const { execa } = await import("execa");
|
|
118
|
+
const mockExeca = vi.mocked(execa);
|
|
119
|
+
mockExeca.mockResolvedValue({} as any);
|
|
120
|
+
|
|
121
|
+
await installPackages("deno", ["npm:vue"]);
|
|
122
|
+
|
|
123
|
+
expect(mockExeca).toHaveBeenCalledWith("deno", ["add", "npm:vue"]);
|
|
91
124
|
});
|
|
92
125
|
|
|
93
126
|
it("should run nuxt prepare after installation", async () => {
|