@catchdrift/cli 0.1.20 → 0.1.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catchdrift/cli",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "CLI for Drift — install, check, and manage design system coverage for any React app.",
5
5
  "keywords": [
6
6
  "design-system",
@@ -31,6 +31,7 @@ import {
31
31
  } from '../lib/storybook.mjs'
32
32
  import {
33
33
  writeDriftConfig,
34
+ writeEnvLocal,
34
35
  writeAIRulesFiles,
35
36
  writeClaudeSkills,
36
37
  patchAppEntry,
@@ -339,7 +340,9 @@ export async function init(argv) {
339
340
  dsPackages,
340
341
  threshold: Number(threshold) || 80,
341
342
  components,
343
+ framework,
342
344
  })
345
+ if (figmaToken) writeEnvLocal(cwd, { figmaToken })
343
346
  spinner.stop('drift.config.ts written')
344
347
 
345
348
  // ── Step 7: Write AI rules files ─────────────────────────────────────────────
@@ -13,7 +13,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
13
13
 
14
14
  // ── drift.config.ts ───────────────────────────────────────────────────────────
15
15
 
16
- export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFiles, dsPackages, threshold, components }) {
16
+ export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFiles, dsPackages, threshold, components, framework }) {
17
17
  const registry = buildComponentRegistry(components)
18
18
 
19
19
  const dsPackagesLine = dsPackages?.length
@@ -22,6 +22,7 @@ export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFiles,
22
22
 
23
23
  // Build figmaFiles block — single file gets a compact shape, multiple get an array
24
24
  let figmaFilesBlock = null
25
+ const hasFigma = figmaFiles?.length > 0
25
26
  if (figmaFiles?.length === 1) {
26
27
  const f = figmaFiles[0]
27
28
  figmaFilesBlock = ` figmaFileKey: '${f.key}',`
@@ -38,6 +39,16 @@ export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFiles,
38
39
  figmaFilesBlock = ` figmaFiles: [\n${entries}\n ],`
39
40
  }
40
41
 
42
+ // Figma token — read from env at runtime via a Record cast to avoid TS errors
43
+ // for undeclared env vars. The actual value comes from .env.local (gitignored).
44
+ let figmaTokenLine = null
45
+ if (hasFigma) {
46
+ const envExpr = framework === 'nextjs'
47
+ ? `(process.env as Record<string,string|undefined>)['NEXT_PUBLIC_FIGMA_TOKEN']`
48
+ : `(import.meta.env as Record<string,string|undefined>)['VITE_FIGMA_TOKEN']`
49
+ figmaTokenLine = ` figmaToken: ${envExpr}, // set VITE_FIGMA_TOKEN in .env.local — never commit your token`
50
+ }
51
+
41
52
  const lines = [
42
53
  `import type { DriftConfig } from '@catchdrift/overlay'`,
43
54
  ``,
@@ -45,6 +56,7 @@ export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFiles,
45
56
  storybookUrl ? ` storybookUrl: '${storybookUrl}',` : null,
46
57
  chromaticUrl ? ` chromaticUrl: '${chromaticUrl}',` : null,
47
58
  figmaFilesBlock,
59
+ figmaTokenLine,
48
60
  ` threshold: ${threshold},`,
49
61
  dsPackagesLine,
50
62
  ` components: {`,
@@ -60,6 +72,21 @@ export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFiles,
60
72
  writeFileSync(join(cwd, 'drift.config.ts'), lines, 'utf8')
61
73
  }
62
74
 
75
+ export function writeEnvLocal(cwd, { figmaToken }) {
76
+ if (!figmaToken) return
77
+ const envPath = join(cwd, '.env.local')
78
+ const line = `VITE_FIGMA_TOKEN=${figmaToken}\nNEXT_PUBLIC_FIGMA_TOKEN=${figmaToken}\n`
79
+
80
+ if (existsSync(envPath)) {
81
+ const existing = readFileSync(envPath, 'utf8')
82
+ // Don't duplicate if already set
83
+ if (existing.includes('FIGMA_TOKEN=')) return
84
+ writeFileSync(envPath, existing.trimEnd() + '\n' + line, 'utf8')
85
+ } else {
86
+ writeFileSync(envPath, `# Drift — Figma token (auto-generated by npx catchdrift init)\n${line}`, 'utf8')
87
+ }
88
+ }
89
+
63
90
  // ── AI rules files ────────────────────────────────────────────────────────────
64
91
 
65
92
  const COMPONENT_TABLE_START = '<!-- drift:components-start -->'