-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ffe-symbols-react): wip legg til typings for symbol
- Loading branch information
1 parent
48137fe
commit 180673a
Showing
3 changed files
with
1,046 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/ffe-symbols-react/scripts/generateSymbolTypings.js
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,42 @@ | ||
/* | ||
This function is manually triggered, and will fetch all the names of the folders in the "symbols/web" folder | ||
in the official material design icons repository. | ||
The names are gathered in an array that is used for typings in the symbols component. | ||
Important to only run this when we update the icon-font files, as we might sometimes be out of sync with whats | ||
the latest in material icons. | ||
*/ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const fetchAllSymbolNames = () => { | ||
const reqUrl = | ||
'https://api.github.com/repos/google/material-design-icons/contents/symbols/web'; | ||
|
||
return fetch(reqUrl) | ||
.then(response => { | ||
if (response.ok) return response.json(); | ||
else { | ||
throw new Error( | ||
'Failed to fetch the content of the repository', | ||
); | ||
} | ||
}) | ||
.then(data => { | ||
const folderNames = data | ||
.filter(item => item.type === 'dir') | ||
.map(item => item.name); | ||
|
||
let fileContent = `const symbolNames = ' + JSON.stringify(folderNames) + ' as const; | ||
export type SymbolName = (typeof symbolNames)[number];`; | ||
fs.writeFileSync( | ||
'../src/typings/symbolNames.ts', | ||
'export type SymbolName = ' + JSON.stringify(folderNames), | ||
); | ||
|
||
return folderNames; | ||
}) | ||
.catch(error => console.error(error)); | ||
}; | ||
|
||
fetchAllSymbolNames(); |
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
Oops, something went wrong.