Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
2bb814f
Change thema-a color to red
Tangcuyu Oct 4, 2023
5d2c1a6
feat():change github action to own reop
Tangcuyu Oct 4, 2023
6be9348
Merge branch 'main' of github.com:Tangcuyu/token-demo-src into main
Tangcuyu Oct 4, 2023
b786782
change to blue
Tangcuyu Oct 4, 2023
0737020
change back to green
Tangcuyu Oct 4, 2023
c714811
build tokens
Tangcuyu Oct 4, 2023
db4fff5
feat():change dst_owner to Tangcuyu
Tangcuyu Oct 4, 2023
89d82cb
Merge branch 'main' of github.com:Tangcuyu/token-demo-src into main
Tangcuyu Oct 4, 2023
0d7fb21
change color to red
Tangcuyu Oct 4, 2023
1b560eb
build tokens
Tangcuyu Oct 4, 2023
df05fea
feat():change build-tokens.yml
Tangcuyu Oct 4, 2023
4c69ad2
feat():add GH_PAT
Tangcuyu Oct 4, 2023
ceb948c
change color to green
Tangcuyu Oct 4, 2023
5e630a9
build tokens
Tangcuyu Oct 4, 2023
82044de
change color and radius
Tangcuyu Oct 4, 2023
808dcde
build tokens
Tangcuyu Oct 4, 2023
44e7e0b
brand-b change radius and color to blue
Tangcuyu Oct 4, 2023
fa82f2c
build tokens
Tangcuyu Oct 4, 2023
34855b1
feat():add brand-c
Tangcuyu Oct 5, 2023
c34841b
Merge branch 'main' of github.com:Tangcuyu/token-demo-src into main
Tangcuyu Oct 5, 2023
b925efc
feat():add global tokens
Tangcuyu Oct 6, 2023
892dfd8
feat():add base tokens from sd
Tangcuyu Oct 6, 2023
c0cc5bf
feat():add custom tokens
Tangcuyu Oct 6, 2023
55640b3
change to red
Tangcuyu Oct 8, 2023
5432c15
change to green
Tangcuyu Oct 8, 2023
b59a070
build tokens
Tangcuyu Oct 8, 2023
81295dc
change radius to small
Tangcuyu Oct 8, 2023
fa34c7b
build tokens
Tangcuyu Oct 8, 2023
d18abbd
change radius to 12px
Tangcuyu Oct 8, 2023
5b0274d
build tokens
Tangcuyu Oct 8, 2023
4c7b95b
color test to disable button
Tangcuyu Oct 8, 2023
72e594f
build tokens
Tangcuyu Oct 8, 2023
0dfea49
change disable
Tangcuyu Oct 9, 2023
17e2d53
build tokens
Tangcuyu Oct 9, 2023
6e0b329
change to blue
Tangcuyu Oct 12, 2023
fc6ffad
build tokens
Tangcuyu Oct 12, 2023
08cef4e
add base size
Tangcuyu Oct 15, 2023
54f6bc0
build tokens
Tangcuyu Oct 15, 2023
b3c583a
change card width&height
Tangcuyu Oct 15, 2023
d050b38
build tokens
Tangcuyu Oct 15, 2023
2a3b3f1
theme b card width 960px
Tangcuyu Oct 15, 2023
36766fb
build tokens
Tangcuyu Oct 15, 2023
69d0a74
feat():add base color
Tangcuyu Oct 17, 2023
45b1951
add base color
Tangcuyu Oct 17, 2023
be796e6
添加字体、字号Tokens
Tangcuyu Oct 18, 2023
8d3dc33
添加阴影、圆角、图表色值
Tangcuyu Oct 18, 2023
6e3fc0c
apply to brand a
Tangcuyu Oct 19, 2023
e8dccaa
brand a disable color
Tangcuyu Oct 19, 2023
088a89e
card radius value
Tangcuyu Oct 19, 2023
ce5659e
brand b
Tangcuyu Oct 19, 2023
8bccc4e
build tokens
Tangcuyu Oct 19, 2023
a7f8a4f
card bottom spacing
Tangcuyu Oct 19, 2023
3d50848
build tokens
Tangcuyu Oct 19, 2023
8382dc6
feat():change action branch to feature
Tangcuyu Oct 19, 2023
4219dba
card header padding top
Tangcuyu Oct 19, 2023
2e6b328
build tokens
Tangcuyu Oct 19, 2023
996d76f
change brand b
Tangcuyu Oct 19, 2023
af95a41
build tokens
Tangcuyu Oct 19, 2023
207b73f
chang brand a & b
Tangcuyu Oct 19, 2023
15d7159
build tokens
Tangcuyu Oct 19, 2023
2b4211c
brand b gap 32px
Tangcuyu Oct 19, 2023
ef523ce
build tokens
Tangcuyu Oct 19, 2023
8d392f6
brand b margin 24
Tangcuyu Oct 19, 2023
e8a0d0a
build tokens
Tangcuyu Oct 19, 2023
c905d12
color-text-button-title
Tangcuyu Oct 19, 2023
1641f05
build tokens
Tangcuyu Oct 19, 2023
ff017c6
feat():add action copy token to graphqlClient repo
Tangcuyu Oct 19, 2023
b3093bf
Merge branch 'feature' of github.com:Tangcuyu/token-demo-src into fea…
Tangcuyu Oct 19, 2023
b228724
brand b gap 8 px
Tangcuyu Oct 19, 2023
6784ab9
build tokens
Tangcuyu Oct 19, 2023
d2948b0
change brand b gap 12px
Tangcuyu Oct 19, 2023
0b541d7
build tokens
Tangcuyu Oct 19, 2023
097cacd
brand b gap 8px
Tangcuyu Oct 19, 2023
a52300c
build tokens
Tangcuyu Oct 19, 2023
4c80b83
brand b gap 8px
Tangcuyu Oct 19, 2023
019c896
build tokens
Tangcuyu Oct 19, 2023
9721469
feat():add scss build
Tangcuyu Oct 26, 2023
126bbb1
Merge branch 'feature' of github.com:Tangcuyu/token-demo-src into fea…
Tangcuyu Oct 26, 2023
03c3015
brand a disabled color
Tangcuyu Oct 26, 2023
0fc8564
feat():change build-tokens.yml npm registry
Tangcuyu Oct 26, 2023
822e6e7
Merge branch 'feature' of github.com:Tangcuyu/token-demo-src into fea…
Tangcuyu Oct 26, 2023
04c7f37
feat():change package.json
Tangcuyu Oct 26, 2023
d8e8b5f
build tokens
Tangcuyu Oct 26, 2023
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
65 changes: 59 additions & 6 deletions .github/workflows/build-tokens.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ jobs:
- uses: actions/checkout@v2
- name: Setup Node.js environment
uses: actions/setup-node@v2.4.0
- run: npm config set registry https://registry.npmjs.org
- run: npm install
- run: npx token-transformer input/design-tokens.json input/base.json base
- run: npx token-transformer input/design-tokens.json input/brand-a.json base,brand-a base --expandTypography=true
- run: npx token-transformer input/design-tokens.json input/brand-b.json base,brand-b base --expandTypography=true
- run:
npx token-transformer input/design-tokens.json input/brand-a.json
base,brand-a base --expandTypography=true
- run:
npx token-transformer input/design-tokens.json input/brand-b.json
base,brand-b base --expandTypography=true
- run: node build.js
- uses: stefanzweifel/git-auto-commit-action@v4
with:
Expand All @@ -23,12 +28,60 @@ jobs:
- uses: andstor/copycat-action@v3.2.4
with:
personal_token: ${{ secrets.GH_PAT }}
src_branch: main
src_branch: feature
src_path: output/.
dst_owner: nyan-matt
dst_owner: Tangcuyu
dst_repo_name: stencil-storybook-token-demo
dst_branch: main
dst_path: src/css/.
username: nyan-matt
email: matt.rea@gmail.com
username: tangcuyu
email: joysmshr@126.com
commit_message: copy css tokens
copy_tokens_tographclient:
runs-on: ubuntu-latest
needs: [build_tokens]
steps:
- uses: andstor/copycat-action@v3.2.4
with:
personal_token: ${{ secrets.GH_PAT }}
src_branch: feature
src_path: output/.
dst_owner: Tangcuyu
dst_repo_name: graphClient
dst_branch: feature-designtokens
dst_path: src/styles/css/.
username: tangcuyu
email: joysmshr@126.com
commit_message: copy base css tokens from token-demo-src repo
copy_tokens_to_election_client:
runs-on: ubuntu-latest
needs: [build_tokens]
steps:
- uses: andstor/copycat-action@v3.2.4
with:
personal_token: ${{ secrets.GH_PAT }}
src_branch: feature
src_path: output/.
dst_owner: Tangcuyu
dst_repo_name: cleanclient
dst_branch: feature-tokens
dst_path: src/renderer/styles/theme/.
username: tangcuyu
email: joysmshr@126.com
commit_message: copy base css tokens from token-demo-src repo
copy_tokens_to_living_base:
runs-on: ubuntu-latest
needs: [build_tokens]
steps:
- uses: andstor/copycat-action@v3.2.4
with:
personal_token: ${{ secrets.GH_PAT }}
src_branch: feature
src_path: output/base.scss
dst_owner: Tangcuyu
dst_repo_name: living-base
dst_branch: feature
dst_path: src/global/css
username: tangcuyu
email: joysmshr@126.com
commit_message: copy base css tokens from tokens src repo
207 changes: 154 additions & 53 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,70 @@
const StyleDictionaryPackage = require('style-dictionary');
const tinycolor = require('tinycolor2');

// increase the lightness by 10%
// tinycolor represents the percent as a decimal between 0 and 1)
// for example: hsl(262, 100%, 68%) is represented as { h: 262, s: 1, l: .68 }
const OFFSET = 0.1;

// the new color properties to replace the original ones
// recall, the original ones are in `design-tokens.json`
let shades = {};

// round to the highest range
// for example: .62 rounds to .70
function roundUp(num, offset = OFFSET) {
return Math.ceil(num / offset) / 10;
}

// since tinycolor represents the percent as a decimal, translate the decimal to the percentage
function asPercent(num) {
return num * 100;
}

// appends the shade percentage to the key
// for example: primary + { h: 262, s: 1, l: .68 } becomes primary-70
function asShadeKey(key, lightness) {
return `${key}-${asPercent(roundUp(lightness))}`;
}

// convert the object representing the hsl back into a string
// for example: { h: 262, s: 1, l: .68 } becomes hsl(262, 100%, 68%)
function asHslString(ratio) {
return tinycolor.fromRatio(ratio).toHslString();
}

// add a new color property for the generated shade
function cloneShade({ hsl, key, lightness, prop }) {
const shadeKey = asShadeKey(key, lightness);
shades[shadeKey] = {
...prop,
value: asHslString({ ...hsl, l: lightness }),
};
}

// HAVE THE STYLE DICTIONARY CONFIG DYNAMICALLY GENERATED

StyleDictionaryPackage.registerFormat({
name: 'css/variables',
formatter: function (dictionary, config) {
return `${this.selector} {
${dictionary.allProperties.map(prop => ` --${prop.name}: ${prop.value};`).join('\n')}
}`
}
});
name: 'css/variables',
formatter: function (dictionary, config) {
return `${this.selector} {
${dictionary.allProperties
.map((prop) => ` --${prop.name}: ${prop.value};`)
.join('\n')}
}`;
},
});

//

function kebabIt(str) {
return str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.join('-')
.toLowerCase();
}
return str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.join('-')
.toLowerCase();
}

function getBasePxFontSize(options) {
function getBasePxFontSize(options) {
return (options && options.basePxFontSize) || 16;
}

Expand All @@ -37,42 +81,63 @@ function fontPxToRem(token, options) {
}

StyleDictionaryPackage.registerTransform({
name: 'size/pxToRem',
type: 'value',
matcher: (token) => ['fontSizes'].includes(token.type),
transformer: (token, options) => fontPxToRem(token, options)
})
//
name: 'size/pxToRem',
type: 'value',
matcher: (token) => ['fontSizes'].includes(token.type),
transformer: (token, options) => fontPxToRem(token, options),
});
//
StyleDictionaryPackage.registerTransform({
name: 'sizes/px',
type: 'value',
matcher: function(prop) {
// You can be more specific here if you only want 'em' units for font sizes
return ["fontSize", "spacing", "borderRadius", "borderWidth", "sizing"].includes(prop.attributes.category);
},
transformer: function(prop) {
// You can also modify the value here if you want to convert pixels to ems
return parseFloat(prop.original.value) + 'px';
}
});
name: 'sizes/px',
type: 'value',
matcher: function (prop) {
// You can be more specific here if you only want 'em' units for font sizes
return [
'fontSize',
'spacing',
'borderRadius',
'borderWidth',
'sizing',
].includes(prop.attributes.category);
},
transformer: function (prop) {
// You can also modify the value here if you want to convert pixels to ems
return parseFloat(prop.original.value) + 'px';
},
});

function getStyleDictionaryConfig(theme) {
return {
"source": [
`input/${theme}.json`,
],
"platforms": {
"web": {
"transforms":
["attribute/cti", "name/cti/kebab", "sizes/px", "size/pxToRem"],
"buildPath": `output/`,
"files": [{
"destination": `${theme}.css`,
"format": "css/variables",
"selector": `.${theme}-theme`
}]
}
}
source: [`input/${theme}.json`],
platforms: {
web: {
transforms: [
'attribute/cti',
'name/cti/kebab',
'sizes/px',
'size/pxToRem',
],
buildPath: `output/`,
files: [
{
destination: `${theme}.css`,
format: 'css/variables',
selector: `.${theme}-theme`,
},
],
},
scss: {
transformGroup: 'scss',
buildPath: `output/`,
files: [
{
destination: `${theme}.scss`,
format: 'scss/variables',
selector: `.${theme}-theme`,
},
],
},
},
};
}

Expand All @@ -81,19 +146,55 @@ console.log('Build started...');
// PROCESS THE DESIGN TOKENS FOR THE DIFFEREN BRANDS AND PLATFORMS

['base', 'brand-a', 'brand-b'].map(function (theme) {
console.log('\n==============================================');
console.log(`\nProcessing: [${theme}]`);

console.log('\n==============================================');
console.log(`\nProcessing: [${theme}]`);
const StyleDictionary = StyleDictionaryPackage.extend(
getStyleDictionaryConfig(theme),
);

const StyleDictionary = StyleDictionaryPackage.extend(getStyleDictionaryConfig(theme));
if (theme === 'base') {
// the original color properties
const colorProps = Object.entries(StyleDictionary.properties.brand);

StyleDictionary.buildPlatform('web');
for (const [key, prop] of colorProps) {
// convert any color into a hsl object
const hsl = tinycolor(prop.value).toHsl();

console.log('\nEnd processing');
})
// extract the original lightness before we manipulate it
const { l: originalLightness } = hsl;
let lightness = originalLightness;

console.log('\n==============================================');
console.log('\nBuild completed!');
// add a property for the original shade
cloneShade({ hsl, lightness, key, prop });

// add a property for a lighter shade (higher lightness percentage)
// until another lighter shade would go above 99%
while (lightness + OFFSET < 1) {
lightness = lightness + OFFSET;
cloneShade({ hsl, lightness, key, prop });
}

// reset lightness to original value
lightness = originalLightness;

// add a property for a darker shade (lower lightness percentage)
// until another darker shade would go below 1%
while (lightness - OFFSET > 0) {
lightness = lightness - OFFSET;
cloneShade({ hsl, lightness, key, prop });
}
}

// replace the original color properties with all the new shade properties
StyleDictionary.properties.brand = shades;
}

StyleDictionary.buildPlatform('web');
StyleDictionary.buildPlatform('scss');

console.log('\nEnd processing');
});

console.log('\n==============================================');
console.log('\nBuild completed!');
Loading