🛠️ Refactor parseSvgFilename function for improved component name formatting; add directory and file existence checks in generate-registry

This commit is contained in:
pheralb
2025-08-31 16:19:44 +01:00
parent 733e136b3a
commit 4cd2c84273
2 changed files with 32 additions and 5 deletions
+29 -2
View File
@@ -30,7 +30,6 @@ interface RegistryItem {
name: string; name: string;
type: string; type: string;
title: string; title: string;
registryDependencies: string[];
files: RegistryFile[]; files: RegistryFile[];
} }
@@ -80,7 +79,6 @@ function prepareRegistryJson(): ShadcnSchema {
name: componentName, name: componentName,
type: "registry:component", type: "registry:component",
title: componentName, title: componentName,
registryDependencies: [""],
files: files, files: files,
}); });
} }
@@ -238,6 +236,34 @@ async function runShadcnBuild() {
} }
} }
const checkFinallyDirs = async () => {
// Check if static/r directory exists
const rDirExists = await fs.promises
.access(`./${PUBLIC_FOLDER}/r`)
.then(() => true)
.catch(() => false);
if (!rDirExists) {
console.error("[🔎] Error - Directory ./static/r does not exist");
return;
} else {
console.log("[🔎] Directory ./static/r exists");
}
// Check if registry.json exists
const registryExists = await fs.promises
.access("./registry.json")
.then(() => true)
.catch(() => false);
if (!registryExists) {
console.error("[🔎] Error - File registry.json does not exist");
return;
} else {
console.log("[🔎] File registry.json exists");
}
};
async function run() { async function run() {
let convertedCount = 0; let convertedCount = 0;
let totalCount = 0; let totalCount = 0;
@@ -307,6 +333,7 @@ async function run() {
console.error("[❌] Error:", error); console.error("[❌] Error:", error);
throw new Error(error); throw new Error(error);
} finally { } finally {
await checkFinallyDirs();
await cleanupDirectory(OUTPUT_DIR); await cleanupDirectory(OUTPUT_DIR);
console.log("[🎉] Process completed"); console.log("[🎉] Process completed");
} }
+3 -3
View File
@@ -7,9 +7,9 @@ export const parseSvgFilename = (params: ParseSvgFilename): string => {
const { file, log } = params; const { file, log } = params;
const name = file.replace(/\.svg$/i, ""); const name = file.replace(/\.svg$/i, "");
let component = name.replace(/(^\w|[-_]\w)/g, (m) => let component = name
m.replace(/[-_]/, "").toUpperCase(), .replace(/[-_\s]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ""))
); .replace(/^(.)/, (char) => char.toLowerCase());
if (/^\d/.test(component)) { if (/^\d/.test(component)) {
if (log) { if (log) {