@cobalt-ui/plugin-ts
Advanced tools
Comparing version
# @cobalt-ui/plugin-ts | ||
## 0.2.0 | ||
### Minor Changes | ||
- 26bfb4c: Convert to JSON, follow design tokens spec | ||
### Patch Changes | ||
- Updated dependencies [26bfb4c] | ||
- @cobalt-ui/utils@0.2.0 | ||
## 0.1.0 | ||
### Minor Changes | ||
@@ -5,0 +17,0 @@ |
import type { ParsedToken, Plugin } from '@cobalt-ui/core'; | ||
export interface Options { | ||
/** output file (default: "./tokens/index.ts") */ | ||
filename?: string; | ||
fileName?: string; | ||
/** modify values */ | ||
@@ -6,0 +6,0 @@ transformValue?: (token: ParsedToken) => string; |
export default function ts(options) { | ||
let fileName = options?.filename || './index.ts'; | ||
let fileName = options?.fileName || './index.ts'; | ||
let transformer = options?.transformValue; | ||
@@ -48,11 +48,11 @@ function printTokensExport(schemaTokens) { | ||
function printAltFunction() { | ||
return `/** Get alternate values */ | ||
export function getAlt<T = string>(tokenID: keyof TokensFlat, mode: string): T { | ||
return `/** Get mode value */ | ||
export function getMode<T = string>(tokenID: keyof TokensFlat, mode: string): T { | ||
let defaultVal = tokens; | ||
let altVal = modes; | ||
let modeVal = modes; | ||
for (const next of tokenID.split('.')) { | ||
defaultVal = defaultVal[next]; | ||
if (altVal[next] !== undefined) altVal = altVal[next]; | ||
if (modeVal[next] !== undefined) modeVal = modeVal[next]; | ||
} | ||
return (altVal && altVal[mode]) || defaultVal; | ||
return (modeVal && modeVal[mode]) || defaultVal; | ||
}`; | ||
@@ -62,4 +62,4 @@ } | ||
name: '@cobalt-ui/plugin-ts', | ||
async build({ schema }) { | ||
let code = [printTokensExport(schema.tokens), printModesExport(schema.tokens), printAltFunction()]; | ||
async build({ tokens }) { | ||
let code = [printTokensExport(tokens), printModesExport(tokens), printAltFunction()]; | ||
return [ | ||
@@ -74,1 +74,2 @@ { | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@cobalt-ui/plugin-ts", | ||
"description": "TypeScript builder for Cobalt UI design tokens", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": { | ||
@@ -20,6 +20,6 @@ "name": "Drew Powers", | ||
"dependencies": { | ||
"@cobalt-ui/utils": "^0.1.0" | ||
"@cobalt-ui/utils": "^0.2.0" | ||
}, | ||
"devDependencies": { | ||
"@cobalt-ui/core": "^0.1.0" | ||
"@cobalt-ui/core": "^0.2.0" | ||
}, | ||
@@ -26,0 +26,0 @@ "scripts": { |
@@ -5,3 +5,3 @@ import type { BuildResult, ParsedToken, Plugin } from '@cobalt-ui/core'; | ||
/** output file (default: "./tokens/index.ts") */ | ||
filename?: string; | ||
fileName?: string; | ||
/** modify values */ | ||
@@ -12,3 +12,3 @@ transformValue?: (token: ParsedToken) => string; | ||
export default function ts(options?: Options): Plugin { | ||
let fileName = options?.filename || './index.ts'; | ||
let fileName = options?.fileName || './index.ts'; | ||
let transformer = options?.transformValue; | ||
@@ -63,11 +63,11 @@ | ||
function printAltFunction(): string { | ||
return `/** Get alternate values */ | ||
export function getAlt<T = string>(tokenID: keyof TokensFlat, mode: string): T { | ||
return `/** Get mode value */ | ||
export function getMode<T = string>(tokenID: keyof TokensFlat, mode: string): T { | ||
let defaultVal = tokens; | ||
let altVal = modes; | ||
let modeVal = modes; | ||
for (const next of tokenID.split('.')) { | ||
defaultVal = defaultVal[next]; | ||
if (altVal[next] !== undefined) altVal = altVal[next]; | ||
if (modeVal[next] !== undefined) modeVal = modeVal[next]; | ||
} | ||
return (altVal && altVal[mode]) || defaultVal; | ||
return (modeVal && modeVal[mode]) || defaultVal; | ||
}`; | ||
@@ -78,4 +78,4 @@ } | ||
name: '@cobalt-ui/plugin-ts', | ||
async build({ schema }): Promise<BuildResult[]> { | ||
let code = [printTokensExport(schema.tokens), printModesExport(schema.tokens), printAltFunction()]; | ||
async build({ tokens }): Promise<BuildResult[]> { | ||
let code = [printTokensExport(tokens), printModesExport(tokens), printAltFunction()]; | ||
return [ | ||
@@ -82,0 +82,0 @@ { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10673
27.56%8
14.29%0
-100%+ Added
- Removed
Updated