Skip to content

Commit

Permalink
feat: restructure output tokens and filter global and base
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Restructure output tokens
  • Loading branch information
druhill committed Jan 10, 2024
1 parent df2239b commit 32d43d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
13 changes: 11 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const modes = readdirSync('./data/tokens/Modes/')

const getFiles = (modeName, format, subType, suffix) => {
return [
...getSplit(undefined, modeName, format, subType, suffix, false),
...getSplit('base', modeName, format, subType, suffix, false),
...getSplit('global', modeName, format, subType, suffix, false),
...getComponents(modeName, format, subType, suffix)
]
}
Expand All @@ -28,7 +29,15 @@ const getComponents = (modeName, format, subType, suffix) => {
}

const getSplit = (componentName, modeName, format, subType, suffix, outputReferences) => {
const path = componentName ? '/' + componentName : ''
const getPath = (componentName) => {
const path = {
base: '/base/',
global: '/global/'
}
return path[componentName] || '/components/' + componentName
}

const path = getPath(componentName)

return [
{
Expand Down
4 changes: 2 additions & 2 deletions scripts/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const {
outputFile,
outputJson,
removeSync,
ensureDir,
readFileSync
ensureDir
// readFileSync
} = require('fs-extra')
const { generateFonts } = require('fantasticon')
const {
Expand Down
14 changes: 8 additions & 6 deletions scripts/postbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,33 @@ function copyReadme () {
}

function addEntryFile () {
const jsFilePaths = glob('./dist/js/*/*/*.js')
const jsComponentPaths = glob('./dist/js/*/*/*/*.js')
const jsFilePaths = glob('./dist/js/*/*/{base,global}/*.js')
const jsComponentPaths = glob('./dist/js/*/*/components/*/*.js')
const entryFilePath = resolve(__dirname, '../dist/index.js')

const fileExports = jsFilePaths
.map((filePath) => {
const [mode, theme, fullName] = filePath.split('/').slice(-3)
const [mode, theme, type, fullName] = filePath.split('/').slice(-4)
const name = filename(fullName)
return {
mode,
theme,
type,
name
}
})
.map((file) => {
const exportName = camelCase(`${file.mode} ${file.theme} ${file.name}`)
return `export * as ${exportName} from './js/${file.mode}/${file.theme}/${file.name}'`
const exportName = camelCase(`${file.mode} ${file.theme} ${file.type} ${file.name}`)
return `export * as ${exportName} from './js/${file.mode}/${file.theme}/${file.type}/${file.name}'`
}).join('\n')
const componentExports = jsComponentPaths
.map((filePath) => {
const [mode, theme, component, fullName] = filePath.split('/').slice(-4)
const [mode, theme, components, component, fullName] = filePath.split('/').slice(-5)
const name = filename(fullName)
return {
mode,
theme,
components,
component,
name
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils/filter-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Copyright © 2024 The Sage Group plc or its licensors. All Rights reserved
*/

const filterComponent = (token, componentName) => token.path.indexOf('origin') === -1 && (componentName ? token.path[0] === componentName : true)
const filterComponent = (token, componentName) => token.path.indexOf('origin') === -1 && (componentName ? token.path[0] === componentName : false)

module.exports = filterComponent

0 comments on commit 32d43d7

Please sign in to comment.