-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add tonic ui icon builder (#4)
* feat: add TMIcon build workflow * fix * fix * fxi * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fic * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Joshua Tai <[email protected]>
- Loading branch information
Showing
5 changed files
with
842 additions
and
10 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,63 @@ | ||
name: Build TMIcons | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
update-file: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set up Node.js 20 | ||
uses: actions/setup-node@v3 | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Download font files | ||
run: | | ||
ls | ||
css_url="https://i.icomoon.io/public/a8317e20c1/TMIcons/style.css" | ||
css_file="style.css" | ||
dist_dir="dist/fonts" | ||
curl -o $css_file $css_url | ||
font_urls=$(grep -oP 'url\(\K[^)]+' style.css | sort -u) | ||
for url in $font_urls; do | ||
clean_url=$(echo $url | sed 's/[?#].*//') | ||
filename=$(basename "$clean_url") | ||
full_url=$(echo $url | sed "s/'//g" | sed 's/"//g') | ||
curl -o "$dist_dir/$filename" $full_url | ||
done | ||
rm $css_file | ||
echo "Font files downloaded successfully." | ||
- name: Build SVG files | ||
run: | | ||
node ./script/buildSVGIcons.js | ||
echo "SVG files built successfully." | ||
- name: Build Tonic UI icons data | ||
run: | | ||
npm i | ||
node ./script/build-icon-files.js | ||
# - name: Configure Git | ||
# run: | | ||
# git config --global user.name 'HIE UX Service' | ||
# git config --global user.email '[email protected]' | ||
|
||
# - name: Add changes | ||
# run: git add test.txt | ||
|
||
# - name: Commit changes | ||
# run: git commit -m "Add test.txt with dynamic content" | ||
|
||
# - name: Push changes | ||
# env: | ||
# GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
# run: git push origin dev |
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,50 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const svgGen = require('./svgGenerator'); | ||
const preferences = require("../data/Preferences.json"); | ||
const icons = require("../data/Icons.json"); | ||
const svgTpl = fs.readFileSync( | ||
path.join(__dirname, "..", "templates", "svg.tpl"), | ||
"utf8" | ||
); | ||
const targetDir = path.join(__dirname, '..', 'dist', 'svg'); | ||
const defaultColor = `rgb(${preferences.imagePref.color | ||
.toString(16) | ||
.match(/\w\w/gi) | ||
.map((color) => parseInt(color, 16)) | ||
.join(",")})`; | ||
const viewBox = preferences.fontPref.metrics.emSize; | ||
const files = fs.readdirSync(targetDir); | ||
files.forEach(file => { | ||
const filePath = path.join(targetDir, file); | ||
if (fs.lstatSync(filePath).isFile()) { | ||
fs.unlinkSync(filePath); | ||
} | ||
}); | ||
|
||
icons.sort(function (a, b) { | ||
if (a.name > b.name) return 1; | ||
if (a.name < b.name) return -1; | ||
return 0; | ||
}); | ||
|
||
icons.forEach((icon) => { | ||
const targetPath = path.join(targetDir, `${icon.name}.svg`); | ||
icon.width = icon.height = icon.grid; | ||
icon.svgPath = svgGen(icon.paths); | ||
const scale = icon.height / viewBox; | ||
icon.scaledPath = icon.svgPath.scale(scale); | ||
icon.scaledPathData = icon.scaledPath.getPathData(true); | ||
|
||
let svgContent = svgTpl.replace(/_viewBox/gi, icon.grid); | ||
let paths = []; | ||
svgContent = svgContent.replace(/_title/gi, icon.name); | ||
icon.paths.forEach((path, pathIndex) => { | ||
let attr = Object.assign({ fill: defaultColor }, icon.attrs[pathIndex]); | ||
let genAttrs = []; | ||
Object.keys(attr).forEach((key) => genAttrs.push(`${key}="${attr[key]}"`)); | ||
paths.push(`<path ${genAttrs.join(' ')} d="${icon.scaledPathData[pathIndex]}"></path>`); | ||
}); | ||
svgContent = svgContent.replace('<!--paths-->', paths.join('\n ')); | ||
fs.writeFileSync(targetPath, svgContent); | ||
}); |
Oops, something went wrong.