Skip to content

Commit

Permalink
fix(tokens): prepend fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
azuradara committed Dec 31, 2024
1 parent fa92d42 commit 26fc31d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/celeste-tokens/src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
declare module 'style-dictionary' {
declare class StyleDictionary {
class StyleDictionary {
constructor(config: any);
cleanAllPlatforms(): void;
buildAllPlatforms(): void;
}

export = StyleDictionary;
export default StyleDictionary;
}

declare module '@tokens-studio/sd-transforms' {
function register(sd: StyleDictionary): void;
function register(sd: any): void;
}
20 changes: 18 additions & 2 deletions packages/celeste-tokens/src/generate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable antfu/no-top-level-await */
import { readFileSync, writeFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { register } from '@tokens-studio/sd-transforms';
import StyleDictionary from 'style-dictionary';
Expand All @@ -6,6 +8,17 @@ const dist = `${resolve(import.meta.dirname, '..', 'dist')}/`;

register(StyleDictionary);

// TODO: use a custom fonts cdn

const fonts = `
@import url('https://fonts.googleapis.com/css2?family=Cairo:[email protected]&family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');
`;

function prependFonts(path: string): void {
const data = readFileSync(path, 'utf8');
writeFileSync(path, fonts + data, 'utf8');
}

const sd = new StyleDictionary({
source: [join(import.meta.dirname, 'tokens/**/*.json')],
log: {
Expand Down Expand Up @@ -44,5 +57,8 @@ const sd = new StyleDictionary({
},
});

sd.cleanAllPlatforms();
sd.buildAllPlatforms();
await sd.cleanAllPlatforms();
await sd.buildAllPlatforms();

prependFonts(resolve(dist, 'tokens.css'));
prependFonts(resolve(dist, 'tokens.scss'));
11 changes: 11 additions & 0 deletions packages/celeste-tokens/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "nodenext"
},
"exclude": [
"node_modules",
"dist"
]
}

0 comments on commit 26fc31d

Please sign in to comment.