chore: revert create-tool.mjs

This commit is contained in:
Ibrahima G. Coulibaly
2025-05-23 20:04:39 +01:00
parent 9d89f8c0b9
commit 4eacb71938

View File

@@ -1,7 +1,7 @@
import { readFile, writeFile } from "fs/promises"; import { readFile, writeFile } from 'fs/promises';
import fs from "fs"; import fs from 'fs';
import { dirname, join, sep } from "path"; import { dirname, join, sep } from 'path';
import { fileURLToPath } from "url"; import { fileURLToPath } from 'url';
const currentDirname = dirname(fileURLToPath(import.meta.url)); const currentDirname = dirname(fileURLToPath(import.meta.url));
@@ -10,14 +10,14 @@ const folder = process.argv[3];
const toolsDir = join( const toolsDir = join(
currentDirname, currentDirname,
"..", '..',
"src", 'src',
"pages", 'pages',
"tools", 'tools',
folder ?? "" folder ?? ''
); );
if (!toolName) { if (!toolName) {
throw new Error("Please specify a toolname."); throw new Error('Please specify a toolname.');
} }
function capitalizeFirstLetter(string) { function capitalizeFirstLetter(string) {
@@ -35,7 +35,7 @@ function createFolderStructure(basePath, foldersToCreateIndexCount) {
if (!fs.existsSync(currentPath)) { if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath, { recursive: true }); fs.mkdirSync(currentPath, { recursive: true });
} }
const indexPath = join(currentPath, "index.ts"); const indexPath = join(currentPath, 'index.ts');
if ( if (
!fs.existsSync(indexPath) && !fs.existsSync(indexPath) &&
index < folderArray.length - 1 && index < folderArray.length - 1 &&
@@ -54,15 +54,15 @@ function createFolderStructure(basePath, foldersToCreateIndexCount) {
} }
// Start the recursive folder creation // Start the recursive folder creation
recursiveCreate(toolsDir, 0); recursiveCreate('.', 0);
} }
const toolNameCamelCase = toolName.replace(/-./g, x => x[1].toUpperCase()); const toolNameCamelCase = toolName.replace(/-./g, (x) => x[1].toUpperCase());
const toolNameTitleCase = const toolNameTitleCase =
toolName[0].toUpperCase() + toolName.slice(1).replace(/-/g, " "); toolName[0].toUpperCase() + toolName.slice(1).replace(/-/g, ' ');
const toolDir = join(toolsDir, toolName); const toolDir = join(toolsDir, toolName);
const type = folder.split(sep)[folder.split(sep).length - 1]; const type = folder.split(sep)[folder.split(sep).length - 1];
await createFolderStructure(toolName, folder.split(sep).length); await createFolderStructure(toolDir, folder.split(sep).length);
console.log(`Directory created: ${toolDir}`); console.log(`Directory created: ${toolDir}`);
const createToolFile = async (name, content) => { const createToolFile = async (name, content) => {
@@ -150,7 +150,7 @@ export const tool = defineTool('${type}', {
icon: '', icon: '',
description: '', description: '',
shortDescription: '', shortDescription: '',
keywords: ['${toolName.split("-").join("', '")}'], keywords: ['${toolName.split('-').join("', '")}'],
longDescription: '', longDescription: '',
component: lazy(() => import('./index')) component: lazy(() => import('./index'))
}); });
@@ -209,9 +209,9 @@ import { expect, describe, it } from 'vitest';
// ` // `
// ) // )
const toolsIndex = join(toolsDir, "index.ts"); const toolsIndex = join(toolsDir, 'index.ts');
const indexContent = await readFile(toolsIndex, { encoding: "utf-8" }).then(r => const indexContent = await readFile(toolsIndex, { encoding: 'utf-8' }).then(
r.split("\n") (r) => r.split('\n')
); );
indexContent.splice( indexContent.splice(
@@ -221,5 +221,5 @@ indexContent.splice(
toolNameCamelCase toolNameCamelCase
)} } from './${toolName}/meta';` )} } from './${toolName}/meta';`
); );
writeFile(toolsIndex, indexContent.join("\n")); writeFile(toolsIndex, indexContent.join('\n'));
console.log(`Added import in: ${toolsIndex}`); console.log(`Added import in: ${toolsIndex}`);