Skip to content

Commit 6352c5b

Browse files
author
Stephanie Zeng
committed
feat: convert vector to svg
1 parent 7514937 commit 6352c5b

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import fs from "fs/promises";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
4+
5+
const cwd = path.dirname(fileURLToPath(import.meta.url));
6+
7+
const readVectorFile = async (vectorFile) => {
8+
const vectorData = await fs.readFile(vectorFile, "utf8");
9+
return JSON.parse(vectorData);
10+
};
11+
12+
const generateIconFromVectors = async (vectorData) => {
13+
vectorData.forEach(async (icon) => {
14+
const iconName = `${icon.name}_${icon.properties.Size}_${icon.properties['Icon type']}_color${icon.properties['Icon colour']}.svg`;
15+
const iconFile = path.join(cwd, 'svg', iconName)
16+
await fs
17+
.writeFile(iconFile, icon.source.replace('\n', '').replace('\'', ''))
18+
.then(() => console.log(`SVG ${iconName} created`))
19+
.catch((err) => console.error(err));
20+
});
21+
}
22+
23+
(async function main() {
24+
const vectorFile = path.resolve(cwd, ".", "styles", "vector.json");
25+
const vectorData = await readVectorFile(vectorFile);
26+
console.log(vectorData);
27+
await generateIconFromVectors(vectorData);
28+
})();

packages/foundations/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
"version": "4.1.0",
44
"description": "",
55
"main": "index.js",
6+
"type": "module",
67
"exports": {
78
".": "./index.ts",
89
"./styles": "./index.css"
910
},
1011
"scripts": {
1112
"build": "radius-toolkit generate tokens.json -o styles/index.css",
1213
"build:custom": "radius-toolkit generate tokens.json -c myCustomTemplate -T ./templates -o styles/vector.json",
13-
"build:tailwind": "radius-toolkit generate tokens.json -t tailwind"
14+
"build:tailwind": "radius-toolkit generate tokens.json -t tailwind",
15+
"g": "node ./generate-icons.mjs"
1416
},
1517
"keywords": [],
1618
"author": "",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"name": "Box - Moving",
4+
"properties": {
5+
"Size": "S",
6+
"Icon type": "Stroke",
7+
"Icon colour": "Default",
8+
"Frame type": "None",
9+
"Frame fill": "None"
10+
},
11+
"source": "<svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M2.60817 8.19257V4.34122M2.60817 4.34122L8.77033 0.875L11.8514 2.60811M2.60817 4.34122L5.68925 6.21666M14.9325 4.34122V11.5304L8.51357 15.125M14.9325 4.34122L8.51357 7.93581M14.9325 4.34122L11.8514 2.60811M8.51357 15.125L6.45952 13.8412M8.51357 15.125V7.93581M8.51357 7.93581L5.68925 6.21666M5.68925 6.21666L11.8514 2.60811M1.06763 11.7872L4.91898 9.47635M1.06763 14.3547L6.45952 11.0169\" stroke=\"#00549A\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>\n"
12+
},
13+
{
14+
"name": "Box - Moving",
15+
"properties": {
16+
"Size": "M",
17+
"Icon type": "Stroke",
18+
"Icon colour": "Default",
19+
"Frame type": "None",
20+
"Frame fill": "None"
21+
},
22+
"source": "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M3.48651 12.3041V6.22297M3.48651 6.22297L13.2162 0.75L18.0811 3.48649M3.48651 6.22297L8.35137 9.1842M22.946 6.22297V17.5743L12.8108 23.25M22.946 6.22297L12.8108 11.8986M22.946 6.22297L18.0811 3.48649M12.8108 23.25L9.56759 21.223M12.8108 23.25V11.8986M12.8108 11.8986L8.35137 9.1842M8.35137 9.1842L18.0811 3.48649M1.05408 17.9797L7.13516 14.3311M1.05408 22.0338L9.56759 16.7635\" stroke=\"#00549A\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>\n"
23+
}
24+
]
Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Loading

packages/foundations/templates/myCustomTemplate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import type { TemplateModule } from "radius-toolkit";
33
export default {
44
name: "my-custom-template",
55
render: ({ layers, vectors }, options) => {
6+
console.log("data", JSON.stringify(layers, null, 2));
67
const transformed = vectors?.map(({ name, properties, source }) => {
78
return {
89
name,
9-
properties: JSON.stringify(properties),
10+
properties,
1011
source,
1112
};
1213
});

0 commit comments

Comments
 (0)