-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(icons): port to ES module, formating.
Add changeset to trigger release
- Loading branch information
Showing
7 changed files
with
81 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@itk-viewer/icons': patch | ||
--- | ||
|
||
Add @itk-viewer/icons package. |
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 |
---|---|---|
|
@@ -25,4 +25,3 @@ revision `f6b4fa13c8`, before they were extracted. | |
|
||
## Icon Renderings | ||
|
||
|
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env node | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import glob from 'glob'; | ||
import svgToMiniDataURI from 'mini-svg-data-uri'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
try { | ||
fs.mkdirSync('dist'); | ||
} catch (err) { | ||
if (err.code !== 'EEXIST') throw err; | ||
} | ||
|
||
const svgFiles = glob.sync(path.join('src', '*.svg')); | ||
const icons = new Map(); | ||
svgFiles.forEach((svgFile) => { | ||
const contents = fs.readFileSync(svgFile, { encoding: 'utf8', flag: 'r' }); | ||
const optimizedSVGDataURI = svgToMiniDataURI(contents); | ||
const moduleContents = `const optimizedSVGDataUri = "${optimizedSVGDataURI}" | ||
export default optimizedSVGDataUri | ||
`; | ||
const basename = path.basename(svgFile, '.svg'); | ||
icons.set(`${basename}IconDataUri`, { | ||
modulePath: `./${basename}.svg.uri.js`, | ||
svgFile, | ||
}); | ||
fs.writeFileSync(path.join('dist', `${basename}.svg.uri.js`), moduleContents); | ||
}); | ||
|
||
const indexFile = path.join('dist', 'index.js'); | ||
const indexFD = fs.openSync(indexFile, 'w'); | ||
for (const [varName, { modulePath }] of icons) { | ||
fs.writeSync( | ||
indexFD, | ||
`export { default as ${varName} } from "${modulePath}"\n`, | ||
); | ||
} | ||
fs.closeSync(indexFD); | ||
|
||
const readmeContents = fs.readFileSync(path.join(__dirname, 'README.md.in'), { | ||
encoding: 'utf8', | ||
flag: 'r', | ||
}); | ||
const readmeFD = fs.openSync(path.join(__dirname, 'README.md'), 'w'); | ||
fs.writeSync(readmeFD, readmeContents); | ||
|
||
fs.writeSync(readmeFD, '<table>\n'); | ||
for (const [varName, { svgFile }] of icons) { | ||
fs.writeSync(readmeFD, ' <tr>\n'); | ||
fs.writeSync(readmeFD, ` <th>${varName}</th>\n`); | ||
fs.writeSync( | ||
readmeFD, | ||
` <th><img src="${svgFile}" width="40" alt="${varName}"/></th>\n`, | ||
); | ||
fs.writeSync(readmeFD, ' </tr>\n'); | ||
} | ||
fs.writeSync(readmeFD, '</table>\n'); |
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.