ui-thing 0.3.0 → 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/.github/workflows/main.yml +7 -4
- package/.github/workflows/test.yml +7 -4
- package/CHANGELOG.md +20 -0
- package/README.md +208 -21
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1351 -0
- package/dist/index.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/add.ts +34 -9
- package/src/types.ts +12 -0
- package/tests/commands/add.test.ts +136 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { runAddCommand } from "../../src/commands/add";
|
|
4
|
+
import { Component } from "../../src/types";
|
|
5
|
+
|
|
6
|
+
vi.mock("../../src/utils/fetchComponents");
|
|
7
|
+
vi.mock("../../src/utils/config");
|
|
8
|
+
vi.mock("../../src/utils/compareUIConfig");
|
|
9
|
+
vi.mock("../../src/utils/detectNuxtVersion");
|
|
10
|
+
vi.mock("../../src/utils/writeFile");
|
|
11
|
+
vi.mock("../../src/utils/installPackages");
|
|
12
|
+
vi.mock("../../src/utils/fileExists");
|
|
13
|
+
vi.mock("../../src/utils/logger");
|
|
14
|
+
vi.mock("../../src/utils/printFancyBoxMessage");
|
|
15
|
+
vi.mock("../../src/utils/promptForComponents");
|
|
16
|
+
vi.mock("../../src/utils/installValidator");
|
|
17
|
+
vi.mock("prompts");
|
|
18
|
+
vi.mock("c12/update");
|
|
19
|
+
|
|
20
|
+
const mockComponent: Component = {
|
|
21
|
+
name: "Popover",
|
|
22
|
+
value: "popover",
|
|
23
|
+
files: [{ fileName: "Popover.vue", dirPath: "app/components/Ui", fileContent: "<div />" }],
|
|
24
|
+
utils: [],
|
|
25
|
+
composables: [],
|
|
26
|
+
plugins: [],
|
|
27
|
+
deps: [],
|
|
28
|
+
devDeps: [],
|
|
29
|
+
nuxtModules: [],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe("commands/add --skip-config", () => {
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
vi.clearAllMocks();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
vi.restoreAllMocks();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("uses Nuxt 4 defaults when skipConfig is set and nuxt 4 is detected", async () => {
|
|
42
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
43
|
+
const { detectNuxtVersion } = await import("../../src/utils/detectNuxtVersion");
|
|
44
|
+
const { writeFile } = await import("../../src/utils/writeFile");
|
|
45
|
+
const { fileExists } = await import("../../src/utils/fileExists");
|
|
46
|
+
const prompts = await import("prompts");
|
|
47
|
+
|
|
48
|
+
vi.mocked(fetchComponents).mockResolvedValue([mockComponent]);
|
|
49
|
+
vi.mocked(detectNuxtVersion).mockReturnValue(4);
|
|
50
|
+
vi.mocked(fileExists).mockResolvedValue(false);
|
|
51
|
+
vi.mocked(prompts.default).mockResolvedValue({});
|
|
52
|
+
|
|
53
|
+
await runAddCommand(["popover"], { skipConfig: true, packageManager: "npm" });
|
|
54
|
+
|
|
55
|
+
expect(vi.mocked(writeFile)).toHaveBeenCalledWith(
|
|
56
|
+
expect.stringContaining("app/components/Ui/Popover.vue"),
|
|
57
|
+
"<div />"
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("uses Nuxt 3 defaults when skipConfig is set and nuxt 3 is detected", async () => {
|
|
62
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
63
|
+
const { detectNuxtVersion } = await import("../../src/utils/detectNuxtVersion");
|
|
64
|
+
const { writeFile } = await import("../../src/utils/writeFile");
|
|
65
|
+
const { fileExists } = await import("../../src/utils/fileExists");
|
|
66
|
+
const prompts = await import("prompts");
|
|
67
|
+
|
|
68
|
+
vi.mocked(fetchComponents).mockResolvedValue([mockComponent]);
|
|
69
|
+
vi.mocked(detectNuxtVersion).mockReturnValue(3);
|
|
70
|
+
vi.mocked(fileExists).mockResolvedValue(false);
|
|
71
|
+
vi.mocked(prompts.default).mockResolvedValue({});
|
|
72
|
+
|
|
73
|
+
await runAddCommand(["popover"], { skipConfig: true, packageManager: "npm" });
|
|
74
|
+
|
|
75
|
+
expect(vi.mocked(writeFile)).toHaveBeenCalledWith(
|
|
76
|
+
expect.stringContaining("components/Ui/Popover.vue"),
|
|
77
|
+
"<div />"
|
|
78
|
+
);
|
|
79
|
+
expect(vi.mocked(writeFile)).not.toHaveBeenCalledWith(
|
|
80
|
+
expect.stringContaining("app/components/Ui/Popover.vue"),
|
|
81
|
+
expect.any(String)
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("uses the provided --package-manager without prompting", async () => {
|
|
86
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
87
|
+
const { detectNuxtVersion } = await import("../../src/utils/detectNuxtVersion");
|
|
88
|
+
const { fileExists } = await import("../../src/utils/fileExists");
|
|
89
|
+
const prompts = await import("prompts");
|
|
90
|
+
|
|
91
|
+
vi.mocked(fetchComponents).mockResolvedValue([mockComponent]);
|
|
92
|
+
vi.mocked(detectNuxtVersion).mockReturnValue(4);
|
|
93
|
+
vi.mocked(fileExists).mockResolvedValue(false);
|
|
94
|
+
|
|
95
|
+
await runAddCommand(["popover"], { skipConfig: true, packageManager: "bun" });
|
|
96
|
+
|
|
97
|
+
expect(vi.mocked(prompts.default)).not.toHaveBeenCalledWith(
|
|
98
|
+
expect.objectContaining({ name: "packageManager" })
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("prompts for package manager when skipConfig is set but no --package-manager given", async () => {
|
|
103
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
104
|
+
const { detectNuxtVersion } = await import("../../src/utils/detectNuxtVersion");
|
|
105
|
+
const { fileExists } = await import("../../src/utils/fileExists");
|
|
106
|
+
const prompts = await import("prompts");
|
|
107
|
+
|
|
108
|
+
vi.mocked(fetchComponents).mockResolvedValue([mockComponent]);
|
|
109
|
+
vi.mocked(detectNuxtVersion).mockReturnValue(4);
|
|
110
|
+
vi.mocked(fileExists).mockResolvedValue(false);
|
|
111
|
+
vi.mocked(prompts.default).mockResolvedValue({ packageManager: "pnpm" });
|
|
112
|
+
|
|
113
|
+
await runAddCommand(["popover"], { skipConfig: true });
|
|
114
|
+
|
|
115
|
+
expect(vi.mocked(prompts.default)).toHaveBeenCalledWith(
|
|
116
|
+
expect.objectContaining({ name: "packageManager", type: "select" })
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("does not call getUIConfig when skipConfig is set", async () => {
|
|
121
|
+
const { fetchComponents } = await import("../../src/utils/fetchComponents");
|
|
122
|
+
const { detectNuxtVersion } = await import("../../src/utils/detectNuxtVersion");
|
|
123
|
+
const { getUIConfig } = await import("../../src/utils/config");
|
|
124
|
+
const { fileExists } = await import("../../src/utils/fileExists");
|
|
125
|
+
const prompts = await import("prompts");
|
|
126
|
+
|
|
127
|
+
vi.mocked(fetchComponents).mockResolvedValue([mockComponent]);
|
|
128
|
+
vi.mocked(detectNuxtVersion).mockReturnValue(4);
|
|
129
|
+
vi.mocked(fileExists).mockResolvedValue(false);
|
|
130
|
+
vi.mocked(prompts.default).mockResolvedValue({});
|
|
131
|
+
|
|
132
|
+
await runAddCommand(["popover"], { skipConfig: true, packageManager: "npm" });
|
|
133
|
+
|
|
134
|
+
expect(vi.mocked(getUIConfig)).not.toHaveBeenCalled();
|
|
135
|
+
});
|
|
136
|
+
});
|