mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-20 06:55:06 -04:00
chore(script): added tool create helper script
This commit is contained in:
parent
5dcb2ed95c
commit
2f49631ff7
1 changed files with 79 additions and 0 deletions
79
scripts/create-tool.mjs
Normal file
79
scripts/create-tool.mjs
Normal file
|
@ -0,0 +1,79 @@
|
|||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { mkdir, readFile, writeFile } from 'fs/promises';
|
||||
|
||||
const currentDirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const toolsDir = join(currentDirname, '..', 'src', 'tools');
|
||||
const toolName = process.argv[2];
|
||||
|
||||
if (!toolName) {
|
||||
throw new Error('Please specify a toolname.');
|
||||
}
|
||||
|
||||
const toolNameCamelCase = toolName.replace(/-./g, (x) => x[1].toUpperCase());
|
||||
const toolDir = join(toolsDir, toolName);
|
||||
|
||||
await mkdir(toolDir);
|
||||
console.log(`Directory created: ${toolDir}`);
|
||||
|
||||
const createToolFile = async (name, content) => {
|
||||
const filePath = join(toolDir, name);
|
||||
await writeFile(filePath, content.trim());
|
||||
console.log(`File created: ${filePath}`);
|
||||
};
|
||||
|
||||
createToolFile(
|
||||
`${toolName}.vue`,
|
||||
`
|
||||
<template>
|
||||
<n-card>
|
||||
Lorem ipsum
|
||||
</n-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
</style>
|
||||
`
|
||||
);
|
||||
|
||||
createToolFile(
|
||||
`index.ts`,
|
||||
`
|
||||
import { ArrowsShuffle } from '@vicons/tabler';
|
||||
import type { ITool } from './../Tool';
|
||||
|
||||
export const tool: ITool = {
|
||||
name: '${toolName}',
|
||||
path: '/${toolName}',
|
||||
description: '',
|
||||
keywords: ['${toolName.split('-').join("', '")}'],
|
||||
component: () => import('./${toolName}.vue'),
|
||||
icon: ArrowsShuffle,
|
||||
};
|
||||
`
|
||||
);
|
||||
|
||||
createToolFile(`${toolName}.service.ts`, ``);
|
||||
createToolFile(
|
||||
`${toolName}.service.test.ts`,
|
||||
`
|
||||
import { expect, describe, it } from 'vitest';
|
||||
// import { } from './${toolName}.service';
|
||||
//
|
||||
// describe('${toolName}', () => {
|
||||
//
|
||||
// })
|
||||
`
|
||||
);
|
||||
|
||||
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…
Add table
Add a link
Reference in a new issue