forked from digdir/designsystemet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add the @digir/create-tokens CLI tool
- Loading branch information
Showing
26 changed files
with
4,582 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
root: false, | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
import { require } from 'tsx/cjs/api'; | ||
|
||
require('./src/index.ts', import.meta.url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@digdir/create-tokens", | ||
"version": "0.1.0-alpha.7", | ||
"description": "CLI tool to create an initial token structure for Designsystemet", | ||
"author": "Designsystemet team", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/digdir/designsystemet.git" | ||
}, | ||
"homepage": "https://github.com/digdir/designsystemet/tree/main/packages/create-tokens", | ||
"license": "MIT", | ||
"type": "module", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "index.js", | ||
"bin": "index.js", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"dependencies": { | ||
"change-case": "^5.3.0", | ||
"kleur": "^3.0.3", | ||
"prompts": "^2.4.0", | ||
"tsx": "^4.11.2" | ||
}, | ||
"devDependencies": { | ||
"@tokens-studio/types": "^0.4.0", | ||
"@types/prompts": "^2.4.9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { normalizeTokenSetName } from './utils.js'; | ||
|
||
interface Metadata { | ||
tokenSetOrder: string[]; | ||
} | ||
|
||
export default function generateMetadataJson( | ||
modes: Array<'Light' | 'Dark' | 'Contrast'>, | ||
themes: string[], | ||
): Metadata { | ||
return { | ||
tokenSetOrder: [ | ||
'primitives/globals', | ||
'primitives/typography/default', | ||
...modes.flatMap((mode) => [ | ||
`primitives/colors/${normalizeTokenSetName(mode)}/global`, | ||
...themes.map( | ||
(theme) => | ||
`primitives/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`, | ||
), | ||
]), | ||
...themes.map((theme) => `themes/${normalizeTokenSetName(theme)}`), | ||
'semantic/color', | ||
'semantic/style', | ||
], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { randomUUID } from 'node:crypto'; | ||
|
||
import { TokenSetStatus, type ThemeObject } from '@tokens-studio/types'; | ||
|
||
import { normalizeTokenSetName } from './utils.js'; | ||
|
||
export default function generateThemesJson( | ||
modes: Array<'Light' | 'Dark' | 'Contrast'>, | ||
themes: string[], | ||
): ThemeObject[] { | ||
return [ | ||
...generateModesGroup(modes, themes), | ||
...generateThemesGroup(themes), | ||
generateSemanticGroup(), | ||
]; | ||
} | ||
|
||
function generateModesGroup( | ||
modes: Array<'Light' | 'Dark' | 'Contrast'>, | ||
themes: string[], | ||
): ThemeObject[] { | ||
return modes.map( | ||
(mode): ThemeObject => ({ | ||
id: randomUUID(), | ||
name: mode, | ||
selectedTokenSets: Object.fromEntries([ | ||
[ | ||
`primitives/colors/${normalizeTokenSetName(mode)}/global`, | ||
TokenSetStatus.ENABLED, | ||
], | ||
...themes.map( | ||
(theme) => | ||
[ | ||
`primitives/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`, | ||
TokenSetStatus.ENABLED, | ||
] as const, | ||
), | ||
]), | ||
group: 'Mode', | ||
}), | ||
); | ||
} | ||
|
||
function generateThemesGroup(themes: string[]): ThemeObject[] { | ||
return themes.map( | ||
(theme): ThemeObject => ({ | ||
id: randomUUID(), | ||
name: theme, | ||
selectedTokenSets: { | ||
[`themes/${normalizeTokenSetName(theme)}`]: TokenSetStatus.ENABLED, | ||
}, | ||
group: 'Theme', | ||
}), | ||
); | ||
} | ||
|
||
function generateSemanticGroup(): ThemeObject { | ||
return { | ||
id: randomUUID(), | ||
name: 'Semantic', | ||
selectedTokenSets: { | ||
'semantic/style': TokenSetStatus.ENABLED, | ||
'semantic/color': TokenSetStatus.ENABLED, | ||
'primitives/globals': TokenSetStatus.SOURCE, | ||
'primitives/typography/default': TokenSetStatus.SOURCE, | ||
}, | ||
group: 'Semantic', | ||
}; | ||
} |
Oops, something went wrong.