-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix type and breakpoints tokens
- Loading branch information
Raisa Primerova
committed
Sep 9, 2024
1 parent
12c501d
commit 5fa0855
Showing
10 changed files
with
131 additions
and
76 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import fs from 'fs'; | ||
import {decodeJSONBufferString} from './parse-utils'; | ||
const path = require('path'); | ||
|
||
const transformToRefs = (tokens: any, parsed = {}, level = '') => { | ||
const keys = Object.keys(tokens); | ||
|
||
keys.forEach(key => { | ||
const isHighestLevel = /base|brand|sys/.test(key); | ||
if (isHighestLevel) { | ||
// @ts-ignore | ||
parsed[key] = []; | ||
} | ||
|
||
if (keys.includes('value')) { | ||
// @ts-ignore | ||
parsed.push(level); | ||
return parsed; | ||
} | ||
|
||
transformToRefs( | ||
tokens[key], | ||
// @ts-ignore | ||
isHighestLevel ? parsed[key] : parsed, | ||
isHighestLevel ? '' : level ? `${level}.${key}` : key | ||
); | ||
}); | ||
|
||
return parsed; | ||
}; | ||
|
||
export const generateRefs = async (file: any) => { | ||
const refsFileName = path.resolve(__dirname, '../../packages/canvas-tokens/_refs.json'); | ||
|
||
await fs.readFile(refsFileName, async (err, data) => { | ||
const tokens = transformToRefs(file); | ||
|
||
if (err || !data) { | ||
fs.writeFile(refsFileName, JSON.stringify(tokens), () => {}); | ||
} else { | ||
// @ts-ignore | ||
const content = decodeJSONBufferString(data); | ||
fs.writeFile(refsFileName, JSON.stringify({...content, ...tokens}), () => {}); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters