Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/1.guide/3.API.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Theme tokens gets processed by [Style Dictionary](https://amzn.github.io/style-d
- `tokens.json` if you want to import it from a JSON context.
- `index.ts` to import it from runtime or from any TypeScript context.
- `index.js` to import it from runtime or from any JavaScript context.
- `types.d.ts` for global type inference (`$dt()`, `$tokens()`, `useTokens()`, `defineTokens`, `nuxt.config.style.tokens`).
- `types.ts` for global type inference (`$dt()`, `$tokens()`, `useTokens()`, `defineTokens`, `nuxt.config.style.tokens`).

- **Composable usage**
```ts
Expand Down
16 changes: 8 additions & 8 deletions src/config/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { rm, writeFile } from 'fs/promises'
import type { Core as Instance } from 'browser-style-dictionary/types/browser'
import StyleDictionary from 'browser-style-dictionary/browser.js'
import { Dictionary } from 'browser-style-dictionary/types/Dictionary'
import { tsTypesDeclaration, tsFull, jsFull, walkTokens } from '../formats'
import { tsTypesExports, tsFull, jsFull, walkTokens } from '../formats'
import type { NuxtStyleTheme } from '../index'
import { createTokensDir } from './load'

Expand All @@ -15,7 +15,7 @@ export const stubTokens = async (buildPath: string, force = false) => {
'tokens.json': () => '{}',
'index.js': jsFull,
'index.ts': tsFull,
'types.d.ts': tsTypesDeclaration
'types.ts': tsTypesExports
}

for (const [file, stubbingFunction] of Object.entries(files)) {
Expand All @@ -40,7 +40,7 @@ export const getStyleDictionaryInstance = async (tokens: NuxtStyleTheme, buildPa
styleDictionary.registerFormat({
name: 'typescript/types-declaration',
formatter ({ dictionary }) {
return tsTypesDeclaration(dictionary)
return tsTypesExports(dictionary)
}
})

Expand Down Expand Up @@ -104,7 +104,7 @@ export const getStyleDictionaryInstance = async (tokens: NuxtStyleTheme, buildPa
format: 'typescript/full'
},
{
destination: 'types.d.ts',
destination: 'types.ts',
format: 'typescript/types-declaration'
}
]
Expand Down Expand Up @@ -146,8 +146,8 @@ const generateTokensOutputs = (styleDictionary: Instance, silent = true) => new
try {
// Weird trick to disable nasty logging
if (silent) {
// @ts-ignore
// eslint-disable-next-line no-console
// @ts-ignore
// eslint-disable-next-line no-console
console._log = console.log
// eslint-disable-next-line no-console
console.log = () => {}
Expand All @@ -170,8 +170,8 @@ const generateTokensOutputs = (styleDictionary: Instance, silent = true) => new

// Weird trick to disable nasty logging
if (silent) {
// @ts-ignore
// eslint-disable-next-line no-console
// @ts-ignore
// eslint-disable-next-line no-console
console.log = console._log
}
} catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions src/formats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export { walkTokens }
* Formats
*/

export const tsTypesDeclaration = ({ tokens }: Dictionary) => {
export const tsTypesExports = ({ tokens }: Dictionary) => {
const { type } = walkTokens(tokens)

let result = 'import type { RefΒ } from \'vue\'\n\n'
Expand Down Expand Up @@ -41,9 +41,9 @@ export const tsTypesDeclaration = ({ tokens }: Dictionary) => {
export const tsFull = ({ tokens }: Dictionary) => {
const { type, aliased } = walkTokens(tokens, false)

let result = 'import type { NuxtThemeTokens, NuxtThemeTokensPaths, TokenHelperOptions } from \'./types.d\'\n\n'
let result = 'import type { NuxtThemeTokens, NuxtThemeTokensPaths, TokenHelperOptions } from \'./types\'\n\n'

result = result + 'export * from \'./types.d\'\n\n'
result = result + 'export * from \'./types\'\n\n'

result = result + `${getFunction}\n\n`

Expand Down
4 changes: 2 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default defineNuxtModule<ModuleOptions>({
nuxt.options.alias = nuxt.options.alias || {}
nuxt.options.alias['#design-tokens'] = resolveTokensDir('index')
nuxt.options.alias['#design-tokens/style'] = resolveTokensDir('tokens.css')
nuxt.options.alias['#design-tokens/types'] = resolveTokensDir('types.d')
nuxt.options.alias['#design-tokens/types'] = resolveTokensDir('types')

// Inject CSS
// nuxt.options.css = nuxt.options.css || []
Expand Down Expand Up @@ -169,7 +169,7 @@ export default defineNuxtModule<ModuleOptions>({

// Inject typings
nuxt.hook('prepare:types', (opts) => {
opts.references.push({ path: resolveTokensDir('types.d.ts') })
opts.references.push({ path: resolveTokensDir('types.ts') })
})

// Initial build
Expand Down