Skip to content

Commit

Permalink
Naming Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-herkamp committed Jan 7, 2024
1 parent 7af5ac9 commit 903be06
Show file tree
Hide file tree
Showing 13 changed files with 14,725 additions and 69 deletions.
1 change: 1 addition & 0 deletions buildTools/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.vscode
test
test.components.json
45 changes: 4 additions & 41 deletions buildTools/package-lock.json

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

6 changes: 3 additions & 3 deletions buildTools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
"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",
"dev": "deno run --allow-all src/main.ts --target test --component-json test.components.json",
"build": "deno run --allow-all src/main.ts --target ../src --component-json ../components.json",
"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"
"simple-icons": "11.0.0"
},
"devDependencies": {
"@biomejs/biome": "1.4.1"
Expand Down
17 changes: 15 additions & 2 deletions buildTools/src/component_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ ${componentScript}`;

return result;
}
const TITLE_TO_SLUG_REPLACEMENTS_UPPER_CASE: Record<string, string> = {
"&": "And",
"+": "Plus",
".": "Dot",
};

const TITLE_TO_SLUG_REPLACEMENTS_UPPER_CASE_REGEX = RegExp(
`[${Object.keys(TITLE_TO_SLUG_REPLACEMENTS_UPPER_CASE).join("")}]`,
"g"
);
/**
* If Brand.title is all AlphaNumeric characters and spaces convert to PascalCase
* If Brand.Title is not use Brand slug
Expand All @@ -25,13 +34,17 @@ ${componentScript}`;
*
*/
export function getComponentName(icon: Brand): string {
if (icon.title.match(/^[a-zA-Z ]+$/)) {
const iconToTest = icon.title.replace(
TITLE_TO_SLUG_REPLACEMENTS_UPPER_CASE_REGEX,
(char) => TITLE_TO_SLUG_REPLACEMENTS_UPPER_CASE[char]
);
if (iconToTest.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);
const name = changeCase.pascalCase(iconToTest);
return `${name}Icon`;
}
let title = getIconSlug(icon);
Expand Down
16 changes: 10 additions & 6 deletions buildTools/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ await new Command()
.option("--simple-icons [simpleIcons:file]", "Path to simple-icons", {
default: "node_modules/simple-icons",
})
.action(async ({ target, simpleIcons }) => {
.option("--component-json [componentJson:file]", "Path to component.json", {
default: "component.json",
})
.action(async ({ target, simpleIcons, componentJson }) => {
const source = !simpleIcons
? "node_modules/simple-icons"
: (simpleIcons as string);
const finalTarget = !target ? "test" : (target as string);
await buildIcons(finalTarget, source);
const jsonOutput = !componentJson ? "component.json" : (componentJson as string);
await buildIcons(finalTarget, source, jsonOutput);
})
.parse(Deno.args);

async function buildIcons(targetFolder: string, sourceFolder: string) {
async function buildIcons(targetFolder: string, sourceFolder: string, componentJson: string) {
console.log(
`Building vue3-simple-icons with simple-icons ${simpleIconsVersion} to ${targetFolder}...`,
);
Expand Down Expand Up @@ -81,6 +85,8 @@ async function buildIcons(targetFolder: string, sourceFolder: string) {
components.push(component);
}
await buildIndex(components, targetFolder);

await Deno.writeTextFile(componentJson, JSON.stringify(components, null, 2));
console.log("Done");
}

Expand All @@ -101,9 +107,7 @@ async function buildIndex(
`;
let exports = "";
for (const component of components) {
index +=
`// ${component.originalTitle} component generated from ${component.slug}.svg
import ${component.componentName} from "./components/${component.componentName}.vue";`;
index +=`import ${component.componentName} from "./components/${component.componentName}.vue"; // ${component.originalTitle} component generated from ${component.slug}.svg\n`;
exports += `\t\t${component.componentName},\n`;
}

Expand Down
Loading

0 comments on commit 903be06

Please sign in to comment.