7onic 0.1.5 → 0.1.6

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/dist/index.js CHANGED
@@ -1296,10 +1296,26 @@ async function init(args) {
1296
1296
  } catch {
1297
1297
  }
1298
1298
  }
1299
+ const viteConfigPath = import_node_fs4.default.existsSync(import_node_path4.default.join(projectRoot, "vite.config.ts")) ? import_node_path4.default.join(projectRoot, "vite.config.ts") : import_node_fs4.default.existsSync(import_node_path4.default.join(projectRoot, "vite.config.js")) ? import_node_path4.default.join(projectRoot, "vite.config.js") : null;
1300
+ const isViteProject = import_node_fs4.default.existsSync(import_node_path4.default.join(projectRoot, "tsconfig.app.json")) && viteConfigPath !== null;
1301
+ let needsTypesNode = false;
1299
1302
  if (!hasPathAlias) {
1300
- O2.warn(
1301
- 'No @/ path alias detected in tsconfig.\n Components use @/lib/utils \u2014 make sure your project has path aliases configured.\n Next.js: automatic (no action needed)\n Vite: add to both files:\n\n // tsconfig.app.json \u2192 "compilerOptions.paths"\n { "@/*": ["./src/*"] }\n\n // vite.config.ts \u2192 "resolve.alias"\n { "@": path.resolve(__dirname, "./src") }'
1302
- );
1303
+ if (isViteProject) {
1304
+ const tscPatch = patchTsconfigApp(import_node_path4.default.join(projectRoot, "tsconfig.app.json"));
1305
+ const vitePatch = patchViteConfig(viteConfigPath);
1306
+ if (vitePatch) needsTypesNode = true;
1307
+ if (tscPatch || vitePatch) {
1308
+ O2.success("Configured @/ path alias in tsconfig.app.json and vite.config.ts");
1309
+ } else {
1310
+ O2.warn(
1311
+ 'Could not auto-configure @/ path alias. Add manually:\n tsconfig.app.json \u2192 compilerOptions.paths: { "@/*": ["./src/*"] }\n vite.config.ts \u2192 resolve: { alias: { "@": path.resolve(__dirname, "./src") } }'
1312
+ );
1313
+ }
1314
+ } else {
1315
+ O2.warn(
1316
+ "No @/ path alias detected.\n Next.js: automatic (no action needed)\n Other: configure compilerOptions.paths in tsconfig.json"
1317
+ );
1318
+ }
1303
1319
  }
1304
1320
  try {
1305
1321
  const pkgJson = JSON.parse(import_node_fs4.default.readFileSync(import_node_path4.default.join(projectRoot, "package.json"), "utf-8"));
@@ -1363,6 +1379,9 @@ async function init(args) {
1363
1379
  s.start(`Installing dependencies (${pm})...`);
1364
1380
  try {
1365
1381
  installDeps(baseDeps, { cwd: projectRoot, pm });
1382
+ if (needsTypesNode) {
1383
+ installDeps(["@types/node"], { cwd: projectRoot, pm, dev: true });
1384
+ }
1366
1385
  s.stop("Dependencies installed");
1367
1386
  } catch (err) {
1368
1387
  s.stop("Failed to install dependencies");
@@ -1456,6 +1475,48 @@ async function init(args) {
1456
1475
  O2.success("Created 7onic.json");
1457
1476
  gt("Done! Run " + import_picocolors2.default.cyan("npx 7onic add <component>") + " to add components.");
1458
1477
  }
1478
+ function patchTsconfigApp(tsconfigPath) {
1479
+ try {
1480
+ const raw = import_node_fs4.default.readFileSync(tsconfigPath, "utf-8");
1481
+ const clean = raw.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").replace(/,(\s*[}\]])/g, "$1");
1482
+ const tc = JSON.parse(clean);
1483
+ if (!tc.compilerOptions) tc.compilerOptions = {};
1484
+ const existingPaths = tc.compilerOptions.paths ?? {};
1485
+ if (existingPaths["@/*"]) return false;
1486
+ tc.compilerOptions.paths = { "@/*": ["./src/*"], ...existingPaths };
1487
+ import_node_fs4.default.writeFileSync(tsconfigPath, JSON.stringify(tc, null, 2), "utf-8");
1488
+ return true;
1489
+ } catch {
1490
+ return false;
1491
+ }
1492
+ }
1493
+ function patchViteConfig(viteConfigPath) {
1494
+ try {
1495
+ let content = import_node_fs4.default.readFileSync(viteConfigPath, "utf-8");
1496
+ if (content.includes("'@'") || content.includes('"@"') || content.includes("'@/*'") || content.includes('"@/*"') || content.includes("resolve:")) return false;
1497
+ if (!content.includes("import path from 'path'") && !content.includes('import path from "path"')) {
1498
+ const importMatches = [...content.matchAll(/^import .+$/gm)];
1499
+ const lastImport = importMatches.at(-1);
1500
+ if (lastImport?.index !== void 0) {
1501
+ const insertAt = lastImport.index + lastImport[0].length;
1502
+ content = content.slice(0, insertAt) + "\nimport path from 'path'" + content.slice(insertAt);
1503
+ }
1504
+ }
1505
+ const lastClose = content.lastIndexOf("\n})");
1506
+ if (lastClose === -1) return false;
1507
+ const beforeClose = content.slice(0, lastClose).trimEnd();
1508
+ const comma = beforeClose.endsWith(",") ? "" : ",";
1509
+ const resolveBlock = `${comma}
1510
+ resolve: {
1511
+ alias: { '@': path.resolve(__dirname, './src') },
1512
+ },`;
1513
+ content = content.slice(0, lastClose) + resolveBlock + content.slice(lastClose);
1514
+ import_node_fs4.default.writeFileSync(viteConfigPath, content, "utf-8");
1515
+ return true;
1516
+ } catch {
1517
+ return false;
1518
+ }
1519
+ }
1459
1520
  function resolveAliasPath(projectRoot, alias) {
1460
1521
  if (!alias.startsWith("@/")) return null;
1461
1522
  const relative = alias.slice(2);
@@ -14418,7 +14479,7 @@ function showSetupHints(names) {
14418
14479
 
14419
14480
  // cli/src/index.ts
14420
14481
  var import_picocolors4 = __toESM(require_picocolors());
14421
- var VERSION = "0.1.5";
14482
+ var VERSION = "0.1.6";
14422
14483
  var HELP = `
14423
14484
  ${import_picocolors4.default.bold("7onic")} \u2014 Add 7onic design system components to your project
14424
14485
 
package/llms.txt CHANGED
@@ -25,14 +25,15 @@ npx 7onic init --tailwind v3 --yes # Explicit v3, skip prompts
25
25
  **What it does:**
26
26
  1. Detects Tailwind version (v3: config file exists, v4: no config) — or uses `--tailwind` flag
27
27
  2. Detects package manager (npm/pnpm/yarn/bun)
28
- 3. Installs: `@7onic-ui/tokens`, `clsx`, `tailwind-merge`, `class-variance-authority`
29
- 4. Creates/updates CSS file with token imports
30
- 5. Creates `cn()` utility at configured path
31
- 6. Writes `7onic.json` config
28
+ 3. **Vite projects**: auto-configures `@/` path alias — patches `tsconfig.app.json` (JSONC-safe) and `vite.config.ts` (adds `import path` + `resolve.alias`), installs `@types/node`
29
+ 4. Installs: `@7onic-ui/tokens`, `lucide-react`, `clsx`, `tailwind-merge`, `class-variance-authority`
30
+ 5. Creates/updates CSS file with token imports (v4: auto-injects `@import "tailwindcss"` if missing)
31
+ 6. Creates `cn()` utility at configured path
32
+ 7. Writes `7onic.json` config
32
33
 
33
34
  **Requirements:**
34
35
  - TypeScript project (tsconfig.json required)
35
- - `@/` path alias configured
36
+ - `@/` path alias — auto-configured for Vite; Next.js handles this automatically
36
37
 
37
38
  ### add
38
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "7onic",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "CLI for adding 7onic design system components to your project",
5
5
  "bin": {
6
6
  "7onic": "./dist/index.js"