Skip to content

Commit

Permalink
added file header to the generation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexasselin008 committed Nov 1, 2023
1 parent 74694fd commit 25b15ee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Do not edit directly
* Generated on Wed, 01 Nov 2023 16:09:51 GMT
* This file is generated by Style Dictionary. Do not edit directly.
*/

export const DarkSemanticTokens = {
Expand Down
3 changes: 1 addition & 2 deletions packages/styled-system/src/tokens/generated/light-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Do not edit directly
* Generated on Wed, 01 Nov 2023 16:09:51 GMT
* This file is generated by Style Dictionary. Do not edit directly.
*/

export const CoreTokens = {
Expand Down
15 changes: 13 additions & 2 deletions packages/tokens/src/style-dictionary/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { cssDarkMode, customDoc, customJson, customTsTokens, fontFace } from "./
import { w3cTokenJsonParser } from "./parser/w3c-token-parser.ts";
import { attributeFont, isSizeType, pxToRem } from "./transform/index.ts";

const { fileHeader } = StyleDictionary.formatHelpers;

// Filters
StyleDictionary.registerFilter({
Expand Down Expand Up @@ -61,8 +62,18 @@ StyleDictionary.registerFormat({

StyleDictionary.registerFormat({
name: "custom/ts-tokens",
formatter: function({ dictionary, file }) {
return StyleDictionary.formatHelpers.fileHeader({ file }) + customTsTokens({ dictionary });
formatter: ({ dictionary, file }) => {
return fileHeader({ file }) + customTsTokens({ dictionary });
}
});

// File Headers
StyleDictionary.registerFileHeader({
name: "typescript-file-header",
fileHeader: () => {
return [
"This file is generated by Style Dictionary. Do not edit directly."
];
}
});

Expand Down
11 changes: 7 additions & 4 deletions packages/tokens/src/style-dictionary/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Config } from "style-dictionary";
import type { Config, File } from "style-dictionary";

const PREFIX = "hop";
const BUILD_PATH = "dist/";
const STORYBOOK_BUILD_PATH = "../src/stories";
const DOCS_BUILD_PATH = "../../../apps/docs";
const STYLED_SYSTEM_BUILD_PATH = "../styled-system/src/";

export const fontsConfig = {
export const fontsConfig: Config = {
"source": ["src/tokens/asset/*.tokens.json"],
"platforms": {
"css-font-face": {
Expand Down Expand Up @@ -42,6 +42,9 @@ export function getStyledSystemTokensConfig(mode: "light" | "dark"): Config {
"transformGroup": "custom/css", // We want the same values and name as the ones shown in css
"buildPath": STYLED_SYSTEM_BUILD_PATH,
"prefix": PREFIX,
"options": {
"fileHeader": "typescript-file-header"
},
"files": [
{
"destination": `tokens/generated/${isLightMode ? "light-tokens" : "dark-semantic-tokens" }.ts`,
Expand All @@ -60,15 +63,15 @@ export function getStyledSystemTokensConfig(mode: "light" | "dark"): Config {
export function getStyleDictionaryConfig(mode: "light" | "dark"): Config {
const isLightMode = mode === "light";

const lightConfig = {
const lightConfig: File = {
"destination": "tokens.css",
"format": "css/variables",
"options": {
"outputReferences": true
}
};

const darkConfig = {
const darkConfig: File = {
"destination": "dark/tokens.css",
"format": "css/dark-mode",
"filter": "mode/dark",
Expand Down

0 comments on commit 25b15ee

Please sign in to comment.