Skip to content

Commit b18bbce

Browse files
committed
chore(ci): incorporate tokens & ui-icons in compare reports
1 parent 6e4eddf commit b18bbce

File tree

7 files changed

+187
-151
lines changed

7 files changed

+187
-151
lines changed

.github/workflows/compare-results.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ jobs:
7777
uses: actions/download-artifact@v3
7878
with:
7979
name: ubuntu-latest-node18-compiled-assets-${{ inputs.head-sha }}
80-
path: ${{ github.workspace }}/${{ inputs.head-sha }}/components
80+
path: ${{ github.workspace }}/${{ inputs.head-sha }}
8181

8282
- name: Download build artifacts for base ${{ inputs.base-sha }}
8383
uses: actions/download-artifact@v3
8484
with:
8585
name: ubuntu-latest-node18-compiled-assets-${{ inputs.base-sha }}
86-
path: ${{ github.workspace }}/${{ inputs.base-sha }}/components
86+
path: ${{ github.workspace }}/${{ inputs.base-sha }}
8787

8888
- name: Compare compiled output file size
8989
id: compare
@@ -92,7 +92,10 @@ jobs:
9292
with:
9393
path: ${{ github.workspace }}/${{ inputs.head-sha }}/
9494
diff-path: ${{ github.workspace }}/${{ inputs.base-sha }}/
95-
file-glob-pattern: components/*/dist/**
95+
file-glob-pattern: |
96+
components/*/dist/**
97+
tokens/dist/**
98+
ui-icons/dist/**
9699
token: ${{ secrets.GITHUB_TOKEN }}
97100

98101
fetch-build-artifacts:
@@ -161,16 +164,13 @@ jobs:
161164
uses: actions/cache@v3
162165
with:
163166
path: |
164-
components/*/dist/**
167+
components/*/dist/**
168+
tokens/dist/**
169+
ui-icons/dist/**
165170
key: ${{ steps.derive-key.outputs.key }}
166171

167-
- name: Build components
168-
if: ${{ matrix.branch == inputs.base-sha && steps.cache-build.outputs.cache-hit != 'true' }}
169-
shell: bash
170-
run: yarn build
171-
172-
- name: Build components
173-
if: ${{ matrix.branch == inputs.head-sha && steps.cache-build.outputs.cache-hit != 'true' }}
172+
- name: Build
173+
if: ${{ steps.cache-build.outputs.cache-hit != 'true' }}
174174
shell: bash
175175
run: yarn build
176176

@@ -179,7 +179,9 @@ jobs:
179179
uses: actions/upload-artifact@v3
180180
with:
181181
path: |
182-
${{ github.workspace }}/components/*/dist/**
182+
${{ github.workspace }}/components/*/dist/**
183+
${{ github.workspace }}/tokens/dist/**
184+
${{ github.workspace }}/ui-icons/dist/**
183185
name: ${{ steps.derive-key.outputs.key }}
184186
# this is important, it lets us catch if the build failed silently
185187
# by alterting us that no compiled assets were generated

.storybook/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const componentPkgs = readdirSync(componentsPath, {
88
.map((dirent) => dirent.name);
99
module.exports = {
1010
stories: [
11-
"../components/*/stories/*.stories.mdx",
1211
"../components/*/stories/*.stories.@(js|jsx|ts|tsx)",
1312
],
1413
rootDir: "../",

components/icon/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# `@spectrum-css/icon`
22

3-
The icons component contains all UI icons used for components as well as the CSS for UI and workflow icons.
3+
The icons component contains the CSS for UI and workflow icons.

tasks/clean-up-after-migration.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ test -d "components/vars" && rm -rf components/vars
2424
test -d "components/expressvars" && rm -rf components/expressvars
2525
test -d "components/tokens" && rm -rf components/tokens
2626

27+
# Migrated icons assets
28+
test -d "components/icon/combined" && rm -rf components/icon/combined
29+
test -d "components/icon/large" && rm -rf components/icon/large
30+
test -d "components/icon/medium" && rm -rf components/icon/medium
31+
2732
# test -d "plugins/legacy-postcss-dropdupedvars" && rm -rf plugins/legacy-postcss-dropdupedvars
2833
# test -d "plugins/legacy-postcss-dropunusedvars" && rm -rf plugins/legacy-postcss-dropunusedvars
2934
# test -d "plugins/postcss-combininator" && rm -rf plugins/postcss-combininator

ui-icons/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# @adobe/spectrum-css-ui-icons
2+
3+
> The source for UI iconography used in Spectrum CSS
4+
5+
This package uses SVGO to process SVGs and combines them into several sprite sheets for use in this and other projects.
6+
7+
_Please do not import assets from the source directory as these are fluid and not part of the semantic publishing contract. Instead, use the `dist` directory._
8+
9+
## Installation
10+
11+
```sh
12+
yarn add -DW @adobe/spectrum-css-ui-icons
13+
```
14+
15+
## Usage
16+
17+
### SVGs
18+
19+
SVGs are available in the `dist` directory. They are organized by size. The `dist` directory contains the following:
20+
21+
- `medium`: assets to be used in desktop display formats
22+
- `large`: assets to be used in mobile display formats
23+
- `combined`: assets to be used in products requiring both desktop and mobile display icons to swap quickly or be used in parallel
24+
- `spectrum-css-icons.svg`: a single sprite sheet containing all icons
25+
- `spectrum-css-icons-medium.svg`: a single sprite sheet for medium icons
26+
- `spectrum-css-icons-large.svg`: a single sprite sheet for large icons
27+
28+
### CSS
29+
30+
CSS for the icons is available from the `@spectrum-css/icon` package. See the [Icon documentation](../components/icon/README.md) for more information.

ui-icons/index.js

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,118 @@
1-
const fs = require("fs");
1+
const fs = require('fs');
22
const fsp = fs.promises;
3-
const path = require("path");
3+
const path = require('path');
44

5-
const fg = require("fast-glob");
6-
const { optimize } = require("svgo");
7-
const combine = require("svgcombiner");
8-
const svgstore = require("svgstore");
5+
const fg = require('fast-glob');
6+
const { optimize } = require('svgo');
7+
const combine = require('svgcombiner');
8+
const svgstore = require('svgstore');
99

1010
async function setupIconStores() {
11-
const stores = new Map();
12-
stores.set("all", svgstore());
13-
14-
for (const variant of await fg(["*"], {
15-
cwd: __dirname,
16-
ignore: ["dist", "node_modules"],
17-
onlyDirectories: true,
18-
})) {
19-
stores.set(variant, svgstore());
20-
}
21-
22-
return stores;
11+
const stores = new Map();
12+
stores.set('all', svgstore());
13+
14+
for (const variant of await fg(['*'], {
15+
cwd: __dirname,
16+
ignore: ['dist', 'node_modules'],
17+
onlyDirectories: true,
18+
})) {
19+
stores.set(variant, svgstore());
20+
}
21+
22+
return stores;
2323
}
2424

2525
async function main() {
26-
// Not using svgo's loadConfig because it doesn't support dynamic config files
27-
const getSvgoConfig = require("./svgo.config.js");
26+
// Not using svgo's loadConfig because it doesn't support dynamic config files
27+
const getSvgoConfig = require('./svgo.config.js');
2828

29-
// Hash to hold all icons arranged by processed name
30-
const icons = new Map();
31-
const stores = await setupIconStores();
32-
const variants = [...stores.keys()].filter((key) => key !== "all");
33-
34-
const files = await fg([`{${variants.join(",")}}/*.svg`], {
35-
cwd: __dirname,
36-
onlyFiles: true,
37-
});
29+
// Hash to hold all icons arranged by processed name
30+
const icons = new Map();
31+
const stores = await setupIconStores();
32+
const variants = [...stores.keys()].filter((key) => key !== 'all');
3833

39-
const promises = [];
40-
for (const file of files) {
41-
const assetName = path.basename(file, ".svg");
34+
const files = await fg([`{${variants.join(',')}}/*.svg`], {
35+
cwd: __dirname,
36+
onlyFiles: true,
37+
});
4238

43-
// Capture metadata about the icon from the path and filename
44-
const variant = path.dirname(file);
39+
const promises = [];
40+
for (const file of files) {
41+
const assetName = path.basename(file, '.svg');
4542

46-
// Read in the SVG contents
47-
const contents = await fsp.readFile(file, "utf-8");
48-
const result = optimize(contents, getSvgoConfig({ clean: true }));
43+
// Capture metadata about the icon from the path and filename
44+
const variant = path.dirname(file);
4945

50-
icons.set(assetName, {
51-
...(icons.has(assetName) ? icons.get(assetName) : {}),
52-
[variant]: result.data,
53-
});
46+
// Read in the SVG contents
47+
const contents = await fsp.readFile(file, 'utf-8');
48+
const result = optimize(contents, getSvgoConfig({ clean: true }));
5449

55-
stores.get(variant).add(assetName, result.data);
50+
icons.set(assetName, {
51+
...(icons.has(assetName) ? icons.get(assetName) : {}),
52+
[variant]: result.data,
53+
});
5654

57-
const dest = path.join(__dirname, "dist", file);
58-
if (!fs.existsSync(path.dirname(dest))) {
59-
fs.mkdirSync(path.dirname(dest), { recursive: true });
60-
}
55+
stores.get(variant).add(assetName, result.data);
6156

62-
promises.push(fsp.writeFile(dest, result.data));
57+
const dest = path.join(__dirname, 'dist', file);
58+
if (!fs.existsSync(path.dirname(dest))) {
59+
fs.mkdirSync(path.dirname(dest), { recursive: true });
6360
}
6461

65-
// Wait for all the SVG content to be read in and processed before continuing
66-
await Promise.all(promises);
62+
promises.push(fsp.writeFile(dest, result.data));
63+
}
6764

68-
if (icons.size === 0) return;
65+
// Wait for all the SVG content to be read in and processed before continuing
66+
await Promise.all(promises);
6967

70-
// For each entry in the map, combine the SVG variants into a single SVG file with multiple symbols
71-
promises.length = 0;
72-
[...icons.entries()].map(([iconName, data]) => {
73-
// Combine the SVG variants into a single SVG file with multiple symbols
74-
const contents = combine(iconName, data);
68+
if (icons.size === 0) return;
7569

76-
// Add the combined SVG to the "all" store so we can generate a single SVG file with all icons
77-
stores.get("all").add(iconName, contents);
70+
// For each entry in the map, combine the SVG variants into a single SVG file with multiple symbols
71+
promises.length = 0;
72+
[...icons.entries()].map(([iconName, data]) => {
73+
// Combine the SVG variants into a single SVG file with multiple symbols
74+
const contents = combine(iconName, data);
7875

79-
// Write the combined SVG to the dist folder
80-
const destPath = path.join(__dirname, "dist/combined");
81-
if (!fs.existsSync(destPath)) fs.mkdirSync(destPath, { recursive: true });
76+
// Add the combined SVG to the "all" store so we can generate a single SVG file with all icons
77+
stores.get('all').add(iconName, contents);
8278

83-
promises.push(fsp.writeFile(path.join(destPath, `${iconName}.svg`), optimize(contents, getSvgoConfig())?.data));
84-
});
79+
// Write the combined SVG to the dist folder
80+
const destPath = path.join(__dirname, 'dist/combined');
81+
if (!fs.existsSync(destPath)) fs.mkdirSync(destPath, { recursive: true });
8582

86-
// Finally, we write out the stores to disk
87-
for (const [identifier, store] of stores.entries()) {
88-
const isFullSet = identifier === "all";
89-
const filename = isFullSet ? "spectrum-css-icons" : `spectrum-css-icons-${identifier}`;
90-
const dest = path.join(__dirname, `dist/${filename}.svg`);
91-
const config = getSvgoConfig(
92-
isFullSet
93-
? {
94-
idPrefix: "spectrum-css-icon",
95-
removeViewBox: true,
96-
}
97-
: {},
98-
);
99-
100-
const result = optimize(store.toString(), config);
101-
102-
if (!result?.data) continue;
103-
104-
promises.push(fsp.writeFile(dest, result?.data));
105-
}
83+
promises.push(fsp.writeFile(path.join(destPath, `${iconName}.svg`), optimize(contents, getSvgoConfig())?.data));
84+
});
85+
86+
// Finally, we write out the stores to disk
87+
for (const [identifier, store] of stores.entries()) {
88+
const isFullSet = identifier === 'all';
89+
const filename = isFullSet ? 'spectrum-css-icons' : `spectrum-css-icons-${identifier}`;
90+
const dest = path.join(__dirname, `dist/${filename}.svg`);
91+
const config = getSvgoConfig(
92+
isFullSet
93+
? {
94+
idPrefix: 'spectrum-css-icon',
95+
removeViewBox: true,
96+
}
97+
: {},
98+
);
99+
100+
const result = optimize(store.toString(), config);
106101

107-
return Promise.all(promises);
102+
if (!result?.data) continue;
103+
104+
promises.push(fsp.writeFile(dest, result?.data));
105+
}
106+
107+
return Promise.all(promises);
108108
}
109109

110110
main()
111-
.then(() => {
112-
console.log("✔ Icons generated successfully.");
113-
process.exit(0);
114-
})
115-
.catch((e) => {
116-
console.error(e);
117-
process.exit(1);
118-
});
111+
.then(() => {
112+
console.log('✔ Icons generated successfully.');
113+
process.exit(0);
114+
})
115+
.catch((e) => {
116+
console.error(e);
117+
process.exit(1);
118+
});

0 commit comments

Comments
 (0)