-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: enabled icon subset completely * chore: updated api * chore: updated from main * fix: issue with tests in cicd by installing fonttools * Update IconSubset.md * Update .github/workflows/01-test.yml Co-authored-by: Maximilian Franzke <[email protected]> * Update docs/IconSubset.md Co-authored-by: Maximilian Franzke <[email protected]> * Update docs/IconSubset.md Co-authored-by: Maximilian Franzke <[email protected]> * Update src/commands/icon-subset/data.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update src/commands/icon-subset/helpers/filter-icons.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update src/commands/icon-subset/helpers/ttx.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update src/commands/icon-subset/helpers/ttx.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update src/commands/icon-subset/helpers/ttx.ts Co-authored-by: Maximilian Franzke <[email protected]> * chore: update from main * refactor: replaced Src by Source * Update src/commands/icon-subset/helpers/filter-icons.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update docs/IconSubset.md Co-authored-by: Maximilian Franzke <[email protected]> * Update src/commands/icon-subset/helpers/filter-icons.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update src/commands/icon-subset/helpers/filter-icons.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update src/utils/shared.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update docs/API.md Co-authored-by: Maximilian Franzke <[email protected]> * Update test/icon-subset/simple/simple.test.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update ttx.ts * Update test/icon-subset/config/config.test.ts Co-authored-by: Maximilian Franzke <[email protected]> * Update src/commands/icon-subset/index.ts Co-authored-by: Maximilian Franzke <[email protected]> --------- Co-authored-by: Maximilian Franzke <[email protected]>
- Loading branch information
Showing
23 changed files
with
611 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,4 @@ yarn.lock | |
/fonts/ | ||
/test/**/fonts/ | ||
**/generated/ | ||
**/*.tmp.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Icon subset | ||
|
||
Remove unused icons from your icon font (`woff2`) to reduce file size. | ||
|
||
> **Note:** Requires https://github.com/fonttools/fonttools to be installed. Most of the time you need it in production. In this case look at [CI/CD section](#cicd). | ||
## Requirements - local | ||
|
||
To subset icon fonts we use [fonttools](https://github.com/fonttools/fonttools). To use the tools you need python installed: | ||
|
||
1. Install [python](https://docs.python-guide.org/starting/installation/#installation) and [ensure that you can run Python from the command line](https://packaging.python.org/en/latest/tutorials/installing-packages/#ensure-you-can-run-python-from-the-command-line) | ||
2. Install fonttools: `pip3 install fonttools` | ||
3. Install brotli: `pip3 install brotli` | ||
|
||
## Use | ||
|
||
### Config | ||
|
||
Create a new file `icon-subset.json` with this content: | ||
|
||
```json | ||
{ | ||
"src": "./my-path-to/icons", | ||
"safeList": ["airplane", "bell"] | ||
} | ||
``` | ||
|
||
### JS/TS | ||
|
||
Here is an example for a JS file `index.(js|ts)`: | ||
|
||
```js | ||
// index.(js|ts) | ||
import { iconSubset } from "@db-ux/icon-font-tools/dist/commands/icon-subset"; | ||
|
||
void iconSubset({ | ||
src: "./my-path-to/icons", | ||
safeList: ["airplane", "bell"], | ||
}); | ||
``` | ||
|
||
### CLI | ||
|
||
Example: | ||
|
||
```shell | ||
npx @db-ux/icon-font-tools icon-subset --src ./my-path-to/icons --safeList airplane --safeList bell | ||
``` | ||
|
||
For more information run: | ||
|
||
```shell | ||
npx @db-ux/icon-font-tools icon-subset --help | ||
``` | ||
|
||
## CI/CD | ||
|
||
In most cases you want some `build` job which produces some `dist` folder. We can optimize this `dist` folder before any e2e tests or deployment like this: | ||
|
||
### GitHub Actions | ||
|
||
The default GitHub image is already bundled with `nodejs` and `python`. You can use the following snippet to install the required tools: | ||
|
||
```yaml | ||
jobs: | ||
icon-subset: | ||
name: 🤓🔪 Icon subset | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: ⏬ Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: ⏬ Install fonttools | ||
run: | | ||
pip3 install fonttools brotli | ||
fonttools --help | ||
- name: 🏃🏃➡️ Run Icon subset | ||
run: npx @db-ux/icon-font-tools icon-subset | ||
``` | ||
### GitLab CI | ||
```yaml | ||
stages: | ||
- post_build | ||
|
||
post_build: | ||
stage: post_build | ||
image: nikolaik/python-nodejs:latest | ||
before_script: | ||
- pip3 install fonttools brotli | ||
- fonttools --help | ||
script: | ||
- npx @db-ux/icon-font-tools icon-subset | ||
artifacts: | ||
paths: | ||
- dist # Your dist/build folder | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { IconSubsetConfigType, iconSubsetOptions } from "./data"; | ||
import { startConfigProcess } from "../../utils/config-process"; | ||
import { ICON_SUBSET_COMMAND } from "../../data"; | ||
import { startInquirerProcess } from "../../utils/inquirer-process"; | ||
import { iconSubset } from "./index"; | ||
|
||
export const iconSubsetAction = async (passedConfig: IconSubsetConfigType) => { | ||
let config = await startConfigProcess(ICON_SUBSET_COMMAND, passedConfig); | ||
|
||
config = await startInquirerProcess<IconSubsetConfigType>( | ||
config, | ||
iconSubsetOptions, | ||
); | ||
|
||
return await iconSubset(config); | ||
}; |
Oops, something went wrong.