-
Notifications
You must be signed in to change notification settings - Fork 14
77 lines (67 loc) · 2.69 KB
/
build-tokens.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Build Tokens
on:
pull_request:
types: [opened, synchronize, edited, reopened]
paths:
- 'packages/tokens/**'
jobs:
build:
name: Build Tokens
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup-pnpm
- name: Install dependencies
run: pnpm --filter design-system-tokens... install
- name: Build tokens & dependencies
run: pnpm --filter design-system-tokens... build
- name: Create Summary
id: summary
uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
const path = require('path')
const inputFileNames = fs.readdirSync('packages/tokens/tokensstudio-generated')
const inputFiles = inputFileNames.map(fileName => ({
type: path.extname(fileName).replace(/^\./, ''),
name: fileName,
content: fs.readFileSync(`packages/tokens/tokensstudio-generated/${fileName}`, 'utf8')
}))
const outputOrder = [
'index.scss',
'core.scss',
'mode.scss',
'device.scss',
'channel.scss',
'theme.scss',
'components.scss',
]
const outputFileNames = fs.readdirSync('packages/tokens/dist')
const outputFiles = outputFileNames
.map(fileName => ({
type: path.extname(fileName).replace(/^\./, ''),
name: fileName,
content: fs.readFileSync(`packages/tokens/dist/${fileName}`, 'utf8')
}))
.map(({ type, name, content }) => {
if (type === 'scss') content = content.replaceAll('\n\n', '\n \n').replaceAll('$', '$').replaceAll(' ', ' ')
return { type, name, content }
})
.sort((a, b) => (outputOrder.includes(a.name) ? outputOrder.indexOf(a.name) : 1000) - (outputOrder.includes(b.name) ? outputOrder.indexOf(b.name) : 1000))
return `# Token Build
## Input
${inputFiles.map(({ type, name, content }) => `<details>
<summary><code>${name}</code></summary>
<pre lang="${type}">${content}</pre>
</details>`).join('\n')}
## Output
${outputFiles.map(({ type, name, content }) => `<details>
<summary><code>${name}</code></summary>
<pre lang="${type}">${content}</pre>
</details>`).join('\n')}
`
- name: Output Summary
run: echo -e ${{ steps.summary.outputs.result }} >> $GITHUB_STEP_SUMMARY