trix-ui 0.2.8 → 0.2.10

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.
Files changed (204) hide show
  1. package/dist/__tests__/contracts/registry.test.d.ts +1 -0
  2. package/dist/__tests__/contracts/registry.test.js +42 -0
  3. package/dist/__tests__/contracts/registry.test.js.map +1 -0
  4. package/dist/__tests__/e2e/cli.test.d.ts +1 -0
  5. package/dist/__tests__/e2e/cli.test.js +67 -0
  6. package/dist/__tests__/e2e/cli.test.js.map +1 -0
  7. package/dist/__tests__/helpers/fs.d.ts +5 -0
  8. package/dist/__tests__/helpers/fs.js +26 -0
  9. package/dist/__tests__/helpers/fs.js.map +1 -0
  10. package/dist/__tests__/integration/commands.integration.test.d.ts +1 -0
  11. package/dist/__tests__/integration/commands.integration.test.js +184 -0
  12. package/dist/__tests__/integration/commands.integration.test.js.map +1 -0
  13. package/dist/commands/__tests__/add-composite.test.d.ts +2 -0
  14. package/dist/commands/__tests__/add-composite.test.js +171 -0
  15. package/dist/commands/__tests__/add-composite.test.js.map +1 -0
  16. package/dist/commands/__tests__/add-entry.mocks.d.ts +23 -0
  17. package/dist/commands/__tests__/add-entry.mocks.js +64 -0
  18. package/dist/commands/__tests__/add-entry.mocks.js.map +1 -0
  19. package/dist/commands/__tests__/add-section.test.d.ts +2 -0
  20. package/dist/commands/__tests__/add-section.test.js +191 -0
  21. package/dist/commands/__tests__/add-section.test.js.map +1 -0
  22. package/dist/commands/__tests__/add-wrapper.test.d.ts +2 -0
  23. package/dist/commands/__tests__/add-wrapper.test.js +171 -0
  24. package/dist/commands/__tests__/add-wrapper.test.js.map +1 -0
  25. package/dist/commands/__tests__/cli-mocks.d.ts +1 -0
  26. package/dist/commands/__tests__/cli-mocks.js +24 -0
  27. package/dist/commands/__tests__/cli-mocks.js.map +1 -0
  28. package/dist/commands/__tests__/doctor.mocks.d.ts +6 -0
  29. package/dist/commands/__tests__/doctor.mocks.js +20 -0
  30. package/dist/commands/__tests__/doctor.mocks.js.map +1 -0
  31. package/dist/commands/__tests__/doctor.test.d.ts +2 -0
  32. package/dist/commands/__tests__/doctor.test.js +80 -0
  33. package/dist/commands/__tests__/doctor.test.js.map +1 -0
  34. package/dist/commands/__tests__/list.mocks.d.ts +8 -0
  35. package/dist/commands/__tests__/list.mocks.js +20 -0
  36. package/dist/commands/__tests__/list.mocks.js.map +1 -0
  37. package/dist/commands/__tests__/list.test.d.ts +2 -0
  38. package/dist/commands/__tests__/list.test.js +60 -0
  39. package/dist/commands/__tests__/list.test.js.map +1 -0
  40. package/dist/commands/__tests__/remove.mocks.d.ts +9 -0
  41. package/dist/commands/__tests__/remove.mocks.js +26 -0
  42. package/dist/commands/__tests__/remove.mocks.js.map +1 -0
  43. package/dist/commands/__tests__/remove.test.d.ts +2 -0
  44. package/dist/commands/__tests__/remove.test.js +116 -0
  45. package/dist/commands/__tests__/remove.test.js.map +1 -0
  46. package/dist/commands/add/__tests__/add.mocks.d.ts +19 -19
  47. package/dist/commands/add/__tests__/add.mocks.js +59 -59
  48. package/dist/commands/add/__tests__/add.test.d.ts +2 -2
  49. package/dist/commands/add/__tests__/add.test.js +140 -140
  50. package/dist/commands/add/analysis.d.ts +4 -4
  51. package/dist/commands/add/analysis.js +56 -56
  52. package/dist/commands/add/command.d.ts +2 -2
  53. package/dist/commands/add/command.js +202 -202
  54. package/dist/commands/add/config.d.ts +2 -2
  55. package/dist/commands/add/config.js +11 -11
  56. package/dist/commands/add/install.d.ts +27 -27
  57. package/dist/commands/add/install.js +80 -80
  58. package/dist/commands/add/package-manager.d.ts +1 -1
  59. package/dist/commands/add/package-manager.js +4 -4
  60. package/dist/commands/add/project-files.d.ts +2 -2
  61. package/dist/commands/add/project-files.js +17 -17
  62. package/dist/commands/add/prompts.d.ts +3 -3
  63. package/dist/commands/add/prompts.js +28 -28
  64. package/dist/commands/add/registry.d.ts +4 -4
  65. package/dist/commands/add/registry.js +6 -6
  66. package/dist/commands/add/types.d.ts +33 -33
  67. package/dist/commands/add/types.js +1 -1
  68. package/dist/commands/add/ui.d.ts +4 -4
  69. package/dist/commands/add/ui.js +55 -55
  70. package/dist/commands/add/validation.d.ts +3 -3
  71. package/dist/commands/add/validation.js +30 -30
  72. package/dist/commands/add-collection.d.ts +1 -1
  73. package/dist/commands/add-collection.js +1 -1
  74. package/dist/commands/add-composite.d.ts +2 -2
  75. package/dist/commands/add-composite.js +201 -201
  76. package/dist/commands/add-section.d.ts +2 -2
  77. package/dist/commands/add-section.js +201 -201
  78. package/dist/commands/add-wrapper.d.ts +2 -2
  79. package/dist/commands/add-wrapper.js +201 -201
  80. package/dist/commands/add.d.ts +1 -1
  81. package/dist/commands/add.js +1 -1
  82. package/dist/commands/build.d.ts +2 -2
  83. package/dist/commands/doctor.d.ts +2 -2
  84. package/dist/commands/doctor.js +67 -67
  85. package/dist/commands/init/__tests__/init.mocks.d.ts +24 -0
  86. package/dist/commands/init/__tests__/init.mocks.js +84 -0
  87. package/dist/commands/init/__tests__/init.mocks.js.map +1 -0
  88. package/dist/commands/init/__tests__/init.test.d.ts +2 -0
  89. package/dist/commands/init/__tests__/init.test.js +283 -0
  90. package/dist/commands/init/__tests__/init.test.js.map +1 -0
  91. package/dist/commands/init/__tests__/tailwind.test.d.ts +1 -0
  92. package/dist/commands/init/__tests__/tailwind.test.js +56 -0
  93. package/dist/commands/init/__tests__/tailwind.test.js.map +1 -0
  94. package/dist/commands/init/__tests__/tsconfig.test.d.ts +1 -0
  95. package/dist/commands/init/__tests__/tsconfig.test.js +108 -0
  96. package/dist/commands/init/__tests__/tsconfig.test.js.map +1 -0
  97. package/dist/commands/init/__tests__/vite.test.d.ts +1 -0
  98. package/dist/commands/init/__tests__/vite.test.js +66 -0
  99. package/dist/commands/init/__tests__/vite.test.js.map +1 -0
  100. package/dist/commands/init/command.d.ts +2 -2
  101. package/dist/commands/init/command.js +114 -114
  102. package/dist/commands/init/config.d.ts +2 -2
  103. package/dist/commands/init/config.js +25 -25
  104. package/dist/commands/init/constants.d.ts +3 -3
  105. package/dist/commands/init/constants.js +105 -105
  106. package/dist/commands/init/dependencies.d.ts +5 -5
  107. package/dist/commands/init/dependencies.js +52 -52
  108. package/dist/commands/init/filesystem.d.ts +1 -1
  109. package/dist/commands/init/filesystem.js +10 -10
  110. package/dist/commands/init/lockfile.d.ts +1 -1
  111. package/dist/commands/init/lockfile.js +1 -1
  112. package/dist/commands/init/package-json.d.ts +6 -6
  113. package/dist/commands/init/package-json.js +18 -18
  114. package/dist/commands/init/project-files.d.ts +8 -0
  115. package/dist/commands/init/project-files.js +37 -0
  116. package/dist/commands/init/project-files.js.map +1 -0
  117. package/dist/commands/init/project.d.ts +3 -3
  118. package/dist/commands/init/project.js +97 -97
  119. package/dist/commands/init/style-imports.d.ts +9 -0
  120. package/dist/commands/init/style-imports.js +218 -0
  121. package/dist/commands/init/style-imports.js.map +1 -0
  122. package/dist/commands/init/tailwind.d.ts +3 -3
  123. package/dist/commands/init/tailwind.js +34 -34
  124. package/dist/commands/init/templates.d.ts +3 -3
  125. package/dist/commands/init/templates.js +15 -15
  126. package/dist/commands/init/tsconfig.d.ts +2 -2
  127. package/dist/commands/init/tsconfig.js +273 -273
  128. package/dist/commands/init/types.d.ts +33 -33
  129. package/dist/commands/init/types.js +1 -1
  130. package/dist/commands/init/ui.d.ts +3 -3
  131. package/dist/commands/init/ui.js +33 -33
  132. package/dist/commands/init/vite.d.ts +23 -0
  133. package/dist/commands/init/vite.js +347 -0
  134. package/dist/commands/init/vite.js.map +1 -0
  135. package/dist/commands/init.d.ts +1 -1
  136. package/dist/commands/init.js +1 -1
  137. package/dist/commands/list.d.ts +2 -2
  138. package/dist/commands/list.js +62 -62
  139. package/dist/commands/remove.d.ts +2 -2
  140. package/dist/commands/remove.js +93 -93
  141. package/dist/commands/shared/add-collection.d.ts +50 -50
  142. package/dist/commands/shared/add-collection.js +206 -206
  143. package/dist/commands/shared/list-entries.d.ts +6 -6
  144. package/dist/commands/shared/list-entries.js +12 -12
  145. package/dist/commands/shared/name-utils.d.ts +1 -1
  146. package/dist/commands/shared/name-utils.js +13 -13
  147. package/dist/commands/shared/remove-entries.d.ts +16 -16
  148. package/dist/commands/shared/remove-entries.js +41 -41
  149. package/dist/icons/index.d.ts +1 -1
  150. package/dist/icons/index.js +1 -1
  151. package/dist/icons/libraries.d.ts +37 -37
  152. package/dist/icons/libraries.js +34 -34
  153. package/dist/index.d.ts +2 -2
  154. package/dist/index.js +30 -30
  155. package/dist/lib/__tests__/config.test.d.ts +1 -0
  156. package/dist/lib/__tests__/config.test.js +49 -0
  157. package/dist/lib/__tests__/config.test.js.map +1 -0
  158. package/dist/lib/__tests__/install.test.d.ts +1 -0
  159. package/dist/lib/__tests__/install.test.js +149 -0
  160. package/dist/lib/__tests__/install.test.js.map +1 -0
  161. package/dist/lib/__tests__/lockfile.test.d.ts +1 -0
  162. package/dist/lib/__tests__/lockfile.test.js +89 -0
  163. package/dist/lib/__tests__/lockfile.test.js.map +1 -0
  164. package/dist/lib/__tests__/paths.test.d.ts +1 -0
  165. package/dist/lib/__tests__/paths.test.js +39 -0
  166. package/dist/lib/__tests__/paths.test.js.map +1 -0
  167. package/dist/lib/__tests__/registry.test.d.ts +1 -0
  168. package/dist/lib/__tests__/registry.test.js +76 -0
  169. package/dist/lib/__tests__/registry.test.js.map +1 -0
  170. package/dist/lib/config.d.ts +45 -45
  171. package/dist/lib/config.js +97 -97
  172. package/dist/lib/fs.d.ts +76 -76
  173. package/dist/lib/fs.js +302 -302
  174. package/dist/lib/highlighter.d.ts +6 -6
  175. package/dist/lib/highlighter.js +7 -7
  176. package/dist/lib/install.d.ts +19 -19
  177. package/dist/lib/install.js +55 -55
  178. package/dist/lib/lockfile.d.ts +63 -63
  179. package/dist/lib/lockfile.js +173 -173
  180. package/dist/lib/logger.d.ts +8 -8
  181. package/dist/lib/logger.js +41 -41
  182. package/dist/lib/paths.d.ts +14 -14
  183. package/dist/lib/paths.js +31 -31
  184. package/dist/lib/registry.d.ts +35 -35
  185. package/dist/lib/registry.js +180 -180
  186. package/dist/schema/index.d.ts +1128 -1128
  187. package/dist/schema/index.js +238 -238
  188. package/dist/styles/create-style-map.d.ts +4 -4
  189. package/dist/styles/create-style-map.js +68 -68
  190. package/dist/styles/transform-style-map.d.ts +3 -3
  191. package/dist/styles/transform-style-map.js +428 -428
  192. package/dist/styles/transform.d.ts +10 -10
  193. package/dist/styles/transform.js +15 -15
  194. package/dist/utils/index.d.ts +6 -6
  195. package/dist/utils/index.js +5 -5
  196. package/dist/utils/transformers/transform-icons.d.ts +2 -2
  197. package/dist/utils/transformers/transform-icons.js +164 -164
  198. package/dist/utils/transformers/transform-menu.d.ts +2 -2
  199. package/dist/utils/transformers/transform-menu.js +39 -39
  200. package/dist/utils/transformers/transform-render.d.ts +2 -2
  201. package/dist/utils/transformers/transform-render.js +97 -97
  202. package/dist/utils/transformers/types.d.ts +14 -14
  203. package/dist/utils/transformers/types.js +1 -1
  204. package/package.json +1 -1
@@ -1,42 +1,42 @@
1
- import { highlighter } from "./highlighter.js";
2
- function formatArgs(args) {
3
- return args
4
- .map((arg) => {
5
- if (typeof arg === "string")
6
- return arg;
7
- if (arg instanceof Error) {
8
- return arg.stack ?? arg.message;
9
- }
10
- if (typeof arg === "object" && arg !== null) {
11
- try {
12
- return JSON.stringify(arg, null, 2);
13
- }
14
- catch {
15
- return "[Unserializable Object]";
16
- }
17
- }
18
- return String(arg);
19
- })
20
- .join(" ");
21
- }
22
- export const logger = {
23
- error(...args) {
24
- console.log(highlighter.error(formatArgs(args)));
25
- },
26
- warn(...args) {
27
- console.log(highlighter.warn(formatArgs(args)));
28
- },
29
- info(...args) {
30
- console.log(highlighter.info(formatArgs(args)));
31
- },
32
- success(...args) {
33
- console.log(highlighter.success(formatArgs(args)));
34
- },
35
- log(...args) {
36
- console.log(formatArgs(args));
37
- },
38
- break() {
39
- console.log("");
40
- },
41
- };
1
+ import { highlighter } from "./highlighter.js";
2
+ function formatArgs(args) {
3
+ return args
4
+ .map((arg) => {
5
+ if (typeof arg === "string")
6
+ return arg;
7
+ if (arg instanceof Error) {
8
+ return arg.stack ?? arg.message;
9
+ }
10
+ if (typeof arg === "object" && arg !== null) {
11
+ try {
12
+ return JSON.stringify(arg, null, 2);
13
+ }
14
+ catch {
15
+ return "[Unserializable Object]";
16
+ }
17
+ }
18
+ return String(arg);
19
+ })
20
+ .join(" ");
21
+ }
22
+ export const logger = {
23
+ error(...args) {
24
+ console.log(highlighter.error(formatArgs(args)));
25
+ },
26
+ warn(...args) {
27
+ console.log(highlighter.warn(formatArgs(args)));
28
+ },
29
+ info(...args) {
30
+ console.log(highlighter.info(formatArgs(args)));
31
+ },
32
+ success(...args) {
33
+ console.log(highlighter.success(formatArgs(args)));
34
+ },
35
+ log(...args) {
36
+ console.log(formatArgs(args));
37
+ },
38
+ break() {
39
+ console.log("");
40
+ },
41
+ };
42
42
  //# sourceMappingURL=logger.js.map
@@ -1,14 +1,14 @@
1
- export declare function toPosix(filePath: string): string;
2
- export declare function fromPosix(posixPath: string): string;
3
- export declare function getBundledRegistryPath(): string;
4
- export declare function getBundledTemplatesPath(): string;
5
- export declare function resolveTemplatePath(relativePath: string, templateRoot: string): string;
6
- export declare function getTemplatePath(relativePath: string): string;
7
- export declare function resolveTargetPath(cwd: string, target: string, paths: {
8
- components: string;
9
- sections: string;
10
- wrappers: string;
11
- composites: string;
12
- utils: string;
13
- styles: string;
14
- }): string;
1
+ export declare function toPosix(filePath: string): string;
2
+ export declare function fromPosix(posixPath: string): string;
3
+ export declare function getBundledRegistryPath(): string;
4
+ export declare function getBundledTemplatesPath(): string;
5
+ export declare function resolveTemplatePath(relativePath: string, templateRoot: string): string;
6
+ export declare function getTemplatePath(relativePath: string): string;
7
+ export declare function resolveTargetPath(cwd: string, target: string, paths: {
8
+ components: string;
9
+ sections: string;
10
+ wrappers: string;
11
+ composites: string;
12
+ utils: string;
13
+ styles: string;
14
+ }): string;
package/dist/lib/paths.js CHANGED
@@ -1,32 +1,32 @@
1
- import path from "node:path";
2
- import { fileURLToPath } from "node:url";
3
- export function toPosix(filePath) {
4
- return filePath.split(path.sep).join("/");
5
- }
6
- export function fromPosix(posixPath) {
7
- return posixPath.split("/").join(path.sep);
8
- }
9
- export function getBundledRegistryPath() {
10
- return fileURLToPath(new URL("../../registry/index.json", import.meta.url));
11
- }
12
- export function getBundledTemplatesPath() {
13
- return fileURLToPath(new URL("../../templates", import.meta.url));
14
- }
15
- export function resolveTemplatePath(relativePath, templateRoot) {
16
- const normalized = relativePath.replace(/^[\\/]+/, "");
17
- return path.resolve(templateRoot, normalized);
18
- }
19
- export function getTemplatePath(relativePath) {
20
- return resolveTemplatePath(relativePath, getBundledTemplatesPath());
21
- }
22
- export function resolveTargetPath(cwd, target, paths) {
23
- const resolved = target
24
- .replace("{{components}}", paths.components)
25
- .replace("{{sections}}", paths.sections)
26
- .replace("{{wrappers}}", paths.wrappers)
27
- .replace("{{composites}}", paths.composites)
28
- .replace("{{lib}}", paths.utils)
29
- .replace("{{styles}}", paths.styles);
30
- return path.resolve(cwd, resolved);
31
- }
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ export function toPosix(filePath) {
4
+ return filePath.split(path.sep).join("/");
5
+ }
6
+ export function fromPosix(posixPath) {
7
+ return posixPath.split("/").join(path.sep);
8
+ }
9
+ export function getBundledRegistryPath() {
10
+ return fileURLToPath(new URL("../../registry/index.json", import.meta.url));
11
+ }
12
+ export function getBundledTemplatesPath() {
13
+ return fileURLToPath(new URL("../../templates", import.meta.url));
14
+ }
15
+ export function resolveTemplatePath(relativePath, templateRoot) {
16
+ const normalized = relativePath.replace(/^[\\/]+/, "");
17
+ return path.resolve(templateRoot, normalized);
18
+ }
19
+ export function getTemplatePath(relativePath) {
20
+ return resolveTemplatePath(relativePath, getBundledTemplatesPath());
21
+ }
22
+ export function resolveTargetPath(cwd, target, paths) {
23
+ const resolved = target
24
+ .replace("{{components}}", paths.components)
25
+ .replace("{{sections}}", paths.sections)
26
+ .replace("{{wrappers}}", paths.wrappers)
27
+ .replace("{{composites}}", paths.composites)
28
+ .replace("{{lib}}", paths.utils)
29
+ .replace("{{styles}}", paths.styles);
30
+ return path.resolve(cwd, resolved);
31
+ }
32
32
  //# sourceMappingURL=paths.js.map
@@ -1,35 +1,35 @@
1
- import type { TrixUIConfig } from "./config.js";
2
- export type RegistryFile = {
3
- source: string;
4
- target: string;
5
- };
6
- export type RegistryDependencies = {
7
- npm?: string[];
8
- local?: string[];
9
- };
10
- export type RegistryItem = {
11
- name: string;
12
- description: string;
13
- files: RegistryFile[];
14
- dependencies?: RegistryDependencies;
15
- tailwindPluginsNeeded?: string[];
16
- notes?: string;
17
- };
18
- export type RegistryIndex = {
19
- version: number;
20
- components: RegistryItem[];
21
- sections?: RegistryItem[];
22
- wrappers?: RegistryItem[];
23
- composites?: RegistryItem[];
24
- };
25
- export type ResolvedRegistrySource = {
26
- type: "bundled" | "local";
27
- registryPath: string;
28
- templatesPath: string;
29
- };
30
- export declare function resolveRegistrySource(config: TrixUIConfig, cwd: string): ResolvedRegistrySource;
31
- export declare function loadRegistry(config: TrixUIConfig, cwd: string): Promise<RegistryIndex>;
32
- export declare function loadBundledRegistry(): Promise<RegistryIndex>;
33
- export declare function getRegistrySections(registry: RegistryIndex): RegistryItem[];
34
- export declare function getRegistryWrappers(registry: RegistryIndex): RegistryItem[];
35
- export declare function getRegistryComposites(registry: RegistryIndex): RegistryItem[];
1
+ import type { TrixUIConfig } from "./config.js";
2
+ export type RegistryFile = {
3
+ source: string;
4
+ target: string;
5
+ };
6
+ export type RegistryDependencies = {
7
+ npm?: string[];
8
+ local?: string[];
9
+ };
10
+ export type RegistryItem = {
11
+ name: string;
12
+ description: string;
13
+ files: RegistryFile[];
14
+ dependencies?: RegistryDependencies;
15
+ tailwindPluginsNeeded?: string[];
16
+ notes?: string;
17
+ };
18
+ export type RegistryIndex = {
19
+ version: number;
20
+ components: RegistryItem[];
21
+ sections?: RegistryItem[];
22
+ wrappers?: RegistryItem[];
23
+ composites?: RegistryItem[];
24
+ };
25
+ export type ResolvedRegistrySource = {
26
+ type: "bundled" | "local";
27
+ registryPath: string;
28
+ templatesPath: string;
29
+ };
30
+ export declare function resolveRegistrySource(config: TrixUIConfig, cwd: string): ResolvedRegistrySource;
31
+ export declare function loadRegistry(config: TrixUIConfig, cwd: string): Promise<RegistryIndex>;
32
+ export declare function loadBundledRegistry(): Promise<RegistryIndex>;
33
+ export declare function getRegistrySections(registry: RegistryIndex): RegistryItem[];
34
+ export declare function getRegistryWrappers(registry: RegistryIndex): RegistryItem[];
35
+ export declare function getRegistryComposites(registry: RegistryIndex): RegistryItem[];
@@ -1,181 +1,181 @@
1
- import path from "node:path";
2
- import { fileExists, readJsonFile } from "./fs.js";
3
- import { getBundledRegistryPath, getBundledTemplatesPath } from "./paths.js";
4
- function normalizeRegistryConfig(registry) {
5
- if (!registry) {
6
- return { type: "bundled" };
7
- }
8
- if (typeof registry === "string") {
9
- if (registry === "bundled") {
10
- return { type: "bundled" };
11
- }
12
- return { type: "local", path: registry };
13
- }
14
- if (registry.type === "bundled") {
15
- return { type: "bundled" };
16
- }
17
- if (registry.type === "local") {
18
- if (!registry.path || typeof registry.path !== "string") {
19
- throw new Error("Registry config missing required 'path' value.");
20
- }
21
- if (registry.templates !== undefined &&
22
- typeof registry.templates !== "string") {
23
- throw new Error("Registry config 'templates' must be a string.");
24
- }
25
- return registry;
26
- }
27
- throw new Error("Invalid registry config. Use 'bundled' or 'local'.");
28
- }
29
- export function resolveRegistrySource(config, cwd) {
30
- const normalized = normalizeRegistryConfig(config.registry);
31
- if (normalized.type === "bundled") {
32
- return {
33
- type: "bundled",
34
- registryPath: getBundledRegistryPath(),
35
- templatesPath: getBundledTemplatesPath(),
36
- };
37
- }
38
- const registryPath = path.resolve(cwd, normalized.path);
39
- const templatesPath = normalized.templates
40
- ? path.resolve(cwd, normalized.templates)
41
- : path.resolve(path.dirname(registryPath), "..", "templates");
42
- return {
43
- type: "local",
44
- registryPath,
45
- templatesPath,
46
- };
47
- }
48
- function isRecord(value) {
49
- return typeof value === "object" && value !== null;
50
- }
51
- function ensureString(value, label) {
52
- if (typeof value !== "string" || value.length === 0) {
53
- throw new Error(`Registry ${label} must be a non-empty string.`);
54
- }
55
- return value;
56
- }
57
- function ensureStringArray(value, label) {
58
- if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
59
- throw new Error(`Registry ${label} must be an array of strings.`);
60
- }
61
- return value;
62
- }
63
- function parseRegistryFile(value, label) {
64
- if (!isRecord(value)) {
65
- throw new Error(`Registry ${label} must be an object.`);
66
- }
67
- return {
68
- source: ensureString(value.source, `${label}.source`),
69
- target: ensureString(value.target, `${label}.target`),
70
- };
71
- }
72
- function parseRegistryDependencies(value, label) {
73
- if (value === undefined) {
74
- return undefined;
75
- }
76
- if (!isRecord(value)) {
77
- throw new Error(`Registry ${label} must be an object.`);
78
- }
79
- const npm = value.npm === undefined
80
- ? undefined
81
- : ensureStringArray(value.npm, `${label}.npm`);
82
- const local = value.local === undefined
83
- ? undefined
84
- : ensureStringArray(value.local, `${label}.local`);
85
- const dependencies = {};
86
- if (npm) {
87
- dependencies.npm = npm;
88
- }
89
- if (local) {
90
- dependencies.local = local;
91
- }
92
- return dependencies;
93
- }
94
- function parseRegistryItem(value, label) {
95
- if (!isRecord(value)) {
96
- throw new Error(`Registry ${label} must be an object.`);
97
- }
98
- if (!Array.isArray(value.files)) {
99
- throw new Error(`Registry ${label}.files must be an array.`);
100
- }
101
- const files = value.files.map((file, index) => parseRegistryFile(file, `${label}.files[${index}]`));
102
- const tailwindPluginsNeeded = value.tailwindPluginsNeeded === undefined
103
- ? undefined
104
- : ensureStringArray(value.tailwindPluginsNeeded, `${label}.tailwindPluginsNeeded`);
105
- const notes = value.notes === undefined
106
- ? undefined
107
- : ensureString(value.notes, `${label}.notes`);
108
- return {
109
- name: ensureString(value.name, `${label}.name`),
110
- description: ensureString(value.description, `${label}.description`),
111
- files,
112
- dependencies: parseRegistryDependencies(value.dependencies, `${label}.dependencies`),
113
- tailwindPluginsNeeded,
114
- notes,
115
- };
116
- }
117
- function parseRegistryIndex(value, filePath) {
118
- if (!isRecord(value)) {
119
- throw new Error(`Registry ${filePath} must be a JSON object.`);
120
- }
121
- if (typeof value.version !== "number") {
122
- throw new Error(`Registry ${filePath} missing numeric 'version'.`);
123
- }
124
- if (!Array.isArray(value.components)) {
125
- throw new Error(`Registry ${filePath} missing 'components' array.`);
126
- }
127
- const components = value.components.map((item, index) => parseRegistryItem(item, `components[${index}]`));
128
- let sections;
129
- if (value.sections !== undefined) {
130
- if (!Array.isArray(value.sections)) {
131
- throw new Error(`Registry ${filePath} 'sections' must be an array.`);
132
- }
133
- sections = value.sections.map((item, index) => parseRegistryItem(item, `sections[${index}]`));
134
- }
135
- let wrappers;
136
- if (value.wrappers !== undefined) {
137
- if (!Array.isArray(value.wrappers)) {
138
- throw new Error(`Registry ${filePath} 'wrappers' must be an array.`);
139
- }
140
- wrappers = value.wrappers.map((item, index) => parseRegistryItem(item, `wrappers[${index}]`));
141
- }
142
- let composites;
143
- if (value.composites !== undefined) {
144
- if (!Array.isArray(value.composites)) {
145
- throw new Error(`Registry ${filePath} 'composites' must be an array.`);
146
- }
147
- composites = value.composites.map((item, index) => parseRegistryItem(item, `composites[${index}]`));
148
- }
149
- return {
150
- version: value.version,
151
- components,
152
- sections,
153
- wrappers,
154
- composites,
155
- };
156
- }
157
- async function readRegistryFile(filePath) {
158
- if (!(await fileExists(filePath))) {
159
- throw new Error(`Registry file not found: ${filePath}`);
160
- }
161
- const parsed = await readJsonFile(filePath);
162
- return parseRegistryIndex(parsed, filePath);
163
- }
164
- export async function loadRegistry(config, cwd) {
165
- const { registryPath } = resolveRegistrySource(config, cwd);
166
- return readRegistryFile(registryPath);
167
- }
168
- export async function loadBundledRegistry() {
169
- const registryPath = getBundledRegistryPath();
170
- return readRegistryFile(registryPath);
171
- }
172
- export function getRegistrySections(registry) {
173
- return registry.sections ?? [];
174
- }
175
- export function getRegistryWrappers(registry) {
176
- return registry.wrappers ?? [];
177
- }
178
- export function getRegistryComposites(registry) {
179
- return registry.composites ?? [];
180
- }
1
+ import path from "node:path";
2
+ import { fileExists, readJsonFile } from "./fs.js";
3
+ import { getBundledRegistryPath, getBundledTemplatesPath } from "./paths.js";
4
+ function normalizeRegistryConfig(registry) {
5
+ if (!registry) {
6
+ return { type: "bundled" };
7
+ }
8
+ if (typeof registry === "string") {
9
+ if (registry === "bundled") {
10
+ return { type: "bundled" };
11
+ }
12
+ return { type: "local", path: registry };
13
+ }
14
+ if (registry.type === "bundled") {
15
+ return { type: "bundled" };
16
+ }
17
+ if (registry.type === "local") {
18
+ if (!registry.path || typeof registry.path !== "string") {
19
+ throw new Error("Registry config missing required 'path' value.");
20
+ }
21
+ if (registry.templates !== undefined &&
22
+ typeof registry.templates !== "string") {
23
+ throw new Error("Registry config 'templates' must be a string.");
24
+ }
25
+ return registry;
26
+ }
27
+ throw new Error("Invalid registry config. Use 'bundled' or 'local'.");
28
+ }
29
+ export function resolveRegistrySource(config, cwd) {
30
+ const normalized = normalizeRegistryConfig(config.registry);
31
+ if (normalized.type === "bundled") {
32
+ return {
33
+ type: "bundled",
34
+ registryPath: getBundledRegistryPath(),
35
+ templatesPath: getBundledTemplatesPath(),
36
+ };
37
+ }
38
+ const registryPath = path.resolve(cwd, normalized.path);
39
+ const templatesPath = normalized.templates
40
+ ? path.resolve(cwd, normalized.templates)
41
+ : path.resolve(path.dirname(registryPath), "..", "templates");
42
+ return {
43
+ type: "local",
44
+ registryPath,
45
+ templatesPath,
46
+ };
47
+ }
48
+ function isRecord(value) {
49
+ return typeof value === "object" && value !== null;
50
+ }
51
+ function ensureString(value, label) {
52
+ if (typeof value !== "string" || value.length === 0) {
53
+ throw new Error(`Registry ${label} must be a non-empty string.`);
54
+ }
55
+ return value;
56
+ }
57
+ function ensureStringArray(value, label) {
58
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
59
+ throw new Error(`Registry ${label} must be an array of strings.`);
60
+ }
61
+ return value;
62
+ }
63
+ function parseRegistryFile(value, label) {
64
+ if (!isRecord(value)) {
65
+ throw new Error(`Registry ${label} must be an object.`);
66
+ }
67
+ return {
68
+ source: ensureString(value.source, `${label}.source`),
69
+ target: ensureString(value.target, `${label}.target`),
70
+ };
71
+ }
72
+ function parseRegistryDependencies(value, label) {
73
+ if (value === undefined) {
74
+ return undefined;
75
+ }
76
+ if (!isRecord(value)) {
77
+ throw new Error(`Registry ${label} must be an object.`);
78
+ }
79
+ const npm = value.npm === undefined
80
+ ? undefined
81
+ : ensureStringArray(value.npm, `${label}.npm`);
82
+ const local = value.local === undefined
83
+ ? undefined
84
+ : ensureStringArray(value.local, `${label}.local`);
85
+ const dependencies = {};
86
+ if (npm) {
87
+ dependencies.npm = npm;
88
+ }
89
+ if (local) {
90
+ dependencies.local = local;
91
+ }
92
+ return dependencies;
93
+ }
94
+ function parseRegistryItem(value, label) {
95
+ if (!isRecord(value)) {
96
+ throw new Error(`Registry ${label} must be an object.`);
97
+ }
98
+ if (!Array.isArray(value.files)) {
99
+ throw new Error(`Registry ${label}.files must be an array.`);
100
+ }
101
+ const files = value.files.map((file, index) => parseRegistryFile(file, `${label}.files[${index}]`));
102
+ const tailwindPluginsNeeded = value.tailwindPluginsNeeded === undefined
103
+ ? undefined
104
+ : ensureStringArray(value.tailwindPluginsNeeded, `${label}.tailwindPluginsNeeded`);
105
+ const notes = value.notes === undefined
106
+ ? undefined
107
+ : ensureString(value.notes, `${label}.notes`);
108
+ return {
109
+ name: ensureString(value.name, `${label}.name`),
110
+ description: ensureString(value.description, `${label}.description`),
111
+ files,
112
+ dependencies: parseRegistryDependencies(value.dependencies, `${label}.dependencies`),
113
+ tailwindPluginsNeeded,
114
+ notes,
115
+ };
116
+ }
117
+ function parseRegistryIndex(value, filePath) {
118
+ if (!isRecord(value)) {
119
+ throw new Error(`Registry ${filePath} must be a JSON object.`);
120
+ }
121
+ if (typeof value.version !== "number") {
122
+ throw new Error(`Registry ${filePath} missing numeric 'version'.`);
123
+ }
124
+ if (!Array.isArray(value.components)) {
125
+ throw new Error(`Registry ${filePath} missing 'components' array.`);
126
+ }
127
+ const components = value.components.map((item, index) => parseRegistryItem(item, `components[${index}]`));
128
+ let sections;
129
+ if (value.sections !== undefined) {
130
+ if (!Array.isArray(value.sections)) {
131
+ throw new Error(`Registry ${filePath} 'sections' must be an array.`);
132
+ }
133
+ sections = value.sections.map((item, index) => parseRegistryItem(item, `sections[${index}]`));
134
+ }
135
+ let wrappers;
136
+ if (value.wrappers !== undefined) {
137
+ if (!Array.isArray(value.wrappers)) {
138
+ throw new Error(`Registry ${filePath} 'wrappers' must be an array.`);
139
+ }
140
+ wrappers = value.wrappers.map((item, index) => parseRegistryItem(item, `wrappers[${index}]`));
141
+ }
142
+ let composites;
143
+ if (value.composites !== undefined) {
144
+ if (!Array.isArray(value.composites)) {
145
+ throw new Error(`Registry ${filePath} 'composites' must be an array.`);
146
+ }
147
+ composites = value.composites.map((item, index) => parseRegistryItem(item, `composites[${index}]`));
148
+ }
149
+ return {
150
+ version: value.version,
151
+ components,
152
+ sections,
153
+ wrappers,
154
+ composites,
155
+ };
156
+ }
157
+ async function readRegistryFile(filePath) {
158
+ if (!(await fileExists(filePath))) {
159
+ throw new Error(`Registry file not found: ${filePath}`);
160
+ }
161
+ const parsed = await readJsonFile(filePath);
162
+ return parseRegistryIndex(parsed, filePath);
163
+ }
164
+ export async function loadRegistry(config, cwd) {
165
+ const { registryPath } = resolveRegistrySource(config, cwd);
166
+ return readRegistryFile(registryPath);
167
+ }
168
+ export async function loadBundledRegistry() {
169
+ const registryPath = getBundledRegistryPath();
170
+ return readRegistryFile(registryPath);
171
+ }
172
+ export function getRegistrySections(registry) {
173
+ return registry.sections ?? [];
174
+ }
175
+ export function getRegistryWrappers(registry) {
176
+ return registry.wrappers ?? [];
177
+ }
178
+ export function getRegistryComposites(registry) {
179
+ return registry.composites ?? [];
180
+ }
181
181
  //# sourceMappingURL=registry.js.map