Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TimRoe committed Nov 20, 2023
1 parent 6724969 commit 768f70b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 148 deletions.
115 changes: 7 additions & 108 deletions packages/tokens/build.js
Original file line number Diff line number Diff line change
@@ -1,136 +1,35 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const StyleDictionary = require('style-dictionary')

/**
* Creates a JSON flat file of the style dictionary.
*
* @memberof Formats
* @kind member
* @example
* ```json
* {
* "color-base-red": "#ff0000"
* }
* ```
*/
// 'json/flat': function({dictionary}) {
// return '{\n' + dictionary.allTokens.map(function(token) {
// return ` "${token.name}": ${JSON.stringify(token.value)}`;
// }).join(',\n') + '\n}' + '\n';
// },
const groupName = StyleDictionary.transformGroup['group_name']
if (groupName) {
console.log(groupName)
}

console.log(StyleDictionary.transformGroup['group_name'])
StyleDictionary.registerTransformGroup({
name: 'figma',
transforms: ['name/ti/camel', 'color/hex'],
})

/** Function to generate JSON into Design Token Community Group format (https://tr.designtokens.org/format/) */
/** Function to generate JSON in Design Token Community Group format (https://tr.designtokens.org/format/) */
StyleDictionary.registerFormat({
name: 'json/dtcg',
// type: 'value',
// matcher: function(token) {
// // this is an example of a possible filter (based on the "cti" values) to show how a "matcher" works
// return token.attributes.category === 'font' || token.attributes.category === 'margin';
// },
// console.log(dictionary.allTokens)
// const tokensObject = dictionary.allTokens.map(function (token) {
// const tokenValue = {
// $value: token.value,
// $type: token.path[0],
// }
// return `"${token.name}": ${JSON.stringify(tokenValue, undefined, 4)}`
// })
// console.log(JSON.stringify(tokensObject))
// return `{\n ${tokensObject.toString()} \n}\n`
// return (
// '{\n' +
// dictionary.allTokens
// .map(function (token) {
// const tokenValue = {
// $value: token.value,
// $type: token.path[0],
// }
// // console.log(tokenValue)
// return ` "${token.name}": ${JSON.stringify(tokenValue, undefined, 4)}`
// })
// .join(',\n') +
// '\n}' +
// '\n'
// )
formatter: function ({ dictionary }) {
const testObject = {
blue: {
$value: 'blu',
$type: 'color',
},
red: {
$value: 'red',
$type: 'color',
},
white: {
$value: 'white',
$type: 'color',
},
}

// const tokensArray = dictionary.allTokens.map(function (token) {
// const tokenArrayVal = {
// $value: token.value,
// $type: token.path[0],
// }
// return {
// $value: token.value,
// $type: token.path[0],
// }
// })

const tokensObject = dictionary.allTokens.reduce(
(previousTokens, token) => ({
...previousTokens,
[token.name]: {
$value: token.value,
$type: token.path[0], // path[0] is top level token type (e.g. 'color')
$type: token.path[0], // path[0] is top level token type (e.g. 'color'), should meet: https://tr.designtokens.org/format/#types
},
}),
{},
)

// console.log(dictionary.allTokens)
// console.log(JSON.stringify(testObject, undefined, 2))
// console.log(JSON.stringify(tokensObject, undefined, 2))
return JSON.stringify(tokensObject, undefined, 2) + `\n`
// return (
// '{\n' +
// dictionary.allTokens
// .map(function (token) {
// return ` "${token.name}": {\n "$value": ${JSON.stringify(
// token.value,
// )},\n "$type": ${JSON.stringify(token.path[0])}\n }`
// })
// .join(',\n') +
// '\n}' +
// '\n'
// )
},
})

// Works perf but messy:
// return (
// '{\n' +
// dictionary.allTokens
// .map(function (token) {
// return ` "${token.name}": {\n "$value": ${JSON.stringify(
// token.value,
// )},\n "$type": ${JSON.stringify(token.path[0])}\n }`
// })
// .join(',\n') +
// '\n}' +
// '\n'
// )

const StyleDictionaryExtended = StyleDictionary.extend(
__dirname + '/config.js',
)
const StyleDictionaryExtended = StyleDictionary.extend(__dirname + '/config.js')

StyleDictionaryExtended.buildAllPlatforms()
26 changes: 0 additions & 26 deletions packages/tokens/colorTokenTest.json

This file was deleted.

14 changes: 0 additions & 14 deletions packages/tokens/spacerTokenTest.json

This file was deleted.

0 comments on commit 768f70b

Please sign in to comment.