Skip to content

Commit

Permalink
Rewrite Icon Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-herkamp committed Jan 7, 2024
1 parent e0c9bda commit 8996e69
Show file tree
Hide file tree
Showing 15 changed files with 1,276 additions and 442 deletions.
63 changes: 0 additions & 63 deletions build.js

This file was deleted.

3 changes: 3 additions & 0 deletions buildTools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.vscode
test
12 changes: 12 additions & 0 deletions buildTools/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}
203 changes: 203 additions & 0 deletions buildTools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions buildTools/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@vue3-simple-icons/buildtools",
"description": "An example app created with Deno",
"type": "module",
"version": "0.0.0",
"scripts": {
"dev": "deno run --allow-all src/main.ts --target test",
"build": "deno run --allow-all src/main.ts --target ../src",
"format": "deno run -A npm:@biomejs/biome format src --write",
"lint": "deno run -A npm:@biomejs/biome lint src",
"check": "deno run -A npm:@biomejs/biome check --apply src"
},
"dependencies": {
"change-case": "^5.3.0",
"n2words": "^1.18.0",
"simple-icons": "^10.4.0"
},
"devDependencies": {
"@biomejs/biome": "1.4.1"
}
}
52 changes: 52 additions & 0 deletions buildTools/src/component_builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { getIconSlug } from "simple-icons/sdk";
import { Brand } from "./types.ts";
const componentScript = await Deno.readTextFile("template.vue");
import * as changeCase from "change-case";
import n2words from "n2words";

export function buildComponent(iconSVG: string): string {
const result = `
<template>
${iconSVG.replace(
/<svg([^>]+)>/,
'<svg :width="finalSize" :height="finalSize" role="img" viewBox="0 0 24 24" v-bind="$attrs" >'
)}
</template>
${componentScript}`;

return result;
}

/**
* If Brand.title is all AlphaNumeric characters and spaces convert to PascalCase
* If Brand.Title is not use Brand slug
* @param icon Brand
* @returns string
*
*/
export function getComponentName(icon: Brand): string {
if (icon.title.match(/^[a-zA-Z ]+$/)) {
if (icon.slug) {
const slug = changeCase.pascalCase(icon.slug);
console.info("Using slug for component name", slug);
return `${slug}Icon`;
}
const name = changeCase.pascalCase(icon.title);
return `${name}Icon`;
}
let title = getIconSlug(icon);
const beginningNumbers = icon.title.replace(/[^\d].*/, "");
if (beginningNumbers.length) {
const numberInEnglish = n2words(beginningNumbers, {
lang: "en",
})
.split(" ")
.filter((word) => word !== "and")
.join("-");

const numberSlug = `${numberInEnglish}-`;
title = title.replace(beginningNumbers, numberSlug);
}
const finalTile = changeCase.pascalCase(title);
return `${finalTile}Icon`;
}
Loading

0 comments on commit 8996e69

Please sign in to comment.