perf: Optimize the command entry for creating tools, add a new category name when creating, so that the tool can be automatically imported after the developer creates it, reducing code conflicts caused by public file modifications
This commit is contained in:
		
							parent
							
								
									5c335c556d
								
							
						
					
					
						commit
						3173b239d3
					
				
							
								
								
									
										2
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -129,6 +129,8 @@ declare module '@vue/runtime-core' { | |||||||
|     MenuLayout: typeof import('./src/components/MenuLayout.vue')['default'] |     MenuLayout: typeof import('./src/components/MenuLayout.vue')['default'] | ||||||
|     MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default'] |     MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default'] | ||||||
|     MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default'] |     MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default'] | ||||||
|  |     MyNewTool: typeof import('./src/tools/my-new-tool/my-new-tool.vue')['default'] | ||||||
|  |     NardyEncTool: typeof import('./src/tools/nardy-enc-tool/nardy-enc-tool.vue')['default'] | ||||||
|     NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] |     NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] | ||||||
|     NCheckbox: typeof import('naive-ui')['NCheckbox'] |     NCheckbox: typeof import('naive-ui')['NCheckbox'] | ||||||
|     NCode: typeof import('naive-ui')['NCode'] |     NCode: typeof import('naive-ui')['NCode'] | ||||||
|  | |||||||
| @ -1,29 +1,30 @@ | |||||||
| import { mkdir, readFile, writeFile } from 'fs/promises'; | import { mkdir, readFile, writeFile } from 'node:fs/promises'; | ||||||
| import { dirname, join } from 'path'; | import { dirname, join } from 'node:path'; | ||||||
| import { fileURLToPath } from 'url'; | import { fileURLToPath } from 'node:url'; | ||||||
| 
 | 
 | ||||||
| const currentDirname = dirname(fileURLToPath(import.meta.url)); | const currentDirname = dirname(fileURLToPath(import.meta.url)); | ||||||
| 
 | 
 | ||||||
| const toolsDir = join(currentDirname, '..', 'src', 'tools'); | const toolsDir = join(currentDirname, '..', 'src', 'tools'); | ||||||
| // eslint-disable-next-line no-undef
 | 
 | ||||||
| const toolName = process.argv[2]; | const toolName = process.argv[2]; | ||||||
| 
 | 
 | ||||||
| if (!toolName) { | if (!toolName) { | ||||||
|   throw new Error('Please specify a toolname.'); |   throw new Error('Please specify a toolname.'); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const toolNameCamelCase = toolName.replace(/-./g, (x) => x[1].toUpperCase()); | const toolCategory = process.argv[3] || 'Default'; | ||||||
|  | 
 | ||||||
| const toolNameTitleCase = toolName[0].toUpperCase() + toolName.slice(1).replace(/-/g, ' '); | const toolNameTitleCase = toolName[0].toUpperCase() + toolName.slice(1).replace(/-/g, ' '); | ||||||
| const toolDir = join(toolsDir, toolName); | const toolDir = join(toolsDir, toolName); | ||||||
| 
 | 
 | ||||||
| await mkdir(toolDir); | await mkdir(toolDir); | ||||||
| console.log(`Directory created: ${toolDir}`); | console.log(`Directory created: ${toolDir}`); | ||||||
| 
 | 
 | ||||||
| const createToolFile = async (name, content) => { | async function createToolFile(name, content) { | ||||||
|   const filePath = join(toolDir, name); |   const filePath = join(toolDir, name); | ||||||
|   await writeFile(filePath, content.trim()); |   await writeFile(filePath, content.trim()); | ||||||
|   console.log(`File created: ${filePath}`); |   console.log(`File created: ${filePath}`); | ||||||
| }; | } | ||||||
| 
 | 
 | ||||||
| createToolFile( | createToolFile( | ||||||
|   `${toolName}.vue`, |   `${toolName}.vue`, | ||||||
| @ -44,7 +45,7 @@ createToolFile( | |||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
| createToolFile( | createToolFile( | ||||||
|   `index.ts`, |   'index.ts', | ||||||
|   ` |   ` | ||||||
| import { ArrowsShuffle } from '@vicons/tabler'; | import { ArrowsShuffle } from '@vicons/tabler'; | ||||||
| import { defineTool } from '../tool'; | import { defineTool } from '../tool'; | ||||||
| @ -53,15 +54,16 @@ export const tool = defineTool({ | |||||||
|   name: '${toolNameTitleCase}', |   name: '${toolNameTitleCase}', | ||||||
|   path: '/${toolName}', |   path: '/${toolName}', | ||||||
|   description: '', |   description: '', | ||||||
|   keywords: ['${toolName.split('-').join("', '")}'], |   keywords: ['${toolName.split('-').join('\', \'')}'], | ||||||
|   component: () => import('./${toolName}.vue'), |   component: () => import('./${toolName}.vue'), | ||||||
|   icon: ArrowsShuffle, |   icon: ArrowsShuffle, | ||||||
|   createdAt: new Date('${new Date().toISOString().split('T')[0]}'), |   createdAt: new Date('${new Date().toISOString().split('T')[0]}'), | ||||||
|  |   category: '${toolCategory}', | ||||||
| }); | }); | ||||||
| `,
 | `,
 | ||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
| createToolFile(`${toolName}.service.ts`, ``); | createToolFile(`${toolName}.service.ts`, ''); | ||||||
| createToolFile( | createToolFile( | ||||||
|   `${toolName}.service.test.ts`, |   `${toolName}.service.test.ts`, | ||||||
|   ` |   ` | ||||||
| @ -95,10 +97,3 @@ test.describe('Tool - ${toolNameTitleCase}', () => { | |||||||
| 
 | 
 | ||||||
| `,
 | `,
 | ||||||
| ); | ); | ||||||
| 
 |  | ||||||
| const toolsIndex = join(toolsDir, 'index.ts'); |  | ||||||
| const indexContent = await readFile(toolsIndex, { encoding: 'utf-8' }).then((r) => r.split('\n')); |  | ||||||
| 
 |  | ||||||
| indexContent.splice(3, 0, `import { tool as ${toolNameCamelCase} } from './${toolName}';`); |  | ||||||
| writeFile(toolsIndex, indexContent.join('\n')); |  | ||||||
| console.log(`Added import in: ${toolsIndex}`); |  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user