-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(spark-icons): add icon file builder scripts #133
Conversation
I ended up adding some more commits, notably upgrading SVGO to latest and converting our outputted files to be |
7c7b217
to
c687ef8
Compare
- attribution given - no modifications made to ensure working order, purely copy-paste
c687ef8
to
14791b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is dynamite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, impressive conversion here.
Nice work threading it all together.
2 of 4
Part of #73. Reviewable by commit.
In this step
The first commit copies everything, the second commit makes most of the changes. The rest are polishes / improvements.
Script copying
With future knowledge, I've copied all the files from Mui that we'll need to modify, and installed only the packages we'll need later on -- the files might reference things I haven't installed, that's okay, it's meant to be in a broken state the next PR can highlight the changes clearly.
I've given permalink attribution for everything (except
templateSvgIcon.tsx
, that needs to be unchanged because it's literally used as a template). Mui is open-source under the MIT-license, so this is permissible. I didn't copy the download script that would make the process completed automated because our icons come from Figma and aren't hosted on the web by anyone. But, Figma does have an API that we could leverage in the future to prevent manual intervention in future maintenance (see #131 for such improvements)Script modifying
As outlined in
BUILDER.md
, the manual export process should end with a directorylibs/spark-icons/svg-files
with three sub directoriesline/
,filled/
,duotone/
.default/renameFilter.js
is one of the first steps in generation. The file name becomesPascalCased.js
withsnake_case.svg
andWhatever - YouCallThis 2.svg
formats being transformed. I could only find one instance of an icon name starting with a number, which is renamed to its word equivalent -- variable names can't be numbers. The sub directory ofsvg-files/
that each file belongs to is also matched and added as a suffix to the filename (note, Line becomes the default).svg-files/line/Activity.svg -> src/Activity.js
svg-files/filled/Activity.svg -> src/ActivityFilled.js
svg-files/duotone/Activity.svg -> src/ActivityDuotone.js
Notable changes in
builder.js
are 1) stripping attributes our icons tend to come out with, that are unnecessary 2) altering thetransform
scaling logic to accept that our icon files aren't suffixed by_24px
(even though our icons are always 24px x 24px). Instead I implemented a dynamic algorithm to scale to variable width and height values inviewBox
(this will be useful in custom icons described in improvements here #131).babel.config.json
exists to be passed to the"src:icons"
script (seepackage.json
). The config is necessary to runbuilder.js
or it will produce errors about "es" modules, needing to mark "module" type and such.Installed only required packages.
> npm i -D @babel/cli @babel/node @babel/plugin-proposal-class-properties @babel/plugin-transform-runtime fs-extra glob mustache path rimraf svgo temp yargs
Later commits:
next
branch modifications, also includes some modifications/upgrades around the svgo usage).tsx
not.js