Skip to content

Commit

Permalink
fix(token-cli): prefix, selector, actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mimokmt committed Jul 11, 2024
1 parent fa34318 commit 0b7a34c
Show file tree
Hide file tree
Showing 9 changed files with 727 additions and 32 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/tokens.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ jobs:
run:
working-directory: packages/token-cli
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}

- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
Expand Down Expand Up @@ -50,9 +53,15 @@ jobs:
- name: Copy to theme package
run: |
rm -rf ../theme/src/json
rm -rf ../theme/src/css
cp -r ./tokens ../theme/src/json
cp -r ./build/css ../theme/src/css
- name: Run prettier
working-directory: ./
run: yarn fmt:prettier

- name: Generate github token
id: generate_token
uses: tibdex/github-app-token@v1
Expand All @@ -66,7 +75,7 @@ jobs:
GITHUB_ACCESS_TOKEN: ${{ steps.generate_token.outputs.token }}
GITHUB_REPO_OWNER: pixiv
GITHUB_REPO_NAME: charcoal
GITHUB_DEFAULT_BRANCH: main
GITHUB_DEFAULT_BRANCH: ${{ github.ref_name }}
TARGET_DIR: packages/theme
run: yarn pullrequest-cli github:pr -c theme -t 'Update theme'

Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ LICENSE
/packages/token-cli/build/
/packages/token-cli/tokens/
/packages/token-cli/out/
/packages/theme/src/json/
/packages/theme/src/css/
328 changes: 327 additions & 1 deletion packages/theme/src/json/base.json

Large diffs are not rendered by default.

182 changes: 181 additions & 1 deletion packages/theme/src/json/pixiv-dark.json

Large diffs are not rendered by default.

176 changes: 175 additions & 1 deletion packages/theme/src/json/pixiv-light.json

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions packages/token-cli/pixiv-dark.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { transformer } = require('./src/transformer')
const { nameTransformer } = require('./src/transformer')

/** @type { import('style-dictionary') } */
/** @type { import('style-dictionary').Config } */
module.exports = {
source: ['tokens/base.json', 'tokens/pixiv-dark.json'],
transform: {
'name/cti/kebab': {
'charcoal/kebab': {
type: 'name',
transformer: transformer,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
transformer: nameTransformer,
},
},
platforms: {
css: {
transforms: ['charcoal/kebab'],
transformGroup: 'css',
buildPath: 'build/css/',
prefix: 'charcoal',
files: [
{
destination: '_variables_dark.css',
format: 'css/variables',
options: {
selector: ":root[data-color-scheme='dark']",
outputReferences: true,
},
},
],
options: {
outputReferences: true,
},
},
},
}
19 changes: 11 additions & 8 deletions packages/token-cli/pixiv-light.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { transformer } = require('./src/transformer')
const { nameTransformer } = require('./src/transformer')

/** @type { import('style-dictionary') } */
/** @type { import('style-dictionary').Config } */
module.exports = {
source: ['tokens/base.json', 'tokens/pixiv-light.json'],
transform: {
'name/cti/kebab': {
'charcoal/kebab': {
type: 'name',
transformer: transformer,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
transformer: nameTransformer,
},
},
platforms: {
css: {
transforms: ['charcoal/kebab'],
transformGroup: 'css',
buildPath: 'build/css/',
prefix: 'charcoal',
files: [
{
destination: '_variables_light.css',
format: 'css/variables',
options: {
selector:
":root[data-color-scheme='light'], :root:not([data-color-scheme])",
outputReferences: true,
},
},
],
options: {
outputReferences: true,
},
},
},
}
8 changes: 5 additions & 3 deletions packages/token-cli/src/transformer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
* @param {import('style-dictionary').TransformedToken} token
* @return {string}
*/
const transformer = (token) => {
return token.path
const nameTransformer = (token) => {
const name = token.path
.join('-')
.replace(/(.)([A-Z])/g, '$1-$2')
.replace(/([A-Z])([A-Z])/g, '$1-$2')
.toLowerCase()
.replaceAll('/', '-')
.replaceAll(' ', '-')
.replace(/(--)(\D)/g, '-$2')

return `charcoal-${name}`
}

module.exports = {
transformer,
nameTransformer,
}
14 changes: 7 additions & 7 deletions packages/token-cli/src/transformer/index.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { transformer } = require('.')
const { nameTransformer } = require('.')
test('tests transformer real case', () => {
expect(transformer({ path: ['Color', 'container/secondary/defaultA'] })).toBe(
'color-container-secondary-default-a'
)
expect(
nameTransformer({ path: ['Color', 'container/secondary/defaultA'] })
).toBe('color-container-secondary-default-a')

Check failure on line 6 in packages/token-cli/src/transformer/index.test.js

View workflow job for this annotation

GitHub Actions / test

packages/token-cli/src/transformer/index.test.js > tests transformer real case

AssertionError: expected 'charcoal-color-container-secondary-de…' to be 'color-container-secondary-default-a' // Object.is equality - Expected + Received - color-container-secondary-default-a + charcoal-color-container-secondary-default-a ❯ packages/token-cli/src/transformer/index.test.js:6:5
})
test('tests transformer negative primitive value case', () => {
expect(transformer({ path: ['Colors', 'Dark/Neutral/-10'] })).toBe(
expect(nameTransformer({ path: ['Colors', 'Dark/Neutral/-10'] })).toBe(

Check failure on line 9 in packages/token-cli/src/transformer/index.test.js

View workflow job for this annotation

GitHub Actions / test

packages/token-cli/src/transformer/index.test.js > tests transformer negative primitive value case

AssertionError: expected 'charcoal-colors-dark-neutral--10' to be 'colors-dark-neutral--10' // Object.is equality - Expected + Received - colors-dark-neutral--10 + charcoal-colors-dark-neutral--10 ❯ packages/token-cli/src/transformer/index.test.js:9:69
'colors-dark-neutral--10'
)
})
test('tests transformer negative primitive value unreal case', () => {
expect(transformer({ path: ['Colors', 'dark/neutralABCDEF/-10'] })).toBe(
expect(nameTransformer({ path: ['Colors', 'dark/neutralABCDEF/-10'] })).toBe(

Check failure on line 14 in packages/token-cli/src/transformer/index.test.js

View workflow job for this annotation

GitHub Actions / test

packages/token-cli/src/transformer/index.test.js > tests transformer negative primitive value unreal case

AssertionError: expected 'charcoal-colors-dark-neutral-a-b-c-d-…' to be 'colors-dark-neutral-a-b-c-d-e-f--10' // Object.is equality - Expected + Received - colors-dark-neutral-a-b-c-d-e-f--10 + charcoal-colors-dark-neutral-a-b-c-d-e-f--10 ❯ packages/token-cli/src/transformer/index.test.js:14:75
'colors-dark-neutral-a-b-c-d-e-f--10'
)
})
test('tests transformer unreal case', () => {
expect(
transformer({ path: ['Color', 'Container/Secondary/DefaultABCDEF'] })
nameTransformer({ path: ['Color', 'Container/Secondary/DefaultABCDEF'] })
).toBe('color-container-secondary-default-a-b-c-d-e-f')

Check failure on line 21 in packages/token-cli/src/transformer/index.test.js

View workflow job for this annotation

GitHub Actions / test

packages/token-cli/src/transformer/index.test.js > tests transformer unreal case

AssertionError: expected 'charcoal-color-container-secondary-de…' to be 'color-container-secondary-default-a-b…' // Object.is equality - Expected + Received - color-container-secondary-default-a-b-c-d-e-f + charcoal-color-container-secondary-default-a-b-c-d-e-f ❯ packages/token-cli/src/transformer/index.test.js:21:5
})

0 comments on commit 0b7a34c

Please sign in to comment.