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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { AUTO_GENERATED_FILE_HEADER } from '../../constants/auto-generated-file-header.ts';

export const VARIABLE_PREFIX = 'esds';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could we re-use or defined this constant in the same folder as CSS_VARIABLE_PREFIX, see packages/tokens/scripts/scripts/build-tokens/src/constants/css-variable-prefix.ts


export const T1_DIRECTORY_NAME = 't1-primitive';
export const T2_DIRECTORY_NAME = 't2-semantic';
export const T3_DIRECTORY_NAME = 't3-component';
Comment on lines +5 to +7
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: these constants are already defined in /packages/tokens/scripts/scripts/build-tokens/src/constants/design-token-tiers.ts, could we re-use them?


export const DESIGN_TOKEN_TIERS = [T1_DIRECTORY_NAME, T2_DIRECTORY_NAME, T3_DIRECTORY_NAME];

export const AUTOGENERATED_SWIFT_HEADER = ['//', `// ${AUTO_GENERATED_FILE_HEADER}`, '//'];

export function segmentKebabCase(segment: string): string {
return (
segment
// replace white-spaces with single dash
.replace(/\s+/g, '-')
// convert camelCase/PascalCase to dash-case
.replace(
/[A-Z]/g,
(letter: string, offset: number): string =>
`${offset > 0 ? '-' : ''}${letter.toLowerCase()}`,
)
// remove starting and ending dashes
.replace(/^-+|-+$/g, '')
// remove consecutive dashes
.replace(/--+/g, '-')
// remove all non-alphanumeric or dash characters
.replace(/[^a-z0-9-]/g, '')
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Custom parser that moves root-level $type into each top-level group.
* This prevents SD5's merge from losing per-file $type when multiple
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: what does SD5 mean here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style Dictionary 5

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This prevents SD5's merge from losing per-file $type when multiple
* This prevents Style Dictionary's merge from losing per-file $type when multiple

* source files define different $type at their root level.
*/
export const fixTypeInheritanceParser = {
name: 'esds/fix-type-inheritance',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: should esds come from a constant?

pattern: /\.tokens\.json$/,
parser: ({ contents }: { filePath: string; contents: string }) => {
const data = JSON.parse(contents);
const rootType = data['$type'];
if (rootType) {
delete data['$type'];
for (const [key, val] of Object.entries(data)) {
if (key.startsWith('$')) continue;
if (val && typeof val === 'object' && !(val as any)['$type']) {

Check failure on line 16 in packages/tokens/scripts/scripts/build-tokens/src/build/outputs/swift/parser.ts

View workflow job for this annotation

GitHub Actions / check-pr-code-quality

Unexpected any. Specify a different type
(val as any)['$type'] = rootType;

Check failure on line 17 in packages/tokens/scripts/scripts/build-tokens/src/build/outputs/swift/parser.ts

View workflow job for this annotation

GitHub Actions / check-pr-code-quality

Unexpected any. Specify a different type
}
}
}
return data;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Transform, TransformedToken } from 'style-dictionary/types';
import { segmentKebabCase } from './helpers.ts';

/**
* Name transform that replicates the exact naming logic from the custom DTCG framework.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: how is DTCG custom? It should be a standard, no?

Do you mean "custom parser" ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not, it's not a parser, it's for the output.
But I think it's an oversight of my part with testing cause actually SD have a Kebabcase transform built-in

*/
export const nameTransform: Transform = {
name: 'esds/name',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: should esds come from a constant?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right!

type: 'name',
transform: (token: TransformedToken): string => {
return token.path
.map(segmentKebabCase)
.filter((s: string) => s !== '' && s !== '-')
.join('-');
},
};
Loading