Skip to content
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

Add build svg and workflows #6

Merged
merged 5 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build TMIcons

on: push

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

git status
# - 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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-terser": "^0.4.4",
"@trendmicro/babel-config": "^1.0.0-alpha",
"ejs": "^3.1.10",
"cross-env": "^7.0.3",
"del-cli": "^3.0.1",
"ejs": "^3.1.5",
"lodash.sortby": "^4.7.0",
"rollup": "^2.35.1"
},
"dependencies": {
"lodash": "^4.17.21"
}
}
50 changes: 50 additions & 0 deletions script/buildSVGIcons.js
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);
});
Loading
Loading