@catchdrift/cli 0.1.4 → 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/package.json +1 -1
- package/src/commands/init.mjs +42 -1
- package/src/lib/writers.mjs +2 -1
package/package.json
CHANGED
package/src/commands/init.mjs
CHANGED
|
@@ -103,7 +103,7 @@ export async function init(argv) {
|
|
|
103
103
|
const sources = Array.isArray(dsSources) ? dsSources : []
|
|
104
104
|
|
|
105
105
|
// ── Step 3a: Figma ───────────────────────────────────────────────────────────
|
|
106
|
-
let figmaFileKey
|
|
106
|
+
let figmaFileKey, figmaToken, figmaWIPPages
|
|
107
107
|
if (sources.includes('figma')) {
|
|
108
108
|
figmaFileKey = await p.text({
|
|
109
109
|
message: 'Figma file key',
|
|
@@ -112,6 +112,31 @@ export async function init(argv) {
|
|
|
112
112
|
})
|
|
113
113
|
if (p.isCancel(figmaFileKey)) { p.cancel('Setup cancelled.'); process.exit(EXIT_CANCELED) }
|
|
114
114
|
figmaFileKey = figmaFileKey?.trim() || undefined
|
|
115
|
+
|
|
116
|
+
figmaToken = await p.text({
|
|
117
|
+
message: 'Figma personal access token',
|
|
118
|
+
placeholder: 'figd_... (figma.com → Profile → Settings → Security → Personal access tokens)',
|
|
119
|
+
hint: 'Used to fetch your real page list. Store in FIGMA_API_TOKEN env var — not committed to git.',
|
|
120
|
+
})
|
|
121
|
+
if (p.isCancel(figmaToken)) { p.cancel('Setup cancelled.'); process.exit(EXIT_CANCELED) }
|
|
122
|
+
figmaToken = figmaToken?.trim() || undefined
|
|
123
|
+
|
|
124
|
+
// Fetch actual pages from Figma so the user picks from real names
|
|
125
|
+
if (figmaToken && figmaFileKey) {
|
|
126
|
+
spinner.start('Fetching pages from Figma...')
|
|
127
|
+
const pages = await fetchFigmaPages(figmaFileKey, figmaToken)
|
|
128
|
+
spinner.stop(pages ? `Found ${pages.length} pages` : 'Could not reach Figma — skipping page selection')
|
|
129
|
+
|
|
130
|
+
if (pages?.length) {
|
|
131
|
+
const selected = await p.multiselect({
|
|
132
|
+
message: 'Which pages hold in-progress / not-yet-ready components? (drafts — won\'t be added to registry)',
|
|
133
|
+
options: pages.map(name => ({ value: name, label: name })),
|
|
134
|
+
required: false,
|
|
135
|
+
})
|
|
136
|
+
if (p.isCancel(selected)) { p.cancel('Setup cancelled.'); process.exit(EXIT_CANCELED) }
|
|
137
|
+
figmaWIPPages = Array.isArray(selected) && selected.length ? selected : undefined
|
|
138
|
+
}
|
|
139
|
+
}
|
|
115
140
|
}
|
|
116
141
|
|
|
117
142
|
// ── Step 3b: Storybook ───────────────────────────────────────────────────────
|
|
@@ -194,6 +219,7 @@ export async function init(argv) {
|
|
|
194
219
|
storybookUrl: storybookUrl || (storybook.found ? storybook.url : undefined),
|
|
195
220
|
chromaticUrl,
|
|
196
221
|
figmaFileKey,
|
|
222
|
+
figmaWIPPages,
|
|
197
223
|
dsPackages,
|
|
198
224
|
threshold: Number(threshold) || 80,
|
|
199
225
|
components,
|
|
@@ -283,3 +309,18 @@ ${pc.dim('Docs: https://catchdrift.ai · Issues: https://github.com/dyoon92/de
|
|
|
283
309
|
console.log('')
|
|
284
310
|
}
|
|
285
311
|
}
|
|
312
|
+
|
|
313
|
+
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
314
|
+
|
|
315
|
+
async function fetchFigmaPages(fileKey, token) {
|
|
316
|
+
try {
|
|
317
|
+
const res = await fetch(`https://api.figma.com/v1/files/${fileKey}?depth=1`, {
|
|
318
|
+
headers: { 'X-Figma-Token': token },
|
|
319
|
+
})
|
|
320
|
+
if (!res.ok) return null
|
|
321
|
+
const data = await res.json()
|
|
322
|
+
return data.document?.children?.map(page => page.name) ?? null
|
|
323
|
+
} catch {
|
|
324
|
+
return null
|
|
325
|
+
}
|
|
326
|
+
}
|
package/src/lib/writers.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { findAppEntry } from './detect.mjs'
|
|
|
10
10
|
|
|
11
11
|
// ── drift.config.ts ───────────────────────────────────────────────────────────
|
|
12
12
|
|
|
13
|
-
export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFileKey, dsPackages, threshold, components }) {
|
|
13
|
+
export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFileKey, figmaWIPPages, dsPackages, threshold, components }) {
|
|
14
14
|
const registry = buildComponentRegistry(components)
|
|
15
15
|
|
|
16
16
|
const dsPackagesLine = dsPackages?.length
|
|
@@ -24,6 +24,7 @@ export function writeDriftConfig(cwd, { storybookUrl, chromaticUrl, figmaFileKey
|
|
|
24
24
|
storybookUrl ? ` storybookUrl: '${storybookUrl}',` : null,
|
|
25
25
|
chromaticUrl ? ` chromaticUrl: '${chromaticUrl}',` : null,
|
|
26
26
|
figmaFileKey ? ` figmaFileKey: '${figmaFileKey}',` : null,
|
|
27
|
+
figmaWIPPages?.length ? ` figmaWIPPages: [${figmaWIPPages.map(p => `'${p}'`).join(', ')}], // components on these pages are drafts — not added to registry` : null,
|
|
27
28
|
` threshold: ${threshold},`,
|
|
28
29
|
dsPackagesLine,
|
|
29
30
|
` components: {`,
|