Skip to content

Commit

Permalink
Merge pull request #585 from pixiv/mimo/fix-token-cli
Browse files Browse the repository at this point in the history
fix token cli
  • Loading branch information
mimokmt authored Jul 8, 2024
2 parents ebf1640 + b7a4adc commit 5cb313a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 24 deletions.
5 changes: 1 addition & 4 deletions packages/pullrequest-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@charcoal-ui/pullrequest-cli",
"private": "true",
"private": true,
"license": "Apache-2.0",
"bin": "./dist/index.js",
"scripts": {
Expand All @@ -26,9 +26,6 @@
"src",
"dist"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/pixiv/charcoal.git",
Expand Down
4 changes: 3 additions & 1 deletion packages/token-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"scripts": {
"build": "FORCE_COLOR=1 tsup-node",
"typecheck": "tsc --project tsconfig.build.json --pretty --noEmit",
"clean": "rimraf dist .tsbuildinfo"
"clean": "rimraf dist .tsbuildinfo",
"test": "jest"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/yargs": "^17.0.32",
"jest": "^29.6.0",
"rimraf": "^3.0.2",
"style-dictionary": "^3.9.2",
"tsup": "^8.0.2",
Expand Down
13 changes: 5 additions & 8 deletions packages/token-cli/pixiv-dark.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { transformer } = require('./src/transformer')

/** @type { import('style-dictionary') } */
module.exports = {
source: ['tokens/base.json', 'tokens/pixiv-light.json'],
source: ['tokens/base.json', 'tokens/pixiv-dark.json'],
transform: {
'name/cti/kebab': {
type: 'name',
transformer: (token) => {
return token.path
.join('-')
.toLowerCase()
.replaceAll('/', '-')
.replaceAll(' ', '-')
},
transformer: transformer,
},
},
platforms: {
Expand Down
11 changes: 4 additions & 7 deletions packages/token-cli/pixiv-light.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { transformer } = require('./src/transformer')

/** @type { import('style-dictionary') } */
module.exports = {
source: ['tokens/base.json', 'tokens/pixiv-light.json'],
transform: {
'name/cti/kebab': {
type: 'name',
transformer: (token) => {
return token.path
.join('-')
.toLowerCase()
.replaceAll('/', '-')
.replaceAll(' ', '-')
},
transformer: transformer,
},
},
platforms: {
Expand Down
3 changes: 0 additions & 3 deletions packages/token-cli/src/createToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ export const createToken = (
...current,
}))

if (modeName != undefined && collection.defaultModeId != modeId)
return { [collection.name]: { [modeName]: variables } }

return { [collection.name]: variables }
})
.reduce<{ [key: string]: object }>(
Expand Down
18 changes: 18 additions & 0 deletions packages/token-cli/src/transformer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @param {import('style-dictionary').TransformedToken} token
* @return {string}
*/
const transformer = (token) => {
return token.path
.join('-')
.replace(/(.)([A-Z])/g, '$1-$2')
.replace(/([A-Z])([A-Z])/g, '$1-$2')
.toLowerCase()
.replaceAll('/', '-')
.replaceAll(' ', '-')
.replaceAll('--', '-')
}

module.exports = {
transformer,
}
12 changes: 12 additions & 0 deletions packages/token-cli/src/transformer/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { transformer } = require('.')
test('tests transformer real case', () => {
expect(transformer({ path: ['Color', 'container/secondary/defaultA'] })).toBe(
'color-container-secondary-default-a'
)
})
test('tests transformer unreal case', () => {
expect(
transformer({ path: ['Color', 'Container/Secondary/DefaultABCDEF'] })
).toBe('color-container-secondary-default-a-b-c-d-e-f')
})
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2800,6 +2800,7 @@ __metadata:
"@types/yargs": ^17.0.32
axios: ^1.6.7
fs-extra: ^11.2.0
jest: ^29.6.0
rimraf: ^3.0.2
style-dictionary: ^3.9.2
tsup: ^8.0.2
Expand Down Expand Up @@ -19572,7 +19573,7 @@ __metadata:
languageName: node
linkType: hard

"jest@npm:^29.6.4":
"jest@npm:^29.6.0, jest@npm:^29.6.4":
version: 29.7.0
resolution: "jest@npm:29.7.0"
dependencies:
Expand Down

0 comments on commit 5cb313a

Please sign in to comment.