-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Split up mdi icons #4379
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
Merged
Merged
Split up mdi icons #4379
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d75130c
WIP: Split up mdi icons
bramkragten fa12d81
Update package.json
bramkragten 7ec765d
Comments
bramkragten e99d50f
Split icons by size
bramkragten 5381278
Update ha-icon.ts
bramkragten a4b2caa
Remove iconsets
bramkragten 39c24ea
Clean up
bramkragten 0d6b659
Update ci.yaml
bramkragten 4158f17
Last one
bramkragten 3575b4a
Replace all icons with `ha-icon`
bramkragten 65e44aa
Fixes and cleanup of replace
bramkragten a9b1fca
Update hui-media-control-card.ts
bramkragten c6243a5
Optimize debounced caching
bramkragten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,109 @@ | ||
| const gulp = require("gulp"); | ||
| const path = require("path"); | ||
| const fs = require("fs"); | ||
| const hash = require("object-hash"); | ||
|
|
||
| const ICON_PACKAGE_PATH = path.resolve( | ||
| __dirname, | ||
| "../../node_modules/@mdi/svg/" | ||
| ); | ||
| const META_PATH = path.resolve(ICON_PACKAGE_PATH, "meta.json"); | ||
| const ICON_PATH = path.resolve(ICON_PACKAGE_PATH, "svg"); | ||
| const OUTPUT_DIR = path.resolve(__dirname, "../../build/mdi"); | ||
|
|
||
| const encoding = "utf8"; | ||
|
|
||
| const getMeta = () => { | ||
| const file = fs.readFileSync(META_PATH, { encoding }); | ||
| const meta = JSON.parse(file); | ||
| return meta.map((icon) => { | ||
| const svg = fs.readFileSync(`${ICON_PATH}/${icon.name}.svg`, { | ||
| encoding, | ||
| }); | ||
| return { path: svg.match(/ d="([^"]+)"/)[1], name: icon.name }; | ||
| }); | ||
| }; | ||
|
|
||
| const splitBySize = (meta) => { | ||
| const chunks = []; | ||
| const CHUNK_SIZE = 100000; | ||
|
|
||
| let curSize = 0; | ||
| let startKey; | ||
| let icons = []; | ||
|
|
||
| Object.values(meta).forEach((icon) => { | ||
| if (startKey === undefined) { | ||
| startKey = icon.name; | ||
| } | ||
| curSize += icon.path.length; | ||
| icons.push(icon); | ||
| if (curSize > CHUNK_SIZE) { | ||
| chunks.push({ | ||
| startKey, | ||
| endKey: icon.name, | ||
| icons, | ||
| }); | ||
| curSize = 0; | ||
| startKey = undefined; | ||
| icons = []; | ||
| } | ||
| }); | ||
|
|
||
| chunks.push({ | ||
| startKey, | ||
| icons, | ||
| }); | ||
|
|
||
| return chunks; | ||
| }; | ||
|
|
||
| const findDifferentiator = (curString, prevString) => { | ||
| for (let i = 0; i < curString.length; i++) { | ||
| if (curString[i] !== prevString[i]) { | ||
| return curString.substring(0, i + 1); | ||
| } | ||
| } | ||
| console.error("Cannot find differentiator", curString, prevString); | ||
| return undefined; | ||
| }; | ||
|
|
||
| gulp.task("gen-icons-json", (done) => { | ||
| const meta = getMeta(); | ||
| const split = splitBySize(meta); | ||
|
|
||
| if (!fs.existsSync(OUTPUT_DIR)) { | ||
| fs.mkdirSync(OUTPUT_DIR, { recursive: true }); | ||
| } | ||
| const manifest = []; | ||
|
|
||
| let lastEnd; | ||
| split.forEach((chunk) => { | ||
| let startKey; | ||
| if (lastEnd === undefined) { | ||
| chunk.startKey = undefined; | ||
| startKey = undefined; | ||
| } else { | ||
| startKey = findDifferentiator(chunk.startKey, lastEnd); | ||
| } | ||
| lastEnd = chunk.endKey; | ||
|
|
||
| const output = {}; | ||
| chunk.icons.forEach((icon) => { | ||
| output[icon.name] = icon.path; | ||
| }); | ||
| const filename = hash(output); | ||
| manifest.push({ start: startKey, file: filename }); | ||
| fs.writeFileSync( | ||
| path.resolve(OUTPUT_DIR, `${filename}.json`), | ||
| JSON.stringify(output) | ||
| ); | ||
| }); | ||
|
|
||
| fs.writeFileSync( | ||
| path.resolve(OUTPUT_DIR, "iconMetadata.json"), | ||
| JSON.stringify(manifest) | ||
| ); | ||
|
|
||
| done(); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think that it could happen, but we should probably raise here to make sure that it breaks.