frakment 2.0.3 → 3.0.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/README.md +8 -8
- package/dist/bin/index.js +1 -5
- package/dist/package.json +6 -7
- package/dist/src/commands/add.js +19 -56
- package/dist/src/commands/init.js +15 -134
- package/dist/src/commands/list.js +31 -8
- package/dist/src/utils/detect.js +3 -0
- package/dist/src/utils/safe-path.js +93 -0
- package/package.json +5 -6
- package/dist/templates/expo/components.json +0 -20
- package/dist/templates/expo/lib/theme.ts +0 -63
- package/dist/templates/expo/lib/utils.ts +0 -5
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
Monochrome design system and component registry CLI.
|
|
7
7
|
|
|
8
|
-
Frakment is
|
|
8
|
+
Frakment-authored CLI code is licensed under MIT, which permits commercial use, modification, distribution, and sublicensing. Third-party dependencies retain their own licenses; see the [repository third-party notices](https://github.com/frakment/ui/blob/main/docs/legal/THIRD_PARTY_NOTICES.md).
|
|
9
9
|
|
|
10
10
|
## Requirements
|
|
11
11
|
|
|
@@ -16,12 +16,12 @@ Frakment is open source under the MIT License. Commercial use, modification, dis
|
|
|
16
16
|
|
|
17
17
|
The commands below use `npx`. Every package manager works.
|
|
18
18
|
|
|
19
|
-
| Package manager | Run
|
|
20
|
-
|
|
|
21
|
-
| npm
|
|
22
|
-
| pnpm
|
|
23
|
-
| yarn
|
|
24
|
-
| bun
|
|
19
|
+
| Package manager | Run |
|
|
20
|
+
| :-------------- | :----------------------------------- |
|
|
21
|
+
| npm | `npx frakment@latest <command>` |
|
|
22
|
+
| pnpm | `pnpm dlx frakment@latest <command>` |
|
|
23
|
+
| yarn | `yarn dlx frakment@latest <command>` |
|
|
24
|
+
| bun | `bunx frakment@latest <command>` |
|
|
25
25
|
|
|
26
26
|
The CLI auto-detects your package manager from the project lockfile when installing dependencies.
|
|
27
27
|
|
|
@@ -112,4 +112,4 @@ If your `globals.css` lives at `src/app/globals.css`, component files are writte
|
|
|
112
112
|
|
|
113
113
|
## License
|
|
114
114
|
|
|
115
|
-
MIT licensed
|
|
115
|
+
The CLI's own source is MIT licensed; see [LICENSE](./LICENSE). Third-party dependencies retain their respective licenses.
|
package/dist/bin/index.js
CHANGED
|
@@ -16,23 +16,19 @@ program
|
|
|
16
16
|
.addHelpText("after", `
|
|
17
17
|
Examples:
|
|
18
18
|
${chalk.dim("$ frakment init")}
|
|
19
|
-
${chalk.dim("$ frakment init --expo")}
|
|
20
19
|
${chalk.dim("$ frakment add button")}
|
|
21
|
-
${chalk.dim("$ frakment add button --expo")}
|
|
22
20
|
${chalk.dim("$ frakment add button bubble")}
|
|
23
21
|
${chalk.dim("$ frakment list")}
|
|
24
22
|
`);
|
|
25
23
|
program
|
|
26
24
|
.command("init")
|
|
27
25
|
.description("Initialize frakment in your project")
|
|
28
|
-
.
|
|
29
|
-
.action((...args) => init(args.at(-1).opts()));
|
|
26
|
+
.action(() => init());
|
|
30
27
|
program
|
|
31
28
|
.command("add <components...>")
|
|
32
29
|
.description("Add one or more components from the frakment registry")
|
|
33
30
|
.option("--dry-run", "Show planned file and dependency changes without writing")
|
|
34
31
|
.option("--registry <url>", "Custom registry URL")
|
|
35
|
-
.option("--expo", "Use the Expo / React Native registry")
|
|
36
32
|
.option("--skip-dependencies", "Do not install missing npm dependencies")
|
|
37
33
|
.option("--overwrite", "Overwrite existing files", false)
|
|
38
34
|
.action(add);
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frakment",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "MIT-licensed CLI and design system for the Frakment component registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
],
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/
|
|
14
|
+
"url": "git+https://github.com/frakment/ui.git",
|
|
15
15
|
"directory": "packages/cli"
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"author": "The Frakment Authors (https://github.com/
|
|
18
|
+
"author": "The Frakment Authors (https://github.com/frakment/ui)",
|
|
19
19
|
"type": "module",
|
|
20
20
|
"bin": {
|
|
21
21
|
"frakment": "./dist/bin/index.js"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "tsc -p tsconfig.build.json && node ../../scripts/copy-runtime-package.
|
|
29
|
-
"prepack": "
|
|
28
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/copy-runtime-package.ts",
|
|
29
|
+
"prepack": "node ../../scripts/run-package-script.ts build",
|
|
30
30
|
"typecheck": "tsc --noEmit"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
@@ -41,8 +41,7 @@
|
|
|
41
41
|
"@types/react": "19.3.0",
|
|
42
42
|
"clsx": "^2.1.1",
|
|
43
43
|
"react": "19.3.1",
|
|
44
|
-
"
|
|
45
|
-
"tailwind-merge": "^3.7.0"
|
|
44
|
+
"tailwind-merge": "^3.7.1"
|
|
46
45
|
},
|
|
47
46
|
"engines": {
|
|
48
47
|
"node": ">=22.18.0"
|
package/dist/src/commands/add.js
CHANGED
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
13
|
import { existsSync } from "node:fs";
|
|
14
|
-
import {
|
|
14
|
+
import { readFile } from "node:fs/promises";
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
import chalk from "chalk";
|
|
17
17
|
import { execa } from "execa";
|
|
@@ -19,11 +19,12 @@ import ora from "ora";
|
|
|
19
19
|
import prompts from "prompts";
|
|
20
20
|
import { detectPackageManager, findProjectRoot } from "../utils/detect.js";
|
|
21
21
|
import { logger } from "../utils/logger.js";
|
|
22
|
+
import { resolveSafePath as assertSafePath, writeFileWithinProject, } from "../utils/safe-path.js";
|
|
23
|
+
export { assertSafePath };
|
|
22
24
|
const componentNamePattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
23
25
|
const dependencyPattern = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(?:@[0-9A-Za-z*~^<>=|.+_-]+)?$/u;
|
|
24
26
|
const maxRegistryPayloadBytes = 10 * 1024 * 1024;
|
|
25
27
|
const defaultWebRegistry = "https://www.arrafi.dev/frakment/r";
|
|
26
|
-
const defaultExpoRegistry = "https://www.arrafi.dev/frakment/r/expo";
|
|
27
28
|
const defaultAliases = {
|
|
28
29
|
components: "@/components",
|
|
29
30
|
ui: "@/components/ui",
|
|
@@ -75,9 +76,12 @@ function assertDependency(dependency) {
|
|
|
75
76
|
throw new Error(`Invalid dependency in registry payload: ${String(dependency)}`);
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
|
-
const getDependencyName = (dependency) => {
|
|
79
|
+
export const getDependencyName = (dependency) => {
|
|
79
80
|
if (dependency.startsWith("@")) {
|
|
80
|
-
|
|
81
|
+
const versionSeparator = dependency.indexOf("@", 1);
|
|
82
|
+
return versionSeparator === -1
|
|
83
|
+
? dependency
|
|
84
|
+
: dependency.slice(0, versionSeparator);
|
|
81
85
|
}
|
|
82
86
|
return dependency.split("@")[0];
|
|
83
87
|
};
|
|
@@ -154,10 +158,7 @@ export function resolveRegistryUrl(config, options = {}) {
|
|
|
154
158
|
? configRecord.registry
|
|
155
159
|
: undefined;
|
|
156
160
|
const web = typeof registries.web === "string" ? registries.web : undefined;
|
|
157
|
-
const
|
|
158
|
-
const configured = options.expo
|
|
159
|
-
? (expo !== null && expo !== void 0 ? expo : defaultExpoRegistry)
|
|
160
|
-
: ((_a = registry !== null && registry !== void 0 ? registry : web) !== null && _a !== void 0 ? _a : defaultWebRegistry);
|
|
161
|
+
const configured = (_a = registry !== null && registry !== void 0 ? registry : web) !== null && _a !== void 0 ? _a : defaultWebRegistry;
|
|
161
162
|
return getRegistryUrl((_b = options.registry) !== null && _b !== void 0 ? _b : configured);
|
|
162
163
|
}
|
|
163
164
|
async function fetchComponent(name, registryUrl, spinner) {
|
|
@@ -185,57 +186,26 @@ async function fetchComponent(name, registryUrl, spinner) {
|
|
|
185
186
|
process.exit(1);
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
|
-
export async function assertSafePath(cwd, relativePath) {
|
|
189
|
-
if (typeof relativePath !== "string" || relativePath.length === 0) {
|
|
190
|
-
throw new Error("Invalid file path in registry payload");
|
|
191
|
-
}
|
|
192
|
-
if (relativePath.includes("\0")) {
|
|
193
|
-
throw new Error(`Null byte in path: ${relativePath}`);
|
|
194
|
-
}
|
|
195
|
-
if (path.isAbsolute(relativePath) || /^[a-zA-Z]:/.test(relativePath)) {
|
|
196
|
-
throw new Error(`Absolute path rejected: ${relativePath}`);
|
|
197
|
-
}
|
|
198
|
-
if (relativePath.split(/[\\/]/).some((seg) => seg === "..")) {
|
|
199
|
-
throw new Error(`Parent traversal rejected: ${relativePath}`);
|
|
200
|
-
}
|
|
201
|
-
const root = path.resolve(cwd);
|
|
202
|
-
const target = path.resolve(root, relativePath);
|
|
203
|
-
if (target !== root && !target.startsWith(root + path.sep)) {
|
|
204
|
-
throw new Error(`Path escapes project root: ${relativePath}`);
|
|
205
|
-
}
|
|
206
|
-
const realRoot = await realpath(root).catch(() => root);
|
|
207
|
-
let existingParent = path.dirname(target);
|
|
208
|
-
while (!existsSync(existingParent)) {
|
|
209
|
-
existingParent = path.dirname(existingParent);
|
|
210
|
-
}
|
|
211
|
-
const realParent = await realpath(existingParent).catch(() => existingParent);
|
|
212
|
-
if (realParent !== realRoot && !realParent.startsWith(realRoot + path.sep)) {
|
|
213
|
-
throw new Error(`Symlink escape rejected: ${relativePath}`);
|
|
214
|
-
}
|
|
215
|
-
if (existsSync(target) && (await lstat(target)).isSymbolicLink()) {
|
|
216
|
-
throw new Error(`Symlink target rejected: ${relativePath}`);
|
|
217
|
-
}
|
|
218
|
-
return target;
|
|
219
|
-
}
|
|
220
189
|
async function writeFileSafely(file, cwd, options, aliases) {
|
|
221
190
|
const targetPath = await assertSafePath(cwd, file.path);
|
|
222
|
-
|
|
223
|
-
|
|
191
|
+
let overwrite = options.overwrite === true;
|
|
192
|
+
if (existsSync(targetPath) && !overwrite) {
|
|
193
|
+
const { overwrite: shouldOverwrite } = await prompts({
|
|
224
194
|
initial: false,
|
|
225
195
|
message: `${file.path} already exists. Overwrite?`,
|
|
226
196
|
name: "overwrite",
|
|
227
197
|
type: "confirm",
|
|
228
198
|
});
|
|
229
|
-
if (
|
|
199
|
+
if (shouldOverwrite === undefined || !shouldOverwrite) {
|
|
230
200
|
logger.info(`Skipped ${file.path}.`);
|
|
231
201
|
return null;
|
|
232
202
|
}
|
|
203
|
+
overwrite = true;
|
|
233
204
|
}
|
|
234
|
-
await mkdir(path.dirname(targetPath), { recursive: true });
|
|
235
205
|
const output = file.encoding === "base64"
|
|
236
206
|
? Buffer.from(file.content, "base64")
|
|
237
207
|
: rewriteImports(file.content, aliases).replaceAll("\r\n", "\n");
|
|
238
|
-
await
|
|
208
|
+
await writeFileWithinProject(cwd, file.path, output, overwrite);
|
|
239
209
|
return file.path;
|
|
240
210
|
}
|
|
241
211
|
export async function add(componentNamesInput, options = {}) {
|
|
@@ -370,22 +340,15 @@ export async function add(componentNamesInput, options = {}) {
|
|
|
370
340
|
const s = ora("Installing dependencies").start();
|
|
371
341
|
const packages = missing.map(([, dependency]) => dependency);
|
|
372
342
|
try {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
stdio: "ignore",
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
const pm = detectPackageManager(cwd);
|
|
381
|
-
const args = pm === "npm" ? ["install", ...packages] : ["add", ...packages];
|
|
382
|
-
await execa(pm, args, { cwd, stdio: "ignore" });
|
|
383
|
-
}
|
|
343
|
+
const pm = detectPackageManager(cwd);
|
|
344
|
+
const args = pm === "npm" ? ["install", ...packages] : ["add", ...packages];
|
|
345
|
+
await execa(pm, args, { cwd, stdio: "ignore" });
|
|
384
346
|
s.succeed(`Installed ${missing.length} package(s).`);
|
|
385
347
|
}
|
|
386
348
|
catch (error) {
|
|
387
349
|
s.fail("Failed to install dependencies.");
|
|
388
350
|
logger.warn(error instanceof Error ? error.message : "Unknown error");
|
|
351
|
+
process.exitCode = 1;
|
|
389
352
|
}
|
|
390
353
|
}
|
|
391
354
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { execa } from "execa";
|
|
@@ -7,6 +7,7 @@ import ora from "ora";
|
|
|
7
7
|
import prompts from "prompts";
|
|
8
8
|
import { detectGlobalsCss, detectPackageManager, findProjectRoot, } from "../utils/detect.js";
|
|
9
9
|
import { logger } from "../utils/logger.js";
|
|
10
|
+
import { resolveSafePath, writeFileWithinProject } from "../utils/safe-path.js";
|
|
10
11
|
const __dirname = import.meta.dirname;
|
|
11
12
|
const templatesDir = path.resolve(__dirname, "../../templates");
|
|
12
13
|
const defaultRegistry = "https://www.arrafi.dev/frakment/r";
|
|
@@ -16,129 +17,7 @@ const themeMarkerEnd = "/* ==== FRAKMENT THEME END ==== */";
|
|
|
16
17
|
function escapeRegex(s) {
|
|
17
18
|
return s.replaceAll(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
18
19
|
}
|
|
19
|
-
async function
|
|
20
|
-
var _a, _b;
|
|
21
|
-
let cwd;
|
|
22
|
-
const preflight = ora("Expo preflight checks").start();
|
|
23
|
-
try {
|
|
24
|
-
cwd = findProjectRoot(process.cwd());
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
preflight.fail(error instanceof Error ? error.message : "Unknown error");
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
const pkgPath = path.join(cwd, "package.json");
|
|
31
|
-
let pkg;
|
|
32
|
-
try {
|
|
33
|
-
const raw = await readFile(pkgPath, "utf-8");
|
|
34
|
-
pkg = JSON.parse(raw.replace(/^\uFEFF/u, ""));
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
preflight.fail("Could not read package.json.");
|
|
38
|
-
logger.error(error instanceof Error ? error.message : "Unknown error");
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
const allDeps = Object.assign(Object.assign({}, pkg.dependencies), pkg.devDependencies);
|
|
42
|
-
const required = ["expo", "react-native", "nativewind", "tailwindcss"];
|
|
43
|
-
const missingFramework = required.filter((name) => !allDeps[name]);
|
|
44
|
-
if (missingFramework.length > 0) {
|
|
45
|
-
preflight.fail("Expo project prerequisites are missing.");
|
|
46
|
-
logger.error("frakment init --expo requires Expo, React Native, NativeWind, and Tailwind CSS.");
|
|
47
|
-
logger.info(`Missing: ${missingFramework.join(", ")}`);
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
preflight.succeed("Found Expo + React Native + NativeWind project.");
|
|
51
|
-
const cssCandidates = [
|
|
52
|
-
"global.css",
|
|
53
|
-
"app/global.css",
|
|
54
|
-
"src/global.css",
|
|
55
|
-
"src/app/global.css",
|
|
56
|
-
"styles/global.css",
|
|
57
|
-
];
|
|
58
|
-
const cssPath = cssCandidates.find((candidate) => existsSync(path.join(cwd, candidate)));
|
|
59
|
-
if (!cssPath) {
|
|
60
|
-
logger.error("Could not find the NativeWind stylesheet, for example global.css.");
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
const css = (await readFile(path.join(cwd, cssPath), "utf-8")).replace(/^\uFEFF/u, "");
|
|
64
|
-
if (!/@import\s+["']nativewind\/theme["'];?/u.test(css)) {
|
|
65
|
-
logger.error("The stylesheet must import nativewind/theme. Configure NativeWind first.");
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
const configPath = path.join(cwd, configFile);
|
|
69
|
-
let shouldWriteConfig = !existsSync(configPath);
|
|
70
|
-
if (!shouldWriteConfig) {
|
|
71
|
-
const { overwrite } = await prompts({
|
|
72
|
-
initial: false,
|
|
73
|
-
message: `${configFile} already exists. Overwrite?`,
|
|
74
|
-
name: "overwrite",
|
|
75
|
-
type: "confirm",
|
|
76
|
-
});
|
|
77
|
-
if (overwrite === undefined) {
|
|
78
|
-
logger.break();
|
|
79
|
-
logger.info("Cancelled.");
|
|
80
|
-
process.exit(0);
|
|
81
|
-
}
|
|
82
|
-
shouldWriteConfig = overwrite === true;
|
|
83
|
-
if (!shouldWriteConfig) {
|
|
84
|
-
logger.info(`Keeping existing ${configFile}.`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (shouldWriteConfig) {
|
|
88
|
-
const spinner = ora("Writing Expo components.json").start();
|
|
89
|
-
const templatePath = path.join(templatesDir, "expo", configFile);
|
|
90
|
-
const templateRaw = await readFile(templatePath, "utf-8");
|
|
91
|
-
const template = JSON.parse(templateRaw.replace(/^\uFEFF/u, ""));
|
|
92
|
-
if (template.platform !== "expo" || !((_a = template.registries) === null || _a === void 0 ? void 0 : _a.expo)) {
|
|
93
|
-
spinner.fail("Expo CLI template is missing its Expo registry.");
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
const config = Object.assign(Object.assign({}, template), { registry: (_b = template.registries.web) !== null && _b !== void 0 ? _b : defaultRegistry, tailwind: Object.assign(Object.assign({}, template.tailwind), { css: cssPath }) });
|
|
97
|
-
await writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
98
|
-
spinner.succeed(`Created ${configFile}.`);
|
|
99
|
-
}
|
|
100
|
-
for (const name of ["utils.ts", "theme.ts"]) {
|
|
101
|
-
const target = path.join(cwd, "lib", name);
|
|
102
|
-
if (existsSync(target)) {
|
|
103
|
-
logger.info(`Keeping existing lib/${name}.`);
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const source = path.join(templatesDir, "expo", "lib", name);
|
|
107
|
-
const content = await readFile(source, "utf-8");
|
|
108
|
-
await mkdir(path.dirname(target), { recursive: true });
|
|
109
|
-
await writeFile(target, content);
|
|
110
|
-
logger.log(`Created lib/${name}.`);
|
|
111
|
-
}
|
|
112
|
-
const baseDependencies = [
|
|
113
|
-
"clsx",
|
|
114
|
-
"tailwind-merge",
|
|
115
|
-
"class-variance-authority",
|
|
116
|
-
];
|
|
117
|
-
const missing = baseDependencies.filter((name) => !allDeps[name]);
|
|
118
|
-
if (missing.length > 0) {
|
|
119
|
-
const spinner = ora("Installing Expo dependencies").start();
|
|
120
|
-
try {
|
|
121
|
-
await execa("npx", ["expo", "install", ...missing], {
|
|
122
|
-
cwd,
|
|
123
|
-
stdio: "ignore",
|
|
124
|
-
});
|
|
125
|
-
spinner.succeed(`Installed ${missing.length} package(s).`);
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
spinner.fail("Failed to install Expo dependencies.");
|
|
129
|
-
logger.warn(error instanceof Error ? error.message : "Unknown error");
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
logger.break();
|
|
133
|
-
logger.log(chalk.green("Success!") +
|
|
134
|
-
" Expo initialization completed. Use frakment add <component> --expo for native components.");
|
|
135
|
-
logger.break();
|
|
136
|
-
}
|
|
137
|
-
export async function init(options = {}) {
|
|
138
|
-
if (options.expo) {
|
|
139
|
-
await initExpo();
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
20
|
+
export async function init() {
|
|
142
21
|
let cwd;
|
|
143
22
|
const preflight = ora("Preflight checks").start();
|
|
144
23
|
try {
|
|
@@ -150,7 +29,7 @@ export async function init(options = {}) {
|
|
|
150
29
|
process.exit(1);
|
|
151
30
|
}
|
|
152
31
|
const cssPath = detectGlobalsCss(cwd);
|
|
153
|
-
const cssFullPath =
|
|
32
|
+
const cssFullPath = await resolveSafePath(cwd, cssPath);
|
|
154
33
|
const cssCheck = ora("Verifying Tailwind CSS config").start();
|
|
155
34
|
if (!existsSync(cssFullPath)) {
|
|
156
35
|
cssCheck.fail(`CSS file not found: ${cssPath}`);
|
|
@@ -165,7 +44,7 @@ export async function init(options = {}) {
|
|
|
165
44
|
process.exit(1);
|
|
166
45
|
}
|
|
167
46
|
cssCheck.succeed(`Verifying Tailwind CSS config. Found ${chalk.cyan("v4")} in ${chalk.cyan(cssPath)}.`);
|
|
168
|
-
const configPath =
|
|
47
|
+
const configPath = await resolveSafePath(cwd, configFile);
|
|
169
48
|
const configExists = existsSync(configPath);
|
|
170
49
|
let shouldWriteConfig = !configExists;
|
|
171
50
|
if (configExists) {
|
|
@@ -190,7 +69,7 @@ export async function init(options = {}) {
|
|
|
190
69
|
const s = ora("Writing components.json").start();
|
|
191
70
|
const template = JSON.parse(await readFile(path.join(templatesDir, "components.json"), "utf-8"));
|
|
192
71
|
const config = Object.assign(Object.assign({}, template), { registry: defaultRegistry, tailwind: Object.assign(Object.assign({}, template.tailwind), { css: cssPath }) });
|
|
193
|
-
await
|
|
72
|
+
await writeFileWithinProject(cwd, configFile, `${JSON.stringify(config, null, 2)}\n`);
|
|
194
73
|
s.succeed("Writing components.json.");
|
|
195
74
|
}
|
|
196
75
|
const themeSpinner = ora("Updating CSS variables").start();
|
|
@@ -213,12 +92,12 @@ export async function init(options = {}) {
|
|
|
213
92
|
else {
|
|
214
93
|
css = `${css.trimEnd()}\n\n${wrapped}\n`;
|
|
215
94
|
}
|
|
216
|
-
await
|
|
95
|
+
await writeFileWithinProject(cwd, cssPath, css);
|
|
217
96
|
themeSpinner.succeed(`Updating CSS variables in ${cssPath}`);
|
|
218
|
-
|
|
97
|
+
const utilsPath = await resolveSafePath(cwd, "lib/utils.ts");
|
|
98
|
+
if (!existsSync(utilsPath)) {
|
|
219
99
|
const s = ora("Creating lib/utils.ts").start();
|
|
220
|
-
await
|
|
221
|
-
await writeFile(path.join(cwd, "lib/utils.ts"), `import { clsx, type ClassValue } from "clsx";
|
|
100
|
+
await writeFileWithinProject(cwd, "lib/utils.ts", `import { clsx, type ClassValue } from "clsx";
|
|
222
101
|
import { twMerge } from "tailwind-merge";
|
|
223
102
|
|
|
224
103
|
export function cn(...inputs: ClassValue[]) {
|
|
@@ -228,13 +107,13 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
228
107
|
s.succeed("Created 1 file:");
|
|
229
108
|
logger.log(" - lib/utils.ts");
|
|
230
109
|
}
|
|
231
|
-
|
|
110
|
+
const motionPath = await resolveSafePath(cwd, "lib/motion.ts");
|
|
111
|
+
if (existsSync(motionPath)) {
|
|
232
112
|
}
|
|
233
113
|
else {
|
|
234
114
|
const s = ora("Creating lib/motion.ts").start();
|
|
235
|
-
await mkdir(path.join(cwd, "lib"), { recursive: true });
|
|
236
115
|
const motion = await readFile(path.join(templatesDir, "lib/motion.ts"), "utf-8");
|
|
237
|
-
await
|
|
116
|
+
await writeFileWithinProject(cwd, "lib/motion.ts", motion);
|
|
238
117
|
s.succeed("Created 1 file:");
|
|
239
118
|
logger.log(" - lib/motion.ts");
|
|
240
119
|
}
|
|
@@ -259,6 +138,8 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
259
138
|
catch (error) {
|
|
260
139
|
s.fail("Failed to install dependencies.");
|
|
261
140
|
logger.warn(error instanceof Error ? error.message : "Unknown error");
|
|
141
|
+
process.exitCode = 1;
|
|
142
|
+
return;
|
|
262
143
|
}
|
|
263
144
|
}
|
|
264
145
|
logger.break();
|
|
@@ -5,8 +5,17 @@ import chalk from "chalk";
|
|
|
5
5
|
import ora from "ora";
|
|
6
6
|
import { findProjectRoot } from "../utils/detect.js";
|
|
7
7
|
import { logger } from "../utils/logger.js";
|
|
8
|
+
import { resolveRegistryUrl } from "./add.js";
|
|
9
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
export const isRegistryIndex = (value) => isRecord(value) &&
|
|
11
|
+
Array.isArray(value.components) &&
|
|
12
|
+
value.components.every((component) => isRecord(component) &&
|
|
13
|
+
typeof component.name === "string" &&
|
|
14
|
+
/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(component.name) &&
|
|
15
|
+
(component.description === undefined ||
|
|
16
|
+
typeof component.description === "string"));
|
|
8
17
|
export async function list(options) {
|
|
9
|
-
var _a
|
|
18
|
+
var _a;
|
|
10
19
|
let cwd;
|
|
11
20
|
const preflight = ora("Preflight checks").start();
|
|
12
21
|
try {
|
|
@@ -23,19 +32,33 @@ export async function list(options) {
|
|
|
23
32
|
logger.info("Run `frakment init` first.");
|
|
24
33
|
process.exit(1);
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
let registryUrl;
|
|
36
|
+
try {
|
|
37
|
+
const configRaw = await readFile(configPath, "utf-8");
|
|
38
|
+
const config = JSON.parse(configRaw.replace(/^\uFEFF/u, ""));
|
|
39
|
+
registryUrl = resolveRegistryUrl(config, options);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
logger.error(error instanceof Error ? error.message : "Invalid components.json.");
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
28
45
|
const s = ora("Fetching components").start();
|
|
29
46
|
let index;
|
|
30
47
|
try {
|
|
31
|
-
const res = await fetch(`${registryUrl}/index.json
|
|
48
|
+
const res = await fetch(`${registryUrl}/index.json`, {
|
|
49
|
+
signal: AbortSignal.timeout(30000),
|
|
50
|
+
});
|
|
32
51
|
if (!res.ok) {
|
|
33
52
|
throw new Error(`HTTP ${res.status}`);
|
|
34
53
|
}
|
|
35
|
-
|
|
54
|
+
const response = await res.json();
|
|
55
|
+
if (!isRegistryIndex(response)) {
|
|
56
|
+
throw new Error("Registry index has an invalid shape");
|
|
57
|
+
}
|
|
58
|
+
index = response;
|
|
36
59
|
}
|
|
37
|
-
catch (
|
|
38
|
-
s.fail(
|
|
60
|
+
catch (error) {
|
|
61
|
+
s.fail(`Failed to fetch component list: ${error instanceof Error ? error.message : "unknown error"}`);
|
|
39
62
|
process.exit(1);
|
|
40
63
|
}
|
|
41
64
|
s.succeed(`Found ${index.components.length} component(s).`);
|
|
@@ -47,7 +70,7 @@ export async function list(options) {
|
|
|
47
70
|
const nameWidth = Math.max(...index.components.map((c) => c.name.length));
|
|
48
71
|
logger.break();
|
|
49
72
|
for (const c of index.components) {
|
|
50
|
-
logger.log(` ${chalk.cyan(c.name.padEnd(nameWidth))} ${chalk.dim((
|
|
73
|
+
logger.log(` ${chalk.cyan(c.name.padEnd(nameWidth))} ${chalk.dim((_a = c.description) !== null && _a !== void 0 ? _a : "")}`);
|
|
51
74
|
}
|
|
52
75
|
logger.break();
|
|
53
76
|
logger.log(`Add one with ${chalk.cyan("frakment add <name>")}`);
|
package/dist/src/utils/detect.js
CHANGED
|
@@ -17,6 +17,9 @@ export function detectPackageManager(cwd) {
|
|
|
17
17
|
if (existsSync(path.join(cwd, "yarn.lock"))) {
|
|
18
18
|
return "yarn";
|
|
19
19
|
}
|
|
20
|
+
if (existsSync(path.join(cwd, "bun.lock"))) {
|
|
21
|
+
return "bun";
|
|
22
|
+
}
|
|
20
23
|
if (existsSync(path.join(cwd, "bun.lockb"))) {
|
|
21
24
|
return "bun";
|
|
22
25
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { link, lstat, mkdir, realpath, rename, rm, writeFile, } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const isWithin = (root, target) => {
|
|
5
|
+
const relative = path.relative(root, target);
|
|
6
|
+
return (relative === "" ||
|
|
7
|
+
(relative !== ".." &&
|
|
8
|
+
!relative.startsWith(`..${path.sep}`) &&
|
|
9
|
+
!path.isAbsolute(relative)));
|
|
10
|
+
};
|
|
11
|
+
const isPathMissing = (error) => error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
12
|
+
export async function resolveSafePath(cwd, relativePath) {
|
|
13
|
+
if (typeof relativePath !== "string" || relativePath.length === 0) {
|
|
14
|
+
throw new Error("Invalid file path in registry payload");
|
|
15
|
+
}
|
|
16
|
+
if (relativePath.includes("\0")) {
|
|
17
|
+
throw new Error(`Null byte in path: ${relativePath}`);
|
|
18
|
+
}
|
|
19
|
+
if (path.isAbsolute(relativePath) ||
|
|
20
|
+
path.win32.isAbsolute(relativePath) ||
|
|
21
|
+
/^[a-zA-Z]:/u.test(relativePath)) {
|
|
22
|
+
throw new Error(`Absolute path rejected: ${relativePath}`);
|
|
23
|
+
}
|
|
24
|
+
if (relativePath.split(/[\\/]/u).some((segment) => segment === "..")) {
|
|
25
|
+
throw new Error(`Parent traversal rejected: ${relativePath}`);
|
|
26
|
+
}
|
|
27
|
+
const root = await realpath(path.resolve(cwd));
|
|
28
|
+
const target = path.resolve(root, relativePath);
|
|
29
|
+
if (!isWithin(root, target)) {
|
|
30
|
+
throw new Error(`Path escapes project root: ${relativePath}`);
|
|
31
|
+
}
|
|
32
|
+
let existingAncestor = path.dirname(target);
|
|
33
|
+
let realAncestor;
|
|
34
|
+
while (true) {
|
|
35
|
+
try {
|
|
36
|
+
realAncestor = await realpath(existingAncestor);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (!isPathMissing(error)) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
const parent = path.dirname(existingAncestor);
|
|
44
|
+
if (parent === existingAncestor) {
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
existingAncestor = parent;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!isWithin(root, realAncestor)) {
|
|
51
|
+
throw new Error(`Symlink escape rejected: ${relativePath}`);
|
|
52
|
+
}
|
|
53
|
+
const canonicalTarget = path.resolve(realAncestor, path.relative(existingAncestor, target));
|
|
54
|
+
if (!isWithin(root, canonicalTarget)) {
|
|
55
|
+
throw new Error(`Path escapes project root: ${relativePath}`);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
if ((await lstat(target)).isSymbolicLink()) {
|
|
59
|
+
throw new Error(`Symlink target rejected: ${relativePath}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (!isPathMissing(error)) {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return canonicalTarget;
|
|
68
|
+
}
|
|
69
|
+
export async function writeFileWithinProject(cwd, relativePath, contents, overwrite = true) {
|
|
70
|
+
const initialTarget = await resolveSafePath(cwd, relativePath);
|
|
71
|
+
await mkdir(path.dirname(initialTarget), { recursive: true });
|
|
72
|
+
const target = await resolveSafePath(cwd, relativePath);
|
|
73
|
+
const parent = await realpath(path.dirname(target));
|
|
74
|
+
const root = await realpath(path.resolve(cwd));
|
|
75
|
+
if (!isWithin(root, parent)) {
|
|
76
|
+
throw new Error(`Symlink escape rejected: ${relativePath}`);
|
|
77
|
+
}
|
|
78
|
+
const canonicalTarget = path.join(parent, path.basename(target));
|
|
79
|
+
const temporary = path.join(parent, `.frakment-${randomUUID()}.tmp`);
|
|
80
|
+
await writeFile(temporary, contents, { flag: "wx" });
|
|
81
|
+
try {
|
|
82
|
+
if (overwrite) {
|
|
83
|
+
await rename(temporary, canonicalTarget);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
await link(temporary, canonicalTarget);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await rm(temporary, { force: true });
|
|
91
|
+
}
|
|
92
|
+
return canonicalTarget;
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frakment",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "MIT-licensed CLI and design system for the Frakment component registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
],
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/
|
|
14
|
+
"url": "git+https://github.com/frakment/ui.git",
|
|
15
15
|
"directory": "packages/cli"
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"author": "The Frakment Authors (https://github.com/
|
|
18
|
+
"author": "The Frakment Authors (https://github.com/frakment/ui)",
|
|
19
19
|
"type": "module",
|
|
20
20
|
"bin": {
|
|
21
21
|
"frakment": "./dist/bin/index.js"
|
|
@@ -36,14 +36,13 @@
|
|
|
36
36
|
"@types/react": "19.3.0",
|
|
37
37
|
"clsx": "^2.1.1",
|
|
38
38
|
"react": "19.3.1",
|
|
39
|
-
"
|
|
40
|
-
"tailwind-merge": "^3.7.0"
|
|
39
|
+
"tailwind-merge": "^3.7.1"
|
|
41
40
|
},
|
|
42
41
|
"engines": {
|
|
43
42
|
"node": ">=22.18.0"
|
|
44
43
|
},
|
|
45
44
|
"scripts": {
|
|
46
|
-
"build": "tsc -p tsconfig.build.json && node ../../scripts/copy-runtime-package.
|
|
45
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/copy-runtime-package.ts",
|
|
47
46
|
"typecheck": "tsc --noEmit"
|
|
48
47
|
}
|
|
49
48
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://www.arrafi.dev/frakment/schema/frakment.json",
|
|
3
|
-
"platform": "expo",
|
|
4
|
-
"registry": "https://www.arrafi.dev/frakment/r",
|
|
5
|
-
"registries": {
|
|
6
|
-
"web": "https://www.arrafi.dev/frakment/r",
|
|
7
|
-
"expo": "https://www.arrafi.dev/frakment/r/expo"
|
|
8
|
-
},
|
|
9
|
-
"aliases": {
|
|
10
|
-
"components": "@/components",
|
|
11
|
-
"ui": "@/components/ui",
|
|
12
|
-
"utils": "@/lib/utils",
|
|
13
|
-
"lib": "@/lib",
|
|
14
|
-
"hooks": "@/hooks"
|
|
15
|
-
},
|
|
16
|
-
"tailwind": {
|
|
17
|
-
"config": "",
|
|
18
|
-
"css": "global.css"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { useColorScheme } from "react-native";
|
|
2
|
-
|
|
3
|
-
export interface ThemeColors {
|
|
4
|
-
accent: string;
|
|
5
|
-
accentForeground: string;
|
|
6
|
-
background: string;
|
|
7
|
-
border: string;
|
|
8
|
-
destructive: string;
|
|
9
|
-
destructiveForeground: string;
|
|
10
|
-
destructiveHover: string;
|
|
11
|
-
foreground: string;
|
|
12
|
-
input: string;
|
|
13
|
-
mutedForeground: string;
|
|
14
|
-
primary: string;
|
|
15
|
-
primaryForeground: string;
|
|
16
|
-
primaryHover: string;
|
|
17
|
-
secondary: string;
|
|
18
|
-
secondaryForeground: string;
|
|
19
|
-
secondaryHover: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const lightColors: ThemeColors = {
|
|
23
|
-
accent: "rgba(245, 245, 245, 1)",
|
|
24
|
-
accentForeground: "rgba(23, 23, 23, 1)",
|
|
25
|
-
background: "rgba(255, 255, 255, 1)",
|
|
26
|
-
border: "rgba(229, 229, 229, 1)",
|
|
27
|
-
destructive: "rgba(239, 68, 68, 1)",
|
|
28
|
-
destructiveForeground: "rgba(255, 255, 255, 1)",
|
|
29
|
-
destructiveHover: "rgba(240, 86, 86, 1)",
|
|
30
|
-
foreground: "rgba(10, 10, 10, 1)",
|
|
31
|
-
input: "rgba(227, 227, 227, 1)",
|
|
32
|
-
mutedForeground: "rgba(102, 102, 102, 1)",
|
|
33
|
-
primary: "rgba(23, 23, 23, 1)",
|
|
34
|
-
primaryForeground: "rgba(250, 250, 250, 1)",
|
|
35
|
-
primaryHover: "rgba(46, 46, 46, 1)",
|
|
36
|
-
secondary: "rgba(245, 245, 245, 1)",
|
|
37
|
-
secondaryForeground: "rgba(23, 23, 23, 1)",
|
|
38
|
-
secondaryHover: "rgba(247, 247, 247, 1)",
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const darkColors: ThemeColors = {
|
|
42
|
-
accent: "rgba(64, 64, 64, 1)",
|
|
43
|
-
accentForeground: "rgba(250, 250, 250, 1)",
|
|
44
|
-
background: "rgba(10, 10, 10, 1)",
|
|
45
|
-
border: "rgba(255, 255, 255, 0.1)",
|
|
46
|
-
destructive: "rgba(248, 113, 113, 1)",
|
|
47
|
-
destructiveForeground: "rgba(255, 255, 255, 1)",
|
|
48
|
-
destructiveHover: "rgba(224, 102, 102, 1)",
|
|
49
|
-
foreground: "rgba(250, 250, 250, 1)",
|
|
50
|
-
input: "rgba(255, 255, 255, 0.15)",
|
|
51
|
-
mutedForeground: "rgba(163, 163, 163, 1)",
|
|
52
|
-
primary: "rgba(229, 229, 229, 1)",
|
|
53
|
-
primaryForeground: "rgba(23, 23, 23, 1)",
|
|
54
|
-
primaryHover: "rgba(207, 207, 207, 1)",
|
|
55
|
-
secondary: "rgba(38, 38, 38, 1)",
|
|
56
|
-
secondaryForeground: "rgba(250, 250, 250, 1)",
|
|
57
|
-
secondaryHover: "rgba(33, 33, 33, 1)",
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export function useThemeColors(): ThemeColors {
|
|
61
|
-
const scheme = useColorScheme();
|
|
62
|
-
return scheme === "dark" ? darkColors : lightColors;
|
|
63
|
-
}
|