fix: create tool

This commit is contained in:
Ibrahima G. Coulibaly
2024-06-23 20:37:17 +01:00
parent 76a6613a4c
commit 2f6c16f274
4 changed files with 97 additions and 62 deletions

115
.idea/workspace.xml generated
View File

@@ -4,22 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: readme"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: missing files">
<change afterPath="$PROJECT_DIR$/scripts/create-tool.mjs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/pages/image/png/change-colors-in-png/change-colors-in-png.service.test.ts" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/pages/image/png/change-colors-in-png/index.tsx" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/pages/image/png/change-colors-in-png/meta.ts" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/pages/image/png/change-colors-in-png/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" /> <change beforePath="$PROJECT_DIR$/scripts/create-tool.mjs" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/create-tool.mjs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/images/imageTools.ts" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/images/png/change-colors-in-png/index.tsx" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/images/png/change-colors-in-png/meta.ts" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/images/png/pngTools.ts" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/join/string-join.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/join/string-join.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/split/string-split.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/split/string-split.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/stringTools.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/index.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/tools/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/tools/index.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tsconfig.json" beforeDir="false" afterPath="$PROJECT_DIR$/tsconfig.json" afterDir="false" /> <change beforePath="$PROJECT_DIR$/tsconfig.json" beforeDir="false" afterPath="$PROJECT_DIR$/tsconfig.json" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@@ -49,36 +36,37 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, "ASKED_ADD_EXTERNAL_FILES": "true",
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;Vitest.mergeText.executor&quot;: &quot;Run&quot;, "Vitest.mergeText.executor": "Run",
&quot;Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor&quot;: &quot;Run&quot;, "Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run",
&quot;Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor&quot;: &quot;Run&quot;, "Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor": "Run",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "main",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, "kotlin-language-version-configured": "true",
&quot;last_opened_file_path&quot;: &quot;C:/Users/HP/IdeaProjects/omni-tools/src/pages/string&quot;, "last_opened_file_path": "C:/Users/HP/IdeaProjects/omni-tools/src/pages/string",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;npm.dev.executor&quot;: &quot;Run&quot;, "npm.dev.executor": "Run",
&quot;npm.prebuild.executor&quot;: &quot;Run&quot;, "npm.prebuild.executor": "Run",
&quot;npm.script:create:tool.executor&quot;: &quot;Run&quot;, "npm.script:create:tool.executor": "Run",
&quot;prettierjs.PrettierConfiguration.Package&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier&quot;, "npm.test.executor": "Run",
&quot;project.structure.last.edited&quot;: &quot;Problems&quot;, "prettierjs.PrettierConfiguration.Package": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier",
&quot;project.structure.proportion&quot;: &quot;0.0&quot;, "project.structure.last.edited": "Problems",
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;, "project.structure.proportion": "0.0",
&quot;settings.editor.selected.configurable&quot;: &quot;settings.typescriptcompiler&quot;, "project.structure.side.proportion": "0.2",
&quot;ts.external.directory.path&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib&quot;, "settings.editor.selected.configurable": "settings.typescriptcompiler",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "ts.external.directory.path": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
"vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="ReactDesignerToolWindowState"> <component name="ReactDesignerToolWindowState">
<option name="myId2Visible"> <option name="myId2Visible">
<map> <map>
@@ -102,7 +90,7 @@
<recent name="C:\Users\HP\IdeaProjects\omni-tools\src\tools" /> <recent name="C:\Users\HP\IdeaProjects\omni-tools\src\tools" />
</key> </key>
</component> </component>
<component name="RunManager" selected="npm.script:create:tool"> <component name="RunManager" selected="npm.test">
<configuration name="dev" type="js.build_tools.npm" temporary="true" nameIsGenerated="true"> <configuration name="dev" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" /> <package-json value="$PROJECT_DIR$/package.json" />
<command value="run" /> <command value="run" />
@@ -133,8 +121,19 @@
<envs /> <envs />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="test" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="test" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="npm.test" />
<item itemvalue="npm.script:create:tool" /> <item itemvalue="npm.script:create:tool" />
<item itemvalue="npm.dev" /> <item itemvalue="npm.dev" />
<item itemvalue="npm.prebuild" /> <item itemvalue="npm.prebuild" />
@@ -161,7 +160,7 @@
<workItem from="1719092003308" duration="14856000" /> <workItem from="1719092003308" duration="14856000" />
<workItem from="1719164664347" duration="2033000" /> <workItem from="1719164664347" duration="2033000" />
<workItem from="1719166718305" duration="1783000" /> <workItem from="1719166718305" duration="1783000" />
<workItem from="1719168519203" duration="179000" /> <workItem from="1719168519203" duration="2752000" />
</task> </task>
<task id="LOCAL-00001" summary="feat: use vite and ts"> <task id="LOCAL-00001" summary="feat: use vite and ts">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -435,7 +434,23 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1719165600245</updated> <updated>1719165600245</updated>
</task> </task>
<option name="localTasksCounter" value="35" /> <task id="LOCAL-00035" summary="feat: create tool script">
<option name="closed" value="true" />
<created>1719169082452</created>
<option name="number" value="00035" />
<option name="presentableId" value="LOCAL-00035" />
<option name="project" value="LOCAL" />
<updated>1719169082452</updated>
</task>
<task id="LOCAL-00036" summary="fix: missing files">
<option name="closed" value="true" />
<created>1719170769791</created>
<option name="number" value="00036" />
<option name="presentableId" value="LOCAL-00036" />
<option name="project" value="LOCAL" />
<updated>1719170769791</updated>
</task>
<option name="localTasksCounter" value="37" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -456,8 +471,6 @@
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" /> <option name="CHECK_NEW_TODO" value="false" />
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="fix: netlify" />
<MESSAGE value="fix: index title" />
<MESSAGE value="chore: split string tools ui" /> <MESSAGE value="chore: split string tools ui" />
<MESSAGE value="chore: use formik" /> <MESSAGE value="chore: use formik" />
<MESSAGE value="chore: output selector" /> <MESSAGE value="chore: output selector" />
@@ -481,7 +494,9 @@
<MESSAGE value="feat: result copy and download" /> <MESSAGE value="feat: result copy and download" />
<MESSAGE value="feat: contributors graph" /> <MESSAGE value="feat: contributors graph" />
<MESSAGE value="fix: readme" /> <MESSAGE value="fix: readme" />
<option name="LAST_COMMIT_MESSAGE" value="fix: readme" /> <MESSAGE value="feat: create tool script" />
<MESSAGE value="fix: missing files" />
<option name="LAST_COMMIT_MESSAGE" value="fix: missing files" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View File

@@ -1,5 +1,6 @@
import { mkdir, readFile, writeFile } from 'fs/promises' import { readFile, writeFile } from 'fs/promises'
import { dirname, join } from 'path' import fs from 'fs'
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))
@@ -8,7 +9,6 @@ const toolName = process.argv[2]
const folder = process.argv[3] const folder = process.argv[3]
const toolsDir = join(currentDirname, '..', 'src', 'pages', folder ?? '') const toolsDir = join(currentDirname, '..', 'src', 'pages', folder ?? '')
if (!toolName) { if (!toolName) {
throw new Error('Please specify a toolname.') throw new Error('Please specify a toolname.')
} }
@@ -17,12 +17,35 @@ function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1) return string.charAt(0).toUpperCase() + string.slice(1)
} }
function createFolderStructure(basePath, foldersToCreateIndexCount) {
const folderArray = basePath.split(sep)
function recursiveCreate(currentBase, index) {
if (index >= folderArray.length) {
return
}
const currentPath = join(currentBase, folderArray[index])
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath, { recursive: true })
}
const indexPath = join(currentPath, 'index.ts')
if (!fs.existsSync(indexPath) && index < folderArray.length - 1 && index >= folderArray.length - 1 - foldersToCreateIndexCount) {
fs.writeFileSync(indexPath, '// index.ts file')
}
// Recursively create the next folder
recursiveCreate(currentPath, index + 1)
}
// Start the recursive folder creation
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)
await mkdir(toolDir) 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) => {
@@ -53,12 +76,12 @@ createToolFile(
` `
import { defineTool } from '@tools/defineTool'; import { defineTool } from '@tools/defineTool';
import { lazy } from 'react'; import { lazy } from 'react';
import image from '../../../assets/text.png'; // import image from '@assets/text.png';
export const tool = defineTool('${folder}', { export const tool = defineTool('${folder}', {
name: '${toolNameTitleCase}', name: '${toolNameTitleCase}',
path: '/${toolName}', path: '/${toolName}',
image, // image,
description: '', description: '',
keywords: ['${toolName.split('-').join('\', \'')}'], keywords: ['${toolName.split('-').join('\', \'')}'],
component: lazy(() => import('./index')) component: lazy(() => import('./index'))

View File

@@ -1,6 +0,0 @@
import { expect, describe, it } from 'vitest';
// import { } from './service';
//
// describe('change-colors-in-png', () => {
//
// })

View File

@@ -27,6 +27,9 @@
"paths": { "paths": {
"@tools/*": [ "@tools/*": [
"./tools/*" "./tools/*"
],
"@assets/*": [
"./assets/*"
] ]
} }
}, },