@@ -17,10 +17,6 @@ Get TokenScript up and running in 5 minutes. You'll install the CLI, resolve you
17173 . Try the interactive REPL
18184 . Write your first script
1919
20- ** Total time:** ~ 5 minutes
21-
22- ---
23-
2420## Step 1: Install TokenScript
2521
2622Install the CLI globally with npm:
@@ -35,72 +31,74 @@ Verify installation:
3531tokenscript --version
3632```
3733
38- :::tip Alternative: npx
39- Don't want to install globally? Use ` npx tokenscript ` instead of ` tokenscript ` in all commands.
40- :::
34+ Or via ` npx `
4135
42- ---
36+ ``` bash
37+ npx @tokens-studio/tokenscript-interpreter
38+ ```
4339
4440## Step 2: Resolve Your First Tokens
4541
4642Create a simple token file called ` tokens.json ` :
4743
4844<TokenScriptCodeBlock mode =" json " showResult ={false} >
4945{`{
50- "spacing": {
51- "base": {
52- "$type": "dimension",
53- "$value": "8px"
54- },
55- "large": {
56- "$type": "dimension",
57- "$value": "{spacing.base} * 2"
58- },
59- "xlarge": {
60- "$type": "dimension",
61- "$value": "{spacing.large} * 1.5"
62- }
46+ "spacing": {
47+ "base": {
48+ "$type": "dimension",
49+ "$value": "8px"
50+ },
51+ "large": {
52+ "$type": "dimension",
53+ "$value": "{spacing.base} * 2"
6354 },
64- "colors": {
65- "primary": {
66- "$type": "color",
67- "$value": "#0066FF"
68- },
69- "primaryLight": {
70- "$type": "color",
71- "$value": "lighten({colors.primary}, 20)"
72- }
55+ "xlarge": {
56+ "$type": "dimension",
57+ "$value": "{spacing.large} * 1.5"
7358 }
74- }`}
59+ },
60+ "colors": {
61+ "primary": {
62+ "$type": "color",
63+ "$value": "#0066FF"
64+ },
65+ "darkPrimary": {
66+ "$type": "color",
67+ "$value": "invert({colors.primary}).to.hex()"
68+ }
69+ }
70+ }
71+ `}
7572</TokenScriptCodeBlock >
7673
7774Now resolve all the references and expressions:
7875
7976``` bash
80- tokenscript parse_json --json tokens.json --output tokens-resolved.json
77+ tokenscript parse_json -- --json tokens.json \
78+ --schema " https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/schema/srgb-color/0.1.0/" \
79+ --schema " https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/schema/invert/0/"
8180```
8281
8382** That's it!** Check ` tokens-resolved.json ` :
8483
8584<TokenScriptCodeBlock mode =" json " showResult ={false} >
8685{`{
8786 "spacing.base": "8px",
88- "spacing.large": "16px", // Computed: 8px * 2
89- "spacing.xlarge": "24px", // Computed: 16px * 1.5
87+ "spacing.large": "16px",
88+ "spacing.xlarge": "24px",
9089 "colors.primary": "#0066FF",
91- "colors.primaryLight ": "#4D94FF" // Computed: lightened version
90+ "colors.darkPrimary ": "#ff9900"
9291}`}
9392</TokenScriptCodeBlock >
9493
9594:::info What Just Happened?
96- TokenScript:
95+
97961 . Resolved all ` {references} `
98- 2 . Evaluated all expressions ( ` * 2 ` , ` * 1.5 ` )
99- 3 . Executed functions ( ` lighten() ` )
100- 4 . Output ready-to-use values
97+ 2 . Evaluated all expressions ` * 2 ` , ` * 1.5 `
98+ 3 . Executed functions ` invert ` and color conversions ` to.hex ` fetched from the schemas
99+ 4 . Printed output tokens
101100:::
102101
103- ---
104102
105103## Step 3: Try the Interactive REPL
106104
@@ -113,15 +111,10 @@ tokenscript interactive
113111Now try some expressions:
114112
115113<TokenScriptCodeBlock mode =" script " >
116- {`variable base: NumberWithUnit = 8px;
117- base * 2`}
118- </TokenScriptCodeBlock >
119-
120- <TokenScriptCodeBlock mode =" script " >
121- {`variable color: Color = #0066FF;
122- lighten(color, 20)`}
114+ {` 16px * 2 ` }
123115</TokenScriptCodeBlock >
124116
117+ For a more advanced repl visit the [ web version of the repl] ( https://repl.tokenscript.dev.gcp.tokens.studio/ ) .
125118
126119## Step 4: Write Your First Script
127120
@@ -174,149 +167,3 @@ Run it:
174167``` bash
175168npx tsx generate-spacing.ts
176169```
177-
178- ** Congratulations!** 🎉 You just:
179- - Installed TokenScript
180- - Resolved design tokens
181- - Tried the interactive REPL
182- - Wrote and executed TokenScript code
183-
184- ---
185-
186- ## What's Next?
187-
188- ### Learn More
189-
190- ** Want to understand the language better?**
191- → [ Language Tutorial] ( /language/tutorial ) - Step-by-step guide to TokenScript syntax
192-
193- ** Need more CLI commands?**
194- → [ CLI Reference] ( /cli/overview ) - All commands and workflows
195-
196- ** Ready to integrate in your project?**
197- → [ API & Integration] ( /api/getting-started ) - Embed the interpreter
198-
199- ** Want to see real examples?**
200- → [ Language Cookbook] ( /language/cookbook ) - Common patterns and recipes
201-
202- ### Common Next Steps
203-
204- #### 1. Resolve Your Own Tokens
205-
206- Replace ` tokens.json ` with your actual JSON token file:
207-
208- ``` bash
209- tokenscript parse_json --json ./your-tokens.json --output ./dist/resolved.json
210- ```
211-
212- #### 2. Add to Your Build Pipeline
213-
214- ``` json
215- // package.json
216- {
217- "scripts" : {
218- "tokens" : " tokenscript parse_json --json tokens.json --output dist/tokens.json" ,
219- "build" : " npm run tokens && vite build"
220- }
221- }
222- ```
223-
224- #### 3. Generate Theme Variations
225-
226- Use permutations for multi-theme support:
227-
228- ``` bash
229- tokenscript permutate_tokenset \
230- --tokenset tokens.zip \
231- --permutate-on theme \
232- --permutate-to colors \
233- --output themes.json
234- ```
235-
236- #### 4. Integrate with Your Tools
237-
238- - ** Webpack/Vite** : Create a plugin to process tokens at build time
239- - ** Figma/Sketch** : Build a plugin to sync tokens
240- - ** CI/CD** : Validate tokens in your pipeline
241- - ** Documentation** : Auto-generate token docs
242-
243- ## Quick Reference
244-
245- ### Common Commands
246-
247- ``` bash
248- # Resolve tokens from JSON
249- tokenscript parse_json --json tokens.json --output output.json
250-
251- # Interactive REPL
252- tokenscript interactive
253-
254- # Process token set (ZIP)
255- tokenscript parse_tokenset --tokenset tokens.zip --output output.json
256-
257- # Run compliance tests
258- tokenscript evaluate_standard_compliance --test-dir ./tests
259- ```
260-
261- ### Common TokenScript Patterns
262-
263- <TokenScriptCodeBlock mode =" script " showResult ={false} >
264- {`// Variables with types
265- variable spacing: NumberWithUnit = 8px;
266- variable scale: Number = 1.5;
267-
268- // Expressions
269- variable large: NumberWithUnit = spacing * scale;
270-
271- // Functions
272- variable lighter: Color = lighten(#0066FF, 20);
273- variable rounded: Number = round(3.14159, 2);
274-
275- // Lists
276- variable colors: List = #FF0000, #00FF00, #0000FF;
277-
278- // Control flow
279- variable condition: Boolean = true;
280- if (condition) [
281- return "yes";
282- ] else [
283- return "no";
284- ] `}
285- </TokenScriptCodeBlock >
286-
287- ---
288-
289- ## Success! What Now?
290-
291- You've got TokenScript working! Here are your next steps based on your goals:
292-
293- <div class =" card-grid " >
294- <div class =" card " >
295- <h3>🎨 I want to write token scripts</h3>
296- <p>Learn the language and write your own transformations</p>
297- <a href="/language/tutorial">Start Language Tutorial →</a>
298- </div >
299-
300- <div class =" card " >
301- <h3>⚙️ I want to use the CLI</h3>
302- <p>Master all CLI commands and workflows</p>
303- <a href="/cli/overview">Explore CLI →</a>
304- </div >
305-
306- <div class =" card " >
307- <h3>🔧 I want to integrate in my app</h3>
308- <p>Embed the interpreter programmatically</p>
309- <a href="/api/getting-started">API Documentation →</a>
310- </div >
311-
312- <div class =" card " >
313- <h3>🧩 I want to extend TokenScript</h3>
314- <p>Add custom color spaces, units, or functions</p>
315- <a href="/extensions/overview">Extension Guide →</a>
316- </div >
317- </div >
318-
319- ---
320-
321- ** You're all set!** Happy token scripting! 🚀
322-
0 commit comments