Skip to content

Commit 153e79a

Browse files
committed
refactor: simplify tools integration
feat: script:create:tool command supports specifying tool categories: pnpm script:create:tool [tool-name] [category-name] feat: A locales folder can be created independently under each tool to support independent configuration of the tool's own internationalization, making developers more focused and reducing file modification conflicts perf: Optimize the script:create:tool command to create generated files, reduce the chance of public file modification conflicts, and allow developers to focus more on developing their own perf: Improve the category field in defineTool for existing tools
1 parent f28128a commit 153e79a

271 files changed

Lines changed: 304 additions & 621 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/create-tool.mjs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
import { mkdir, readFile, writeFile } from 'fs/promises';
2-
import { dirname, join } from 'path';
3-
import { fileURLToPath } from 'url';
1+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
2+
import { dirname, join } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
44

55
const currentDirname = dirname(fileURLToPath(import.meta.url));
66

77
const toolsDir = join(currentDirname, '..', 'src', 'tools');
8-
// eslint-disable-next-line no-undef
8+
99
const toolName = process.argv[2];
1010

1111
if (!toolName) {
1212
throw new Error('Please specify a toolname.');
1313
}
1414

15-
const toolNameCamelCase = toolName.replace(/-./g, (x) => x[1].toUpperCase());
15+
const toolCategory = process.argv[3] || 'Default';
16+
1617
const toolNameTitleCase = toolName[0].toUpperCase() + toolName.slice(1).replace(/-/g, ' ');
1718
const toolDir = join(toolsDir, toolName);
1819

1920
await mkdir(toolDir);
2021
console.log(`Directory created: ${toolDir}`);
2122

22-
const createToolFile = async (name, content) => {
23+
async function createToolFile(name, content) {
2324
const filePath = join(toolDir, name);
2425
await writeFile(filePath, content.trim());
2526
console.log(`File created: ${filePath}`);
26-
};
27+
}
2728

2829
createToolFile(
2930
`${toolName}.vue`,
@@ -44,7 +45,7 @@ createToolFile(
4445
);
4546

4647
createToolFile(
47-
`index.ts`,
48+
'index.ts',
4849
`
4950
import { ArrowsShuffle } from '@vicons/tabler';
5051
import { defineTool } from '../tool';
@@ -53,15 +54,16 @@ export const tool = defineTool({
5354
name: '${toolNameTitleCase}',
5455
path: '/${toolName}',
5556
description: '',
56-
keywords: ['${toolName.split('-').join("', '")}'],
57+
keywords: ['${toolName.split('-').join('\', \'')}'],
5758
component: () => import('./${toolName}.vue'),
5859
icon: ArrowsShuffle,
5960
createdAt: new Date('${new Date().toISOString().split('T')[0]}'),
61+
category: '${toolCategory}',
6062
});
6163
`,
6264
);
6365

64-
createToolFile(`${toolName}.service.ts`, ``);
66+
createToolFile(`${toolName}.service.ts`, '');
6567
createToolFile(
6668
`${toolName}.service.test.ts`,
6769
`
@@ -92,13 +94,6 @@ test.describe('Tool - ${toolNameTitleCase}', () => {
9294
9395
});
9496
});
95-
96-
`,
97-
);
98-
99-
const toolsIndex = join(toolsDir, 'index.ts');
100-
const indexContent = await readFile(toolsIndex, { encoding: 'utf-8' }).then((r) => r.split('\n'));
10197
102-
indexContent.splice(3, 0, `import { tool as ${toolNameCamelCase} } from './${toolName}';`);
103-
writeFile(toolsIndex, indexContent.join('\n'));
104-
console.log(`Added import in: ${toolsIndex}`);
98+
`,
99+
);

src/tools/ai-prompt-splitter/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const tool = defineTool({
99
component: () => import('./ai-prompt-splitter.vue'),
1010
icon: Prompt,
1111
createdAt: new Date('2024-07-14'),
12+
category: 'Text',
1213
});

src/tools/angle-converter/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const tool = defineTool({
99
component: () => import('./angle-converter.vue'),
1010
icon: Angle,
1111
createdAt: new Date('2024-08-15'),
12+
category: 'Physics',
1213
});

src/tools/ansible-vault-crypt-decrypt/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const tool = defineTool({
99
component: () => import('./ansible-vault-crypt-decrypt.vue'),
1010
icon: LockSquare,
1111
createdAt: new Date('2024-02-25'),
12+
category: 'Crypto',
1213
});

src/tools/api-tester/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const tool = defineTool({
99
component: () => import('./api-tester.vue'),
1010
icon: World,
1111
createdAt: new Date('2024-05-11'),
12+
category: 'Development',
1213
});

src/tools/area-converter/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const tool = defineTool({
99
component: () => import('./area-converter.vue'),
1010
icon: SquaresDiagonal,
1111
createdAt: new Date('2024-08-15'),
12+
category: 'Physics',
1213
});

src/tools/ascii-text-drawer/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export const tool = defineTool({
1010
icon: Artboard,
1111
createdAt: new Date('2024-03-03'),
1212
npmPackages: ['figlet'],
13+
category: 'Text',
1314
});

src/tools/aspect-ratio-calculator/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const tool = defineTool({
99
component: () => import('./aspect-ratio-calculator.vue'),
1010
icon: AspectRatio,
1111
createdAt: new Date('2024-08-14'),
12+
category: 'Measurement',
1213
});

src/tools/barcode-generator/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const tool = defineTool({
99
component: () => import('./barcode-generator.vue'),
1010
icon: Barcode,
1111
createdAt: new Date('2024-04-20'),
12+
category: 'Barcodes',
1213
});

src/tools/barcode-reader/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const tool = defineTool({
99
component: () => import('./barcode-reader.vue'),
1010
icon: Barcode,
1111
createdAt: new Date('2024-04-20'),
12+
category: 'Barcodes',
1213
});

0 commit comments

Comments
 (0)