Skip to content

Commit

Permalink
Remove unused formats and other cleanup (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Sep 5, 2024
1 parent d0108de commit 46a4b49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 49 deletions.
9 changes: 8 additions & 1 deletion packages/design-tokens/scripts/build-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ const darkJson = require('../src/tokens/base/colors/dark')

//build most tokens
buildPrimitives({
source: [`tokens/**/*.json`, `!tokens/**/size-*.json`],
source: [`tokens/functional/**/*.json`, `!tokens/functional/**/size-*.json`],
include: ['tokens/**/*.json'],
namespace,
outputPath,
})

buildPrimitives({
source: [`tokens/base/**/*.json`],
namespace: undefined,
outputPath,
})

buildPrimitives({
source: [`tokens/functional/size/size-fine.json`, `tokens/base/size/size.json`], //build size fine
namespace,
Expand Down
59 changes: 11 additions & 48 deletions packages/design-tokens/scripts/style-dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ StyleDictionary.registerTransformGroup({
transforms: ['name/pathToKebabCase', 'pxToRem', 'typography/css'],
})

StyleDictionary.registerTransformGroup({
name: 'scss',
transforms: ['name/pathToKebabCase', 'pxToRem', 'typography/css'],
})

// REGISTER A CUSTOM FORMAT

// wrap mobile tokens in media query
Expand Down Expand Up @@ -89,16 +84,6 @@ StyleDictionary.registerFormat({
},
})

// format docs
StyleDictionary.registerFormat({
name: 'json/docs',
formatter({dictionary}) {
const groupedTokens = groupBy(dictionary.allProperties, 'filePath')

return JSON.stringify(groupedTokens, null, 2)
},
})

/**
* Replacement format for javascript/module
*/
Expand Down Expand Up @@ -185,29 +170,6 @@ export default ${moduleName};`
},
})

/**
* @name groupBy
* @description Equivalent to lodash _.groupBy, to avoid creating another package dependency for users
* @param {Array|Object} The collection to iterate over.
* @param {Function} The iteratee to transform keys.
* @returns {Object} Returns the composed aggregate object.
*/
function groupBy(collection, iteratee = x => x) {
const current = typeof iteratee === 'function' ? iteratee : ({[iteratee]: prop}) => prop

const array = Array.isArray(collection) ? collection : Object.values(collection)

return array.reduce((acc, item) => {
const value = current(item)

acc[value] = acc[value] || []

acc[value].push(item)

return acc
}, {})
}

/**
* @name build
* @description
Expand All @@ -228,7 +190,7 @@ function groupBy(collection, iteratee = x => x) {
* })
*/
function buildPrimitives(
{source, outputPath = 'tokens-v2-private', include, platforms, namespace = 'brand'},
{source, outputPath = 'tokens-v2-private', include, platforms, namespace},
_StyleDictionary = StyleDictionary,
) {
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -274,7 +236,7 @@ function buildPrimitives(
return {
format: `css/variables`,
destination: filePath.replace(`.json`, `.css`),
filter: token => token.filePath === filePath,
filter: token => token.filePath === filePath && token.isSource,
options: {
outputReferences: true,
},
Expand All @@ -286,21 +248,21 @@ function buildPrimitives(
transformGroup: 'css',
files: [
{
filter: token => token.filePath.includes('viewport'),
filter: token => token.filePath.includes('viewport') && token.isSource,
format: 'css/customMedia',
destination: 'viewport.css',
},
],
},
scss: {
buildPath: `${outputPath}/scss/`,
transformGroup: 'scss',
transformGroup: 'css',
// map the array of token file paths to style dictionary output files
files: files.map(filePath => {
return {
format: `scss/variables`,
destination: filePath.replace(`.json`, `.scss`),
filter: token => token.filePath === filePath,
filter: token => token.filePath === filePath && token.isSource,
options: {
outputReferences: true,
},
Expand All @@ -315,7 +277,7 @@ function buildPrimitives(
return {
format: `javascript/es6`,
destination: filePath.replace(`.json`, `.js`),
filter: token => token.filePath === filePath,
filter: token => token.filePath === filePath && token.isSource,
}
}),
},
Expand All @@ -327,7 +289,7 @@ function buildPrimitives(
return {
format: `javascript/module`,
destination: filePath.replace(`.json`, `.js`),
filter: token => token.filePath === filePath,
filter: token => token.filePath === filePath && token.isSource,
}
}),
},
Expand All @@ -339,7 +301,7 @@ function buildPrimitives(
return {
format: `typescript/module-declarations-v2`,
destination: filePath.replace(`.json`, `.d.ts`),
filter: token => token.filePath === filePath,
filter: token => token.filePath === filePath && token.isSource,
}
}),
},
Expand All @@ -351,18 +313,19 @@ function buildPrimitives(
return {
format: `javascript/module-v2`,
destination: filePath.replace(`.json`, `.js`),
filter: token => token.filePath === filePath,
filter: token => token.filePath === filePath && token.isSource,
}
}),
},
}

const config = {
...{include: include ? [include] : undefined},
include,
source: files,
...customParseConfig,
platforms: platforms ? platforms : defaultPlatformConfig,
}

return config
}

Expand Down

0 comments on commit 46a4b49

Please sign in to comment.