Skip to content

Commit

Permalink
Clean up formatting of multiline strings
Browse files Browse the repository at this point in the history
  • Loading branch information
narin committed Jun 26, 2024
1 parent c217ac9 commit 07a6d1b
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions packages/tokens/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ StyleDictionary.registerFormat({
return result
}, {})

return `export const Colors = ${JSON.stringify(sortTokensByKey(colorTokens), null, 2)};`
return `export const colors = ${JSON.stringify(sortTokensByKey(colorTokens), null, 2)};`
},
})

Expand All @@ -89,33 +89,35 @@ StyleDictionary.registerFormat({
.filter(filterDark)
.reduce(stripModeReducer, {})

return `export const themes = {
light: ${JSON.stringify(sortTokensByKey(light), null, 4)},
dark: ${JSON.stringify(sortTokensByKey(dark), null, 4)}
}`
return (
'export const themes = {\n' +
` light: ${JSON.stringify(sortTokensByKey(light), null, 4)},\n` +
` dark: ${JSON.stringify(sortTokensByKey(dark), null, 4)}\n` +
'}'
)
},
})

/** Custom format to generate index js with exports */
StyleDictionary.registerFormat({
name: 'javascript/es6/vads-module-export',
formatter: function () {
return `export { Colors } from './colors'
export { themes } from './themes'
`
return (
"export { colors } from './colors'\n" +
"export { themes } from './themes'"
)
},
})

/** Creates named type declaration for Colors. Allows for TypeScript autocomplete */
/** Creates named type declaration for colors. Allows for TypeScript autocomplete */
StyleDictionary.registerFormat({
name: 'typescript/es6-declarations/colors',
formatter: function (dictionary) {
let declaration = 'export declare const Colors: {\n'
let declaration = 'export declare const colors: {\n'
dictionary.allProperties.forEach((token) => {
declaration += ` ${token.name}: string;\n`
})

declaration += `}`
declaration += '}'
return declaration
},
})
Expand All @@ -128,14 +130,13 @@ StyleDictionary.registerFormat({
dictionary.allProperties.forEach((token) => {
declaration += ` ${stripMode(token.name)}: string;\n`
})
declaration += '}\n\n'

declaration += `}
export declare const themes: {
light: Theme;
dark: Theme;
}`

declaration +=
'export declare const themes: {\n' +
' light: Theme;\n' +
' dark: Theme;\n' +
'}'
return declaration
},
})
Expand Down

0 comments on commit 07a6d1b

Please sign in to comment.