@catchdrift/cli 0.1.20 → 0.1.21
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 +1 -1
- package/src/commands/init.mjs +3 -0
- package/src/lib/writers.mjs +27 -1
package/package.json
CHANGED
package/src/commands/init.mjs
CHANGED
|
@@ -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 ─────────────────────────────────────────────
|
package/src/lib/writers.mjs
CHANGED
|
@@ -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,15 @@ export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFiles,
|
|
|
38
39
|
figmaFilesBlock = ` figmaFiles: [\n${entries}\n ],`
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
// Figma token — read from env var at runtime so it's never committed to git
|
|
43
|
+
let figmaTokenLine = null
|
|
44
|
+
if (hasFigma) {
|
|
45
|
+
const envExpr = framework === 'nextjs'
|
|
46
|
+
? `process.env.NEXT_PUBLIC_FIGMA_TOKEN`
|
|
47
|
+
: `import.meta.env.VITE_FIGMA_TOKEN`
|
|
48
|
+
figmaTokenLine = ` figmaToken: ${envExpr}, // set in .env.local — never commit your token`
|
|
49
|
+
}
|
|
50
|
+
|
|
41
51
|
const lines = [
|
|
42
52
|
`import type { DriftConfig } from '@catchdrift/overlay'`,
|
|
43
53
|
``,
|
|
@@ -45,6 +55,7 @@ export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFiles,
|
|
|
45
55
|
storybookUrl ? ` storybookUrl: '${storybookUrl}',` : null,
|
|
46
56
|
chromaticUrl ? ` chromaticUrl: '${chromaticUrl}',` : null,
|
|
47
57
|
figmaFilesBlock,
|
|
58
|
+
figmaTokenLine,
|
|
48
59
|
` threshold: ${threshold},`,
|
|
49
60
|
dsPackagesLine,
|
|
50
61
|
` components: {`,
|
|
@@ -60,6 +71,21 @@ export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFiles,
|
|
|
60
71
|
writeFileSync(join(cwd, 'drift.config.ts'), lines, 'utf8')
|
|
61
72
|
}
|
|
62
73
|
|
|
74
|
+
export function writeEnvLocal(cwd, { figmaToken }) {
|
|
75
|
+
if (!figmaToken) return
|
|
76
|
+
const envPath = join(cwd, '.env.local')
|
|
77
|
+
const line = `VITE_FIGMA_TOKEN=${figmaToken}\nNEXT_PUBLIC_FIGMA_TOKEN=${figmaToken}\n`
|
|
78
|
+
|
|
79
|
+
if (existsSync(envPath)) {
|
|
80
|
+
const existing = readFileSync(envPath, 'utf8')
|
|
81
|
+
// Don't duplicate if already set
|
|
82
|
+
if (existing.includes('FIGMA_TOKEN=')) return
|
|
83
|
+
writeFileSync(envPath, existing.trimEnd() + '\n' + line, 'utf8')
|
|
84
|
+
} else {
|
|
85
|
+
writeFileSync(envPath, `# Drift — Figma token (auto-generated by npx catchdrift init)\n${line}`, 'utf8')
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
63
89
|
// ── AI rules files ────────────────────────────────────────────────────────────
|
|
64
90
|
|
|
65
91
|
const COMPONENT_TABLE_START = '<!-- drift:components-start -->'
|