@figma-vars/hooks 3.0.0-beta.1 → 3.1.0
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 +417 -173
- package/dist/api/fetcher.d.ts +32 -1
- package/dist/api/fetcher.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/mutator.d.ts +36 -9
- package/dist/api/mutator.d.ts.map +1 -1
- package/dist/constants/index.d.ts +2 -28
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/contexts/FigmaTokenContext.d.ts.map +1 -1
- package/dist/contexts/FigmaVarsProvider.d.ts +3 -1
- package/dist/contexts/FigmaVarsProvider.d.ts.map +1 -1
- package/dist/contexts/index.d.ts +1 -1
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/contexts/useFigmaTokenContext.d.ts.map +1 -1
- package/dist/core/index.d.cts +8 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core.cjs +1 -0
- package/dist/core.d.cts +2 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.mjs +20 -0
- package/dist/hooks/index.d.ts +64 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useBulkUpdateVariables.d.ts.map +1 -1
- package/dist/hooks/useCollectionById.d.ts +31 -0
- package/dist/hooks/useCollectionById.d.ts.map +1 -0
- package/dist/hooks/useCreateVariable.d.ts.map +1 -1
- package/dist/hooks/useDeleteVariable.d.ts.map +1 -1
- package/dist/hooks/useFigmaToken.d.ts.map +1 -1
- package/dist/hooks/useInvalidateVariables.d.ts +34 -0
- package/dist/hooks/useInvalidateVariables.d.ts.map +1 -0
- package/dist/hooks/useModesByCollection.d.ts +34 -0
- package/dist/hooks/useModesByCollection.d.ts.map +1 -0
- package/dist/hooks/usePublishedVariables.d.ts +42 -0
- package/dist/hooks/usePublishedVariables.d.ts.map +1 -0
- package/dist/hooks/useUpdateVariable.d.ts.map +1 -1
- package/dist/hooks/useVariableById.d.ts +31 -0
- package/dist/hooks/useVariableById.d.ts.map +1 -0
- package/dist/hooks/useVariableCollections.d.ts.map +1 -1
- package/dist/hooks/useVariableModes.d.ts.map +1 -1
- package/dist/hooks/useVariables.d.ts +3 -1
- package/dist/hooks/useVariables.d.ts.map +1 -1
- package/dist/index-5ZyKWuYv.cjs +1 -0
- package/dist/index-ClHLYVvu.js +142 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +319 -163
- package/dist/types/contexts.d.ts +30 -3
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/figma.d.ts +64 -3
- package/dist/types/figma.d.ts.map +1 -1
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/mutations.d.ts +18 -4
- package/dist/types/mutations.d.ts.map +1 -1
- package/dist/utils/errorHelpers.d.ts +142 -0
- package/dist/utils/errorHelpers.d.ts.map +1 -0
- package/dist/utils/filterVariables.d.ts.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/swrKeys.d.ts +24 -0
- package/dist/utils/swrKeys.d.ts.map +1 -0
- package/dist/utils/typeGuards.d.ts +50 -0
- package/dist/utils/typeGuards.d.ts.map +1 -0
- package/package.json +75 -31
- package/scripts/export-variables.mjs +101 -0
- package/dist/index.d.mts +0 -2
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs/promises'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
|
|
5
|
+
const FIGMA_TOKEN = process.env.FIGMA_TOKEN || process.env.FIGMA_PAT
|
|
6
|
+
|
|
7
|
+
function parseArgs() {
|
|
8
|
+
const args = process.argv.slice(2)
|
|
9
|
+
const opts = {
|
|
10
|
+
fileKey: process.env.FIGMA_FILE_KEY,
|
|
11
|
+
out: 'data/figma-variables.json',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Show help
|
|
15
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
16
|
+
console.log(`
|
|
17
|
+
Export Figma Variables to JSON
|
|
18
|
+
|
|
19
|
+
Usage:
|
|
20
|
+
figma-vars-export --file-key <FILE_KEY> --out <OUTPUT_PATH>
|
|
21
|
+
figma-vars-export --file-key <FILE_KEY> [--out <OUTPUT_PATH>]
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
--file-key, --fileKey Figma file key (required, or set FIGMA_FILE_KEY env var)
|
|
25
|
+
--out Output file path (default: data/figma-variables.json)
|
|
26
|
+
--help, -h Show this help message
|
|
27
|
+
|
|
28
|
+
Environment Variables:
|
|
29
|
+
FIGMA_TOKEN or FIGMA_PAT Figma Personal Access Token (required)
|
|
30
|
+
FIGMA_FILE_KEY Figma file key (optional, can use --file-key instead)
|
|
31
|
+
|
|
32
|
+
Examples:
|
|
33
|
+
# Using npx (no install needed)
|
|
34
|
+
FIGMA_TOKEN=xxx npx figma-vars-export --file-key abc123 --out ./variables.json
|
|
35
|
+
|
|
36
|
+
# After installing the package
|
|
37
|
+
FIGMA_TOKEN=xxx figma-vars-export --file-key abc123 --out ./variables.json
|
|
38
|
+
|
|
39
|
+
# Using environment variables
|
|
40
|
+
export FIGMA_TOKEN=xxx
|
|
41
|
+
export FIGMA_FILE_KEY=abc123
|
|
42
|
+
figma-vars-export --out ./variables.json
|
|
43
|
+
|
|
44
|
+
Note: Requires Figma Enterprise account for live API access.
|
|
45
|
+
`)
|
|
46
|
+
process.exit(0)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
50
|
+
const arg = args[i]
|
|
51
|
+
if (arg === '--file-key' || arg === '--fileKey') {
|
|
52
|
+
opts.fileKey = args[i + 1]
|
|
53
|
+
i += 1
|
|
54
|
+
} else if (arg === '--out') {
|
|
55
|
+
opts.out = args[i + 1]
|
|
56
|
+
i += 1
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return opts
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function main() {
|
|
63
|
+
const { fileKey, out } = parseArgs()
|
|
64
|
+
if (!FIGMA_TOKEN) {
|
|
65
|
+
console.error('FIGMA_TOKEN (or FIGMA_PAT) is required')
|
|
66
|
+
process.exit(1)
|
|
67
|
+
}
|
|
68
|
+
if (!fileKey) {
|
|
69
|
+
console.error('--file-key or FIGMA_FILE_KEY is required')
|
|
70
|
+
process.exit(1)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const url = `https://api.figma.com/v1/files/${fileKey}/variables/local`
|
|
74
|
+
const res = await fetch(url, {
|
|
75
|
+
headers: {
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
'X-Figma-Token': FIGMA_TOKEN,
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
if (!res.ok) {
|
|
82
|
+
const text = await res.text()
|
|
83
|
+
console.error(`Request failed: ${res.status} ${res.statusText}`)
|
|
84
|
+
console.error(text)
|
|
85
|
+
process.exit(1)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const json = await res.json()
|
|
89
|
+
const outputPath = path.resolve(out)
|
|
90
|
+
await fs.mkdir(path.dirname(outputPath), { recursive: true })
|
|
91
|
+
await fs.writeFile(outputPath, JSON.stringify(json, null, 2), 'utf8')
|
|
92
|
+
console.log(`Saved variables to ${outputPath}`)
|
|
93
|
+
if (json?.meta?.variables) {
|
|
94
|
+
console.log(`Variables count: ${Object.keys(json.meta.variables).length}`)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
main().catch(err => {
|
|
99
|
+
console.error(err)
|
|
100
|
+
process.exit(1)
|
|
101
|
+
})
|
package/dist/index.d.mts
DELETED