frakment 0.0.1 → 3.0.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/LICENSE +21 -190
- package/README.md +41 -14
- package/dist/bin/index.js +40 -0
- package/dist/package.json +49 -0
- package/dist/src/commands/add.js +381 -0
- package/dist/src/commands/init.js +145 -0
- package/dist/src/commands/list.js +55 -0
- package/dist/src/utils/detect.js +34 -0
- package/dist/src/utils/logger.js +11 -0
- package/{templates → dist/templates}/components.json +1 -1
- package/dist/templates/lib/motion.ts +139 -0
- package/{templates → dist/templates}/theme.css +6 -22
- package/package.json +29 -13
- package/bin/index.js +0 -50
- package/src/commands/add.js +0 -142
- package/src/commands/init.js +0 -201
- package/src/commands/list.js +0 -61
- package/src/utils/detect.js +0 -38
- package/templates/lib/animation.ts +0 -12
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
export interface ParsedMotion {
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
duration: number;
|
|
8
|
+
easing: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const durationRegex = /^(\d+(?:\.\d+)?)(ms|s)?$/u;
|
|
12
|
+
const cubicBezierRegex =
|
|
13
|
+
/^cubic-bezier\(\s*-?\d*\.?\d+\s*,\s*-?\d*\.?\d+\s*,\s*-?\d*\.?\d+\s*,\s*-?\d*\.?\d+\s*\)$/u;
|
|
14
|
+
|
|
15
|
+
function warn(message: string): void {
|
|
16
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
17
|
+
console.warn(`[motion] ${message}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function parseMotion(input?: string): ParsedMotion | null {
|
|
22
|
+
if (input === undefined) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (typeof input !== "string") {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const trimmed = input.trim();
|
|
29
|
+
if (!trimmed) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (trimmed === "off") {
|
|
33
|
+
return { disabled: true, duration: 0, easing: "linear" };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const tokens = trimmed.split(/\s+/u);
|
|
37
|
+
let duration = 150;
|
|
38
|
+
let index = 0;
|
|
39
|
+
|
|
40
|
+
const head = tokens[0];
|
|
41
|
+
const match = head.match(durationRegex);
|
|
42
|
+
if (match) {
|
|
43
|
+
const n = Number.parseFloat(match[1]);
|
|
44
|
+
if (!Number.isNaN(n)) {
|
|
45
|
+
duration = match[2] === "s" ? n * 1000 : n;
|
|
46
|
+
index = 1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const rest = tokens.slice(index).join(" ");
|
|
51
|
+
if (!rest) {
|
|
52
|
+
return { disabled: false, duration, easing: "ease-in-out" };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (cubicBezierRegex.test(rest)) {
|
|
56
|
+
return { disabled: false, duration, easing: rest };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (/^(spring|inertia|keyframes)/u.test(rest) || rest.startsWith("spring(")) {
|
|
60
|
+
warn(`"${rest}" is not applicable to CSS-only components`);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { disabled: false, duration, easing: rest };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function getTransition(parsed: ParsedMotion | null): string | undefined {
|
|
68
|
+
if (!parsed) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (parsed.disabled) {
|
|
72
|
+
return "none";
|
|
73
|
+
}
|
|
74
|
+
return `all ${parsed.duration}ms ${parsed.easing}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function useMotionGuard(
|
|
78
|
+
ref: React.RefObject<HTMLElement | null>,
|
|
79
|
+
enabled: boolean,
|
|
80
|
+
styleFingerprint?: string
|
|
81
|
+
): boolean {
|
|
82
|
+
const [yielded, setYielded] = React.useState(false);
|
|
83
|
+
|
|
84
|
+
React.useLayoutEffect(() => {
|
|
85
|
+
if (!(enabled && !yielded)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const el = ref.current;
|
|
89
|
+
if (!el || typeof MutationObserver === "undefined") {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const observer = new MutationObserver(() => {
|
|
93
|
+
observer.disconnect();
|
|
94
|
+
setYielded(true);
|
|
95
|
+
});
|
|
96
|
+
observer.observe(el, { attributeFilter: ["style"], attributes: true });
|
|
97
|
+
return () => {
|
|
98
|
+
observer.disconnect();
|
|
99
|
+
};
|
|
100
|
+
}, [ref, enabled, yielded, styleFingerprint]);
|
|
101
|
+
|
|
102
|
+
return yielded;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const reducedMotionQuery = "(prefers-reduced-motion: reduce)";
|
|
106
|
+
|
|
107
|
+
function subscribeReducedMotion(callback: () => void): () => void {
|
|
108
|
+
if (
|
|
109
|
+
typeof window === "undefined" ||
|
|
110
|
+
typeof window.matchMedia !== "function"
|
|
111
|
+
) {
|
|
112
|
+
return () => undefined;
|
|
113
|
+
}
|
|
114
|
+
const mq = window.matchMedia(reducedMotionQuery);
|
|
115
|
+
mq.addEventListener("change", callback);
|
|
116
|
+
return () => mq.removeEventListener("change", callback);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function getReducedMotionSnapshot(): boolean {
|
|
120
|
+
if (
|
|
121
|
+
typeof window === "undefined" ||
|
|
122
|
+
typeof window.matchMedia !== "function"
|
|
123
|
+
) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return window.matchMedia(reducedMotionQuery).matches;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getReducedMotionServerSnapshot(): boolean {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function useReducedMotion(): boolean {
|
|
134
|
+
return React.useSyncExternalStore(
|
|
135
|
+
subscribeReducedMotion,
|
|
136
|
+
getReducedMotionSnapshot,
|
|
137
|
+
getReducedMotionServerSnapshot
|
|
138
|
+
);
|
|
139
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* Frakment custom variants — required by registry components using data-*: utilities.
|
|
2
|
-
Without these, utility classes like data-checked:bg-primary become no-ops. */
|
|
3
1
|
@custom-variant fixed (&:is(.layout-fixed *));
|
|
4
2
|
@custom-variant data-open (&[data-state="open"]);
|
|
5
3
|
@custom-variant data-closed (&[data-state="closed"]);
|
|
@@ -77,13 +75,13 @@
|
|
|
77
75
|
--secondary: oklch(0.97 0 0);
|
|
78
76
|
--secondary-foreground: oklch(0.205 0 0);
|
|
79
77
|
--muted: oklch(0.97 0 0);
|
|
80
|
-
--muted-foreground: oklch(0.
|
|
78
|
+
--muted-foreground: oklch(0.556 0 0);
|
|
81
79
|
--subtle-foreground: oklch(0.32 0 0);
|
|
82
80
|
--accent: oklch(0.97 0 0);
|
|
83
81
|
--accent-foreground: oklch(0.205 0 0);
|
|
84
|
-
--destructive: oklch(0.577 0.
|
|
85
|
-
--border: oklch(0.
|
|
86
|
-
--input: oklch(0.
|
|
82
|
+
--destructive: oklch(0.577 0.18 27.325);
|
|
83
|
+
--border: oklch(0.922 0 0);
|
|
84
|
+
--input: oklch(0.922 0 0);
|
|
87
85
|
--ring: oklch(0.708 0 0);
|
|
88
86
|
--chart-1: var(--color-blue-300);
|
|
89
87
|
--chart-2: var(--color-blue-500);
|
|
@@ -113,14 +111,14 @@
|
|
|
113
111
|
--foreground: oklch(0.985 0 0);
|
|
114
112
|
--card: oklch(0.205 0 0);
|
|
115
113
|
--card-foreground: oklch(0.985 0 0);
|
|
116
|
-
--popover: oklch(0.
|
|
114
|
+
--popover: oklch(0.205 0 0);
|
|
117
115
|
--popover-foreground: oklch(0.985 0 0);
|
|
118
116
|
--primary: oklch(0.922 0 0);
|
|
119
117
|
--primary-foreground: oklch(0.205 0 0);
|
|
120
118
|
--secondary: oklch(0.269 0 0);
|
|
121
119
|
--secondary-foreground: oklch(0.985 0 0);
|
|
122
120
|
--muted: oklch(0.269 0 0);
|
|
123
|
-
--muted-foreground: oklch(0.
|
|
121
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
124
122
|
--subtle-foreground: oklch(0.88 0 0);
|
|
125
123
|
--accent: oklch(0.371 0 0);
|
|
126
124
|
--accent-foreground: oklch(0.985 0 0);
|
|
@@ -151,8 +149,6 @@
|
|
|
151
149
|
--selection-foreground: oklch(0.205 0 0);
|
|
152
150
|
}
|
|
153
151
|
|
|
154
|
-
/* Component utilities - kept here for the experiment */
|
|
155
|
-
|
|
156
152
|
@utility border-grid {
|
|
157
153
|
@apply border-border/50 dark:border-border;
|
|
158
154
|
}
|
|
@@ -190,9 +186,6 @@
|
|
|
190
186
|
}
|
|
191
187
|
}
|
|
192
188
|
|
|
193
|
-
/* Global scrollbar: transparent track, thin neutral thumb with gap, no arrow.
|
|
194
|
-
Injected to end users via the FRAKMENT THEME block (cli/templates/theme.css).
|
|
195
|
-
The `no-scrollbar` utility wins specificity and still hides scrollbars where used. */
|
|
196
189
|
*::-webkit-scrollbar {
|
|
197
190
|
width: 8px;
|
|
198
191
|
height: 8px;
|
|
@@ -225,10 +218,6 @@
|
|
|
225
218
|
scrollbar-gutter: stable;
|
|
226
219
|
}
|
|
227
220
|
|
|
228
|
-
/* === Registry animations === */
|
|
229
|
-
/* Injected to end users via the FRAKMENT THEME block.
|
|
230
|
-
Required by registry components that use animate-* utilities. */
|
|
231
|
-
|
|
232
221
|
@theme {
|
|
233
222
|
--animate-shimmer: shimmer 3.2s linear infinite;
|
|
234
223
|
|
|
@@ -242,8 +231,6 @@
|
|
|
242
231
|
}
|
|
243
232
|
}
|
|
244
233
|
|
|
245
|
-
/* ---- shimmer utility (CSS class) ---- */
|
|
246
|
-
|
|
247
234
|
@property --shimmer-angle {
|
|
248
235
|
syntax: "<angle>";
|
|
249
236
|
inherits: false;
|
|
@@ -307,8 +294,6 @@
|
|
|
307
294
|
animation: none;
|
|
308
295
|
}
|
|
309
296
|
|
|
310
|
-
/* ---- scroll-fade utility ---- */
|
|
311
|
-
|
|
312
297
|
@property --scroll-fade-size {
|
|
313
298
|
syntax: "<length-percentage>";
|
|
314
299
|
inherits: false;
|
|
@@ -592,7 +577,6 @@
|
|
|
592
577
|
}
|
|
593
578
|
}
|
|
594
579
|
|
|
595
|
-
/* highlight.js — syntax highlight for Markdown code blocks */
|
|
596
580
|
.hljs {
|
|
597
581
|
color: var(--foreground);
|
|
598
582
|
background: transparent;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frakment",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "CLI and design system for the
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "MIT-licensed CLI and design system for the Frakment component registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
7
7
|
"frakment",
|
|
@@ -9,24 +9,40 @@
|
|
|
9
9
|
"registry",
|
|
10
10
|
"tailwindcss"
|
|
11
11
|
],
|
|
12
|
-
"
|
|
13
|
-
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/frakment/ui.git",
|
|
15
|
+
"directory": "packages/cli"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "The Frakment Authors (https://github.com/frakment/ui)",
|
|
14
19
|
"type": "module",
|
|
15
20
|
"bin": {
|
|
16
|
-
"frakment": "./bin/index.js"
|
|
21
|
+
"frakment": "./dist/bin/index.js"
|
|
17
22
|
},
|
|
18
23
|
"files": [
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"templates"
|
|
24
|
+
"dist",
|
|
25
|
+
"LICENSE"
|
|
22
26
|
],
|
|
23
27
|
"dependencies": {
|
|
24
|
-
"
|
|
25
|
-
"commander": "^15.
|
|
28
|
+
"chalk": "^6.0.1",
|
|
29
|
+
"commander": "^15.1.0",
|
|
26
30
|
"execa": "^10.2.1",
|
|
27
|
-
"
|
|
31
|
+
"ora": "^10.0.0",
|
|
32
|
+
"prompts": "^2.4.2"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/prompts": "^2.4.9",
|
|
36
|
+
"@types/react": "19.3.0",
|
|
37
|
+
"clsx": "^2.1.1",
|
|
38
|
+
"react": "19.3.1",
|
|
39
|
+
"tailwind-merge": "^3.7.1"
|
|
28
40
|
},
|
|
29
41
|
"engines": {
|
|
30
|
-
"node": ">=22.
|
|
42
|
+
"node": ">=22.18.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/copy-runtime-package.ts",
|
|
46
|
+
"typecheck": "tsc --noEmit"
|
|
31
47
|
}
|
|
32
|
-
}
|
|
48
|
+
}
|
package/bin/index.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { Command } from "commander";
|
|
5
|
-
import pc from "picocolors";
|
|
6
|
-
|
|
7
|
-
import { add } from "../src/commands/add.js";
|
|
8
|
-
import { init } from "../src/commands/init.js";
|
|
9
|
-
import { list } from "../src/commands/list.js";
|
|
10
|
-
|
|
11
|
-
const __dirname = import.meta.dirname;
|
|
12
|
-
const pkg = JSON.parse(
|
|
13
|
-
readFileSync(path.resolve(__dirname, "../package.json"), "utf-8")
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const program = new Command();
|
|
17
|
-
|
|
18
|
-
program
|
|
19
|
-
.name("frakment")
|
|
20
|
-
.description("Monochrome design system and component registry")
|
|
21
|
-
.version(pkg.version)
|
|
22
|
-
.addHelpText(
|
|
23
|
-
"after",
|
|
24
|
-
`
|
|
25
|
-
Examples:
|
|
26
|
-
${pc.dim("$ frakment init")}
|
|
27
|
-
${pc.dim("$ frakment add status-chip")}
|
|
28
|
-
${pc.dim("$ frakment list")}
|
|
29
|
-
`
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
program
|
|
33
|
-
.command("init")
|
|
34
|
-
.description("Initialize frakment in your project")
|
|
35
|
-
.action(init);
|
|
36
|
-
|
|
37
|
-
program
|
|
38
|
-
.command("add <component>")
|
|
39
|
-
.description("Add a component from the frakment registry")
|
|
40
|
-
.option("--registry <url>", "Custom registry URL")
|
|
41
|
-
.option("--overwrite", "Overwrite existing files", false)
|
|
42
|
-
.action(add);
|
|
43
|
-
|
|
44
|
-
program
|
|
45
|
-
.command("list")
|
|
46
|
-
.description("List available components")
|
|
47
|
-
.option("--registry <url>", "Custom registry URL")
|
|
48
|
-
.action(list);
|
|
49
|
-
|
|
50
|
-
program.parse();
|
package/src/commands/add.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
import * as p from "@clack/prompts";
|
|
6
|
-
import { execa } from "execa";
|
|
7
|
-
import pc from "picocolors";
|
|
8
|
-
|
|
9
|
-
import { detectPackageManager, findProjectRoot } from "../utils/detect.js";
|
|
10
|
-
|
|
11
|
-
async function fetchComponent(name, registryUrl, s) {
|
|
12
|
-
s.start(`fetching ${name}`);
|
|
13
|
-
try {
|
|
14
|
-
const res = await fetch(`${registryUrl}/${name}.json`);
|
|
15
|
-
if (!res.ok) {
|
|
16
|
-
throw new Error(`HTTP ${res.status}`);
|
|
17
|
-
}
|
|
18
|
-
const payload = await res.json();
|
|
19
|
-
s.stop(`${pc.green("✓")} fetched ${name}`);
|
|
20
|
-
return payload;
|
|
21
|
-
} catch {
|
|
22
|
-
s.stop(`${pc.red("✗")} ${name} not found in registry`);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function writeFileSafely(file, cwd, options) {
|
|
28
|
-
const targetPath = path.join(cwd, file.path);
|
|
29
|
-
if (existsSync(targetPath) && !options.overwrite) {
|
|
30
|
-
const overwrite = await p.confirm({
|
|
31
|
-
initialValue: false,
|
|
32
|
-
message: `${file.path} already exists. Overwrite?`,
|
|
33
|
-
});
|
|
34
|
-
if (p.isCancel(overwrite) || !overwrite) {
|
|
35
|
-
p.log.info(`skipped ${file.path}`);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
await mkdir(path.dirname(targetPath), { recursive: true });
|
|
40
|
-
const output =
|
|
41
|
-
file.encoding === "base64"
|
|
42
|
-
? Buffer.from(file.content, "base64")
|
|
43
|
-
: file.content.replaceAll("\r\n", "\n");
|
|
44
|
-
await writeFile(targetPath, output);
|
|
45
|
-
p.log.success(file.path);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function add(componentName, options) {
|
|
49
|
-
p.intro(`${pc.dim("frakment")} add ${pc.bold(componentName)}`);
|
|
50
|
-
|
|
51
|
-
let cwd;
|
|
52
|
-
try {
|
|
53
|
-
cwd = findProjectRoot(process.cwd());
|
|
54
|
-
} catch (error) {
|
|
55
|
-
p.outro(pc.red("error ") + error.message);
|
|
56
|
-
process.exit(1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const configPath = path.join(cwd, "components.json");
|
|
60
|
-
if (!existsSync(configPath)) {
|
|
61
|
-
p.outro(
|
|
62
|
-
`${pc.red(
|
|
63
|
-
"error "
|
|
64
|
-
)}components.json not found. Run \`frakment init\` first.`
|
|
65
|
-
);
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const configRaw = await readFile(configPath, "utf-8");
|
|
70
|
-
const config = JSON.parse(configRaw.replace(/^\uFEFF/u, ""));
|
|
71
|
-
const registryUrl = (options.registry ?? config.registry).replace(/\/$/u, "");
|
|
72
|
-
const s = p.spinner();
|
|
73
|
-
|
|
74
|
-
// 1. Recursively fetch the component and its registryDependencies
|
|
75
|
-
const queue = [componentName];
|
|
76
|
-
const fetched = new Map();
|
|
77
|
-
const npmDeps = new Set();
|
|
78
|
-
|
|
79
|
-
while (queue.length) {
|
|
80
|
-
const name = queue.shift();
|
|
81
|
-
if (fetched.has(name)) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
const payload = await fetchComponent(name, registryUrl, s);
|
|
85
|
-
fetched.set(name, payload);
|
|
86
|
-
for (const d of payload.dependencies ?? []) {
|
|
87
|
-
npmDeps.add(d);
|
|
88
|
-
}
|
|
89
|
-
for (const d of payload.registryDependencies ?? []) {
|
|
90
|
-
if (!fetched.has(d)) {
|
|
91
|
-
queue.push(d);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 2. Write registry deps first (imports resolve), then main component
|
|
97
|
-
// Detect src/ layout: component files go under src/, but public/ assets
|
|
98
|
-
// stay at project root (Next.js serves public/ from root regardless of src/).
|
|
99
|
-
const isSrcLayout = config.tailwind?.css?.startsWith("src/") ?? false;
|
|
100
|
-
const resolveTargetPath = (p) => {
|
|
101
|
-
if (!isSrcLayout) {
|
|
102
|
-
return p;
|
|
103
|
-
}
|
|
104
|
-
if (p.startsWith("public/")) {
|
|
105
|
-
return p;
|
|
106
|
-
}
|
|
107
|
-
return `src/${p}`;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const order = [...fetched.keys()].filter((n) => n !== componentName);
|
|
111
|
-
order.push(componentName);
|
|
112
|
-
for (const name of order) {
|
|
113
|
-
for (const file of fetched.get(name).files ?? []) {
|
|
114
|
-
const targetFile = { ...file, path: resolveTargetPath(file.path) };
|
|
115
|
-
await writeFileSafely(targetFile, cwd, options);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// 3. Install npm dependencies
|
|
120
|
-
if (npmDeps.size > 0) {
|
|
121
|
-
const pkgPath = path.join(cwd, "package.json");
|
|
122
|
-
const pkgRaw = await readFile(pkgPath, "utf-8");
|
|
123
|
-
const pkg = JSON.parse(pkgRaw.replace(/^\uFEFF/u, ""));
|
|
124
|
-
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
125
|
-
const missing = [...npmDeps].filter((d) => !allDeps[d]);
|
|
126
|
-
if (missing.length > 0) {
|
|
127
|
-
s.start(`installing ${missing.join(", ")}`);
|
|
128
|
-
const pm = detectPackageManager(cwd);
|
|
129
|
-
try {
|
|
130
|
-
const args =
|
|
131
|
-
pm === "npm" ? ["install", ...missing] : ["add", ...missing];
|
|
132
|
-
await execa(pm, args, { cwd, stdio: "ignore" });
|
|
133
|
-
s.stop(`${pc.green("✓")} installed ${missing.length} package(s)`);
|
|
134
|
-
} catch (error) {
|
|
135
|
-
s.stop(`${pc.red("✗")} failed to install dependencies`);
|
|
136
|
-
p.log.warn(error.message);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
p.outro(`${pc.green("✓")} ${componentName} added`);
|
|
142
|
-
}
|
package/src/commands/init.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
import * as p from "@clack/prompts";
|
|
6
|
-
import { execa } from "execa";
|
|
7
|
-
import pc from "picocolors";
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
detectGlobalsCss,
|
|
11
|
-
detectPackageManager,
|
|
12
|
-
findProjectRoot,
|
|
13
|
-
} from "../utils/detect.js";
|
|
14
|
-
|
|
15
|
-
const __dirname = import.meta.dirname;
|
|
16
|
-
const TEMPLATES_DIR = path.resolve(__dirname, "../../templates");
|
|
17
|
-
|
|
18
|
-
const DEFAULT_REGISTRY = "https://frakment.vercel.app/r";
|
|
19
|
-
const CONFIG_FILE = "components.json";
|
|
20
|
-
const THEME_MARKER_START = "/* ==== FRAKMENT THEME START ==== */";
|
|
21
|
-
const THEME_MARKER_END = "/* ==== FRAKMENT THEME END ==== */";
|
|
22
|
-
|
|
23
|
-
export async function init() {
|
|
24
|
-
p.intro(`${pc.dim("frakment")} init`);
|
|
25
|
-
|
|
26
|
-
let cwd;
|
|
27
|
-
try {
|
|
28
|
-
cwd = findProjectRoot(process.cwd());
|
|
29
|
-
} catch (error) {
|
|
30
|
-
p.outro(pc.red("error ") + error.message);
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const configPath = path.join(cwd, CONFIG_FILE);
|
|
35
|
-
const configExists = existsSync(configPath);
|
|
36
|
-
let shouldWriteConfig = !configExists;
|
|
37
|
-
|
|
38
|
-
if (configExists) {
|
|
39
|
-
const overwrite = await p.confirm({
|
|
40
|
-
initialValue: false,
|
|
41
|
-
message: `${CONFIG_FILE} already exists. Overwrite?`,
|
|
42
|
-
});
|
|
43
|
-
if (p.isCancel(overwrite)) {
|
|
44
|
-
p.outro(pc.dim("cancelled"));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (overwrite) {
|
|
48
|
-
shouldWriteConfig = true;
|
|
49
|
-
} else {
|
|
50
|
-
p.log.info(`keeping existing ${CONFIG_FILE}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const s = p.spinner();
|
|
55
|
-
const cssPath = detectGlobalsCss(cwd);
|
|
56
|
-
|
|
57
|
-
// 1. components.json (write only if new or user chose to overwrite)
|
|
58
|
-
if (shouldWriteConfig) {
|
|
59
|
-
s.start("writing components.json");
|
|
60
|
-
const template = JSON.parse(
|
|
61
|
-
await readFile(path.join(TEMPLATES_DIR, "components.json"), "utf-8")
|
|
62
|
-
);
|
|
63
|
-
const config = {
|
|
64
|
-
...template,
|
|
65
|
-
registry: DEFAULT_REGISTRY,
|
|
66
|
-
tailwind: { ...template.tailwind, css: cssPath },
|
|
67
|
-
};
|
|
68
|
-
await writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
69
|
-
s.stop(`${pc.green("✓")} components.json`);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 2. theme (inline block)
|
|
73
|
-
const cssFullPath = path.join(cwd, cssPath);
|
|
74
|
-
if (!existsSync(cssFullPath)) {
|
|
75
|
-
p.log.error(`CSS file not found: ${cssPath}`);
|
|
76
|
-
p.outro(
|
|
77
|
-
`${pc.red(
|
|
78
|
-
"error "
|
|
79
|
-
)}Could not find globals.css. Frakment needs an existing Tailwind v4 entry file.`
|
|
80
|
-
);
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let css = await readFile(cssFullPath, "utf-8");
|
|
85
|
-
css = css.replace(/^\uFEFF/u, "");
|
|
86
|
-
|
|
87
|
-
if (!/^@import\s+["']tailwindcss(\/|["'])/mu.test(css)) {
|
|
88
|
-
p.outro(
|
|
89
|
-
`${pc.red(
|
|
90
|
-
"error "
|
|
91
|
-
)}Frakment requires Tailwind v4. Could not find @import "tailwindcss" in ${
|
|
92
|
-
cssPath
|
|
93
|
-
}`
|
|
94
|
-
);
|
|
95
|
-
process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Cleanup: strip any prior theme block (marker-bounded) and
|
|
99
|
-
// any split-approach @import "./theme.css" line.
|
|
100
|
-
css = css.replaceAll(
|
|
101
|
-
new RegExp(
|
|
102
|
-
`\\n*${escapeRegex(THEME_MARKER_START)}[\\s\\S]*?${escapeRegex(THEME_MARKER_END)}\\n*`,
|
|
103
|
-
"g"
|
|
104
|
-
),
|
|
105
|
-
"\n"
|
|
106
|
-
);
|
|
107
|
-
css = css.replaceAll(/^@import\s+["']\.\/theme\.css["'];?\s*$\n?/gmu, "");
|
|
108
|
-
css = `${css.replaceAll(/\n{3,}/gu, "\n\n").trimEnd()}\n`;
|
|
109
|
-
|
|
110
|
-
// Inject fresh theme block right after the last top-level @import
|
|
111
|
-
s.start("injecting theme block");
|
|
112
|
-
const themeContent = await readFile(
|
|
113
|
-
path.join(TEMPLATES_DIR, "theme.css"),
|
|
114
|
-
"utf-8"
|
|
115
|
-
);
|
|
116
|
-
const wrapped = `${THEME_MARKER_START}\n${themeContent.trim()}\n${THEME_MARKER_END}`;
|
|
117
|
-
|
|
118
|
-
const importMatches = [...css.matchAll(/^@import\s+[^;\n]+;\s*$/gmu)];
|
|
119
|
-
if (importMatches.length > 0) {
|
|
120
|
-
const lastMatch = importMatches.at(-1);
|
|
121
|
-
const insertAt = lastMatch.index + lastMatch[0].length;
|
|
122
|
-
css = `${css.slice(0, insertAt)}\n\n${wrapped}${css.slice(insertAt)}`;
|
|
123
|
-
} else {
|
|
124
|
-
css = `${css.trimEnd()}\n\n${wrapped}\n`;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
await writeFile(cssFullPath, css);
|
|
128
|
-
s.stop(`${pc.green("✓")} theme block`);
|
|
129
|
-
|
|
130
|
-
// 3. lib/utils.ts
|
|
131
|
-
if (!existsSync(path.join(cwd, "lib/utils.ts"))) {
|
|
132
|
-
s.start("creating lib/utils.ts");
|
|
133
|
-
await mkdir(path.join(cwd, "lib"), { recursive: true });
|
|
134
|
-
await writeFile(
|
|
135
|
-
path.join(cwd, "lib/utils.ts"),
|
|
136
|
-
`import { clsx, type ClassValue } from "clsx";
|
|
137
|
-
import { twMerge } from "tailwind-merge";
|
|
138
|
-
|
|
139
|
-
export function cn(...inputs: ClassValue[]) {
|
|
140
|
-
return twMerge(clsx(inputs));
|
|
141
|
-
}
|
|
142
|
-
`
|
|
143
|
-
);
|
|
144
|
-
s.stop(`${pc.green("✓")} lib/utils.ts`);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// 3b. lib/animation.ts
|
|
148
|
-
if (!existsSync(path.join(cwd, "lib/animation.ts"))) {
|
|
149
|
-
s.start("creating lib/animation.ts");
|
|
150
|
-
await mkdir(path.join(cwd, "lib"), { recursive: true });
|
|
151
|
-
await writeFile(
|
|
152
|
-
path.join(cwd, "lib/animation.ts"),
|
|
153
|
-
`export const SPRING_SMOOTH = { type: "spring", stiffness: 200, damping: 30 } as const
|
|
154
|
-
|
|
155
|
-
export const EASE_OUT = [0.16, 1, 0.3, 1] as const
|
|
156
|
-
export const EASE_SMOOTH = [0.32, 0.72, 0, 1] as const
|
|
157
|
-
export const EASE_IN_OUT = [0.4, 0, 0.2, 1] as const
|
|
158
|
-
|
|
159
|
-
export const DURATION_FAST = 0.2
|
|
160
|
-
export const DURATION_SMOOTH = 0.45
|
|
161
|
-
`
|
|
162
|
-
);
|
|
163
|
-
s.stop(`${pc.green("✓")} lib/animation.ts`);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// 4. dependencies
|
|
167
|
-
const pkgPath = path.join(cwd, "package.json");
|
|
168
|
-
const pkgRaw = await readFile(pkgPath, "utf-8");
|
|
169
|
-
const pkg = JSON.parse(pkgRaw.replace(/^\uFEFF/u, ""));
|
|
170
|
-
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
171
|
-
const missing = [
|
|
172
|
-
"clsx",
|
|
173
|
-
"tailwind-merge",
|
|
174
|
-
"class-variance-authority",
|
|
175
|
-
"radix-ui",
|
|
176
|
-
"@phosphor-icons/react",
|
|
177
|
-
"motion",
|
|
178
|
-
].filter((d) => !allDeps[d]);
|
|
179
|
-
|
|
180
|
-
if (missing.length > 0) {
|
|
181
|
-
s.start(`installing ${missing.join(", ")}`);
|
|
182
|
-
const pm = detectPackageManager(cwd);
|
|
183
|
-
try {
|
|
184
|
-
const args = pm === "npm" ? ["install", ...missing] : ["add", ...missing];
|
|
185
|
-
await execa(pm, args, { cwd, stdio: "ignore" });
|
|
186
|
-
s.stop(`${pc.green("✓")} installed ${missing.length} package(s)`);
|
|
187
|
-
} catch (error) {
|
|
188
|
-
s.stop(`${pc.red("✗")} failed to install dependencies`);
|
|
189
|
-
p.log.warn(error.message);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
p.outro(
|
|
194
|
-
`${pc.green("✓")} frakment is ready\n\n` +
|
|
195
|
-
` Next ${pc.cyan("frakment add status-chip")}`
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function escapeRegex(s) {
|
|
200
|
-
return s.replaceAll(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
201
|
-
}
|