Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed Dec 31, 2024
1 parent d280448 commit d89820d
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions bin/doc-translate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import OpenAI from "openai";
import { readdir, readFile, writeFile, mkdir } from 'fs/promises';
import path from 'path';
import { execSync } from 'child_process';

const endpoint = "https://api.deepseek.com";
const token = process.env["DEEPSEEK_API_KEY"];
Expand All @@ -13,20 +12,6 @@ const openai = new OpenAI({
apiKey: token,
});

// 获取最近一次提交修改的md文件
async function getRecentlyChangedFiles() {
try {
const output = execSync('git diff-tree --no-commit-id --name-only -r HEAD').toString();
return output
.split('\n')
.filter(file => file.startsWith('docs/zh-cn/') && file.endsWith('.md'))
.map(file => file.replace('docs/zh-cn/', ''));
} catch (error) {
console.error('Error getting changed files:', error);
return [];
}
}

async function translateWithRetry(content, retries = 0) {
try {
const completion = await openai.chat.completions.create({
Expand Down Expand Up @@ -59,16 +44,12 @@ async function processFile(srcPath, destPath) {

async function translateFiles(srcDir, destDir) {
try {
const changedFiles = await getRecentlyChangedFiles();
const files = await readdir(srcDir, { recursive: true });
const mdFiles = files.filter(file => file.endsWith('.md'));

if (changedFiles.length === 0) {
console.log('No markdown files were changed in the last commit.');
return;
}

// 将文件分批处理
for (let i = 0; i < changedFiles.length; i += MAX_CONCURRENT) {
const batch = changedFiles.slice(i, i + MAX_CONCURRENT);
for (let i = 0; i < mdFiles.length; i += MAX_CONCURRENT) {
const batch = mdFiles.slice(i, i + MAX_CONCURRENT);
const promises = batch.map(file => {
const srcPath = path.join(srcDir, file);
const destPath = path.join(destDir, file);
Expand All @@ -80,7 +61,7 @@ async function translateFiles(srcDir, destDir) {
await Promise.all(promises);
}

console.log('Translation of changed files completed!');
console.log('All translations completed!');
} catch (error) {
console.error('Translation error:', error);
}
Expand Down

0 comments on commit d89820d

Please sign in to comment.