mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 22:07:10 -04:00
Added Chinese version
Added Chinese version
This commit is contained in:
parent
d037338a23
commit
730a68b92a
466 changed files with 31255 additions and 0 deletions
104
zh-CN/scripts/create-tool.mjs
Normal file
104
zh-CN/scripts/create-tool.mjs
Normal file
|
@ -0,0 +1,104 @@
|
|||
import { mkdir, readFile, writeFile } from 'fs/promises';
|
||||
import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from '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 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) => {
|
||||
const filePath = join(toolDir, name);
|
||||
await writeFile(filePath, content.trim());
|
||||
console.log(`File created: ${filePath}`);
|
||||
};
|
||||
|
||||
createToolFile(
|
||||
`${toolName}.vue`,
|
||||
`
|
||||
<template>
|
||||
<div>
|
||||
Lorem ipsum
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
</style>
|
||||
`,
|
||||
);
|
||||
|
||||
createToolFile(
|
||||
`index.ts`,
|
||||
`
|
||||
import { ArrowsShuffle } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: '${toolNameTitleCase}',
|
||||
path: '/${toolName}',
|
||||
description: '',
|
||||
keywords: ['${toolName.split('-').join("', '")}'],
|
||||
component: () => import('./${toolName}.vue'),
|
||||
icon: ArrowsShuffle,
|
||||
createdAt: new Date('${new Date().toISOString().split('T')[0]}'),
|
||||
});
|
||||
`,
|
||||
);
|
||||
|
||||
createToolFile(`${toolName}.service.ts`, ``);
|
||||
createToolFile(
|
||||
`${toolName}.service.test.ts`,
|
||||
`
|
||||
import { expect, describe, it } from 'vitest';
|
||||
// import { } from './${toolName}.service';
|
||||
//
|
||||
// describe('${toolName}', () => {
|
||||
//
|
||||
// })
|
||||
`,
|
||||
);
|
||||
|
||||
createToolFile(
|
||||
`${toolName}.e2e.spec.ts`,
|
||||
`
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Tool - ${toolNameTitleCase}', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/${toolName}');
|
||||
});
|
||||
|
||||
test('Has correct title', async ({ page }) => {
|
||||
await expect(page).toHaveTitle('${toolNameTitleCase} - IT Tools');
|
||||
});
|
||||
|
||||
test('', async ({ page }) => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
`,
|
||||
);
|
||||
|
||||
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}`);
|
6
zh-CN/scripts/getLatestChangelog.mjs
Normal file
6
zh-CN/scripts/getLatestChangelog.mjs
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { readFile } from 'fs/promises';
|
||||
|
||||
const changelogContent = await readFile('./CHANGELOG.md', 'utf-8');
|
||||
const [, lastChangelog] = changelogContent.split(/^## .*$/gm);
|
||||
|
||||
console.log(lastChangelog.trim());
|
57
zh-CN/scripts/release.mjs
Normal file
57
zh-CN/scripts/release.mjs
Normal file
|
@ -0,0 +1,57 @@
|
|||
import { $, argv } from 'zx';
|
||||
import { consola } from 'consola';
|
||||
import { rawCommitsToMarkdown } from './shared/commits.mjs';
|
||||
import { addToChangelog } from './shared/changelog.mjs';
|
||||
|
||||
$.verbose = false;
|
||||
|
||||
const isDryRun = argv['dry-run'] ?? false;
|
||||
|
||||
const now = new Date();
|
||||
const currentShortSha = (await $`git rev-parse --short HEAD`).stdout.trim();
|
||||
|
||||
const calver = now.toISOString().slice(0, 10).replace(/-/g, '.');
|
||||
const version = `${calver}-${currentShortSha}`;
|
||||
|
||||
const { stdout: rawCommits } = await $`git log --pretty=oneline $(git describe --tags --abbrev=0)..HEAD`;
|
||||
|
||||
const markdown = rawCommitsToMarkdown({ rawCommits });
|
||||
|
||||
consola.info(`Changelog: \n\n${markdown}\n\n`);
|
||||
|
||||
if (isDryRun) {
|
||||
consola.info(`[dry-run] Not creating version nor tag`);
|
||||
consola.info('Aborting');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const shouldContinue = await consola.prompt(
|
||||
'This script will create a new version and tag, and update the changelog. Continue?',
|
||||
{
|
||||
type: 'confirm',
|
||||
},
|
||||
);
|
||||
|
||||
if (!shouldContinue) {
|
||||
consola.info('Aborting');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
consola.info('Updating changelog');
|
||||
await addToChangelog({ changelog: markdown, version });
|
||||
consola.success('Changelog updated');
|
||||
|
||||
try {
|
||||
consola.info('Committing changelog changes');
|
||||
await $`git add CHANGELOG.md`;
|
||||
await $`git commit -m "docs(changelog): update changelog for ${version}"`;
|
||||
consola.success('Changelog changes committed');
|
||||
|
||||
consola.info('Creating version and tag');
|
||||
await $`npm version ${version} -m "chore(version): release ${version}"`;
|
||||
consola.info('Npm version released with tag');
|
||||
} catch (error) {
|
||||
consola.error(error);
|
||||
consola.info('Aborting');
|
||||
process.exit(1);
|
||||
}
|
15
zh-CN/scripts/shared/changelog.mjs
Normal file
15
zh-CN/scripts/shared/changelog.mjs
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { readFile, writeFile } from 'fs/promises';
|
||||
|
||||
export { addToChangelog };
|
||||
|
||||
async function addToChangelog({ changelog, version, changelogPath = './CHANGELOG.md' }) {
|
||||
const changelogContent = await readFile(changelogPath, 'utf-8');
|
||||
const versionTitle = `## Version ${version}`;
|
||||
|
||||
if (changelogContent.includes(versionTitle)) {
|
||||
throw new Error(`Version ${version} already exists in the changelog`);
|
||||
}
|
||||
|
||||
const newChangeLogContent = changelogContent.replace('## ', `${versionTitle}\n\n${changelog}\n\n## `);
|
||||
await writeFile(changelogPath, newChangeLogContent, 'utf-8');
|
||||
}
|
54
zh-CN/scripts/shared/commits.mjs
Normal file
54
zh-CN/scripts/shared/commits.mjs
Normal file
|
@ -0,0 +1,54 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
export { rawCommitsToMarkdown };
|
||||
|
||||
const commitScopesToHumanReadable = {
|
||||
build: 'Build system',
|
||||
chore: 'Chores',
|
||||
ci: 'Continuous integration',
|
||||
docs: 'Documentation',
|
||||
feat: 'Features',
|
||||
fix: 'Bug fixes',
|
||||
infra: 'Infrastucture',
|
||||
perf: 'Performance',
|
||||
refactor: 'Refactoring',
|
||||
test: 'Tests',
|
||||
};
|
||||
|
||||
const commitTypesOrder = ['feat', 'fix', 'perf', 'refactor', 'test', 'build', 'ci', 'chore', 'other'];
|
||||
|
||||
const getCommitTypeSortIndex = (type) =>
|
||||
commitTypesOrder.includes(type) ? commitTypesOrder.indexOf(type) : commitTypesOrder.length;
|
||||
|
||||
function parseCommitLine(commit) {
|
||||
const [sha, ...splittedRawMessage] = commit.trim().split(' ');
|
||||
const rawMessage = splittedRawMessage.join(' ');
|
||||
const { type, scope, subject } = /^(?<type>.*?)(\((?<scope>.*)\))?: ?(?<subject>.+)$/.exec(rawMessage)?.groups ?? {};
|
||||
|
||||
return {
|
||||
sha: sha.slice(0, 7),
|
||||
type: type ?? 'other',
|
||||
scope,
|
||||
subject: subject ?? rawMessage,
|
||||
};
|
||||
}
|
||||
|
||||
function commitSectionsToMarkdown({ type, commits }) {
|
||||
return [
|
||||
`### ${commitScopesToHumanReadable[type] ?? _.capitalize(type)}`,
|
||||
...commits.map(({ sha, scope, subject }) => ['-', scope ? `**${scope}**:` : '', subject, `(${sha})`].join(' ')),
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function rawCommitsToMarkdown({ rawCommits }) {
|
||||
return _.chain(rawCommits)
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map(parseCommitLine)
|
||||
.groupBy('type')
|
||||
.map((commits, type) => ({ type, commits }))
|
||||
.sortBy(({ type }) => getCommitTypeSortIndex(type))
|
||||
.map(commitSectionsToMarkdown)
|
||||
.join('\n\n')
|
||||
.value();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue