Skip to content

Commit

Permalink
fix: add and example reference
Browse files Browse the repository at this point in the history
  • Loading branch information
panvourtsis committed Aug 13, 2022
1 parent 2e42ab1 commit bb56ae2
Show file tree
Hide file tree
Showing 20 changed files with 479 additions and 9 deletions.
32 changes: 32 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Example

The module is installed locally. Therefore in order to run it without a problem is being in the package.json under scripts with the name `cli`

## Run

```
yarn run cli <then here all the commands explained in the cli README.md>
```

## Convert

In order to fetch all json contents i run the following. Then i get a new directory under `converted` named `json` with all the global properties
because i expanded the global.

```
yarn run cli parseFigmaTokens ./data/figma-tokens.json ./converted/json/ --expand global
```

## To code

The you can see with the below how i can convert the json source files i made to code with the following

```
yarn run cli parseJsonToCode ./converted/json/ ./theme/constants/
```

## Final use

Then you can use files in your theme to link those constants and have typed results.

Check theme/index.ts for more information on how.
78 changes: 78 additions & 0 deletions example/converted/json/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"sizing": {
"0": {
"value": "0px",
"type": "sizing"
},
"1": {
"value": "4px",
"type": "sizing"
},
"2": {
"value": "8px",
"type": "sizing"
}
},
"lineHeight": {
"1": {
"value": "14",
"type": "lineHeights",
"description": "For form field labels only"
},
"2": {
"value": "16",
"type": "lineHeights",
"description": "For input fields only (Form Fields & Tables)"
},
"3": {
"value": "18px",
"type": "lineHeights"
},
"4": {
"value": "20",
"type": "lineHeights"
}
},
"fontWeight": {
"regular": {
"value": "Regular",
"type": "fontWeights"
},
"medium": {
"value": "Medium",
"type": "fontWeights"
},
"bold": {
"value": "Bold",
"type": "fontWeights"
}
},
"fontSize": {
"1": {
"value": "12",
"type": "fontSizes"
},
"2": {
"value": "13",
"type": "fontSizes"
},
"3": {
"value": "14",
"type": "fontSizes"
}
},
"spacing": {
"0": {
"value": "0px",
"type": "spacing"
},
"1": {
"value": "2px",
"type": "spacing"
},
"2": {
"value": "4px",
"type": "spacing"
}
}
}
14 changes: 14 additions & 0 deletions example/converted/json/global/fontSize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"1": {
"value": "12",
"type": "fontSizes"
},
"2": {
"value": "13",
"type": "fontSizes"
},
"3": {
"value": "14",
"type": "fontSizes"
}
}
14 changes: 14 additions & 0 deletions example/converted/json/global/fontWeight.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"regular": {
"value": "Regular",
"type": "fontWeights"
},
"medium": {
"value": "Medium",
"type": "fontWeights"
},
"bold": {
"value": "Bold",
"type": "fontWeights"
}
}
20 changes: 20 additions & 0 deletions example/converted/json/global/lineHeight.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"1": {
"value": "14",
"type": "lineHeights",
"description": "For form field labels only"
},
"2": {
"value": "16",
"type": "lineHeights",
"description": "For input fields only (Form Fields & Tables)"
},
"3": {
"value": "18px",
"type": "lineHeights"
},
"4": {
"value": "20",
"type": "lineHeights"
}
}
14 changes: 14 additions & 0 deletions example/converted/json/global/sizing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"0": {
"value": "0px",
"type": "sizing"
},
"1": {
"value": "4px",
"type": "sizing"
},
"2": {
"value": "8px",
"type": "sizing"
}
}
14 changes: 14 additions & 0 deletions example/converted/json/global/spacing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"0": {
"value": "0px",
"type": "spacing"
},
"1": {
"value": "2px",
"type": "spacing"
},
"2": {
"value": "4px",
"type": "spacing"
}
}
78 changes: 78 additions & 0 deletions example/data/figma-tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"global": {
"sizing": {
"0": {
"value": "0px",
"type": "sizing"
},
"1": {
"value": "4px",
"type": "sizing"
},
"2": {
"value": "8px",
"type": "sizing"
}
},
"lineHeight": {
"1": {
"value": "14",
"type": "lineHeights"
},
"2": {
"value": "16",
"type": "lineHeights"
},
"3": {
"value": "18px",
"type": "lineHeights"
},
"4": {
"value": "20",
"type": "lineHeights"
}
},
"fontWeight": {
"regular": {
"value": "Regular",
"type": "fontWeights"
},
"medium": {
"value": "Medium",
"type": "fontWeights"
},
"bold": {
"value": "Bold",
"type": "fontWeights"
}
},
"fontSize": {
"1": {
"value": "12",
"type": "fontSizes"
},
"2": {
"value": "13",
"type": "fontSizes"
},
"3": {
"value": "14",
"type": "fontSizes"
}
},
"spacing": {
"0": {
"value": "0px",
"type": "spacing"
},
"1": {
"value": "2px",
"type": "spacing"
},
"2": {
"value": "4px",
"type": "spacing"
}
}
}
}
4 changes: 2 additions & 2 deletions example/node_modules/.yarn-integrity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/node_modules/figma-tokens-converter-cli/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"figma-tokens-converter-cli": "^0.0.0"
"figma-tokens-converter-cli": "^1.1.0"
},
"scripts": {
"cli": "figma-tokens-converter-cli"
}
}
16 changes: 16 additions & 0 deletions example/theme/constants/fontSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fontSize = {
'1': {
value: '12',
type: 'fontSizes',
},
'2': {
value: '13',
type: 'fontSizes',
},
'3': {
value: '14',
type: 'fontSizes',
},
} as const;

export default fontSize;
16 changes: 16 additions & 0 deletions example/theme/constants/fontWeight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fontWeight = {
regular: {
value: 'Regular',
type: 'fontWeights',
},
medium: {
value: 'Medium',
type: 'fontWeights',
},
bold: {
value: 'Bold',
type: 'fontWeights',
},
} as const;

export default fontWeight;
Loading

0 comments on commit bb56ae2

Please sign in to comment.