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']
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.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']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
|
||||
@ -1,29 +1,30 @@
|
||||
import { mkdir, readFile, writeFile } from 'fs/promises';
|
||||
import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const currentDirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const toolsDir = join(currentDirname, '..', 'src', 'tools');
|
||||
// eslint-disable-next-line no-undef
|
||||
|
||||
const toolName = process.argv[2];
|
||||
|
||||
if (!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 toolDir = join(toolsDir, toolName);
|
||||
|
||||
await mkdir(toolDir);
|
||||
console.log(`Directory created: ${toolDir}`);
|
||||
|
||||
const createToolFile = async (name, content) => {
|
||||
async function createToolFile(name, content) {
|
||||
const filePath = join(toolDir, name);
|
||||
await writeFile(filePath, content.trim());
|
||||
console.log(`File created: ${filePath}`);
|
||||
};
|
||||
}
|
||||
|
||||
createToolFile(
|
||||
`${toolName}.vue`,
|
||||
@ -44,7 +45,7 @@ createToolFile(
|
||||
);
|
||||
|
||||
createToolFile(
|
||||
`index.ts`,
|
||||
'index.ts',
|
||||
`
|
||||
import { ArrowsShuffle } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
@ -53,15 +54,16 @@ export const tool = defineTool({
|
||||
name: '${toolNameTitleCase}',
|
||||
path: '/${toolName}',
|
||||
description: '',
|
||||
keywords: ['${toolName.split('-').join("', '")}'],
|
||||
keywords: ['${toolName.split('-').join('\', \'')}'],
|
||||
component: () => import('./${toolName}.vue'),
|
||||
icon: ArrowsShuffle,
|
||||
createdAt: new Date('${new Date().toISOString().split('T')[0]}'),
|
||||
category: '${toolCategory}',
|
||||
});
|
||||
`,
|
||||
);
|
||||
|
||||
createToolFile(`${toolName}.service.ts`, ``);
|
||||
createToolFile(`${toolName}.service.ts`, '');
|
||||
createToolFile(
|
||||
`${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