generated from template/apps-template
temp
This commit is contained in:
27
backend/test/create-json.ts
Normal file
27
backend/test/create-json.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import fastGlob from 'fast-glob';
|
||||
|
||||
// 匹配所有 markdown 文件
|
||||
const mds = await fastGlob('../prompts/*.md', {
|
||||
cwd: __dirname,
|
||||
absolute: false,
|
||||
});
|
||||
|
||||
// 生成 JSON 数据
|
||||
const jsonData = mds.map((filePath) => {
|
||||
const fileName = path.basename(filePath, '.md');
|
||||
const content = fs.readFileSync(path.join(__dirname, filePath), 'utf-8');
|
||||
return {
|
||||
title: fileName,
|
||||
content: content,
|
||||
};
|
||||
});
|
||||
|
||||
// 输出 JSON
|
||||
const outputPath = path.join(__dirname, '../prompts/markdown-files.json');
|
||||
fs.writeFileSync(outputPath, JSON.stringify(jsonData, null, 2), 'utf-8');
|
||||
|
||||
console.log(`已生成 JSON 文件: ${outputPath}`);
|
||||
console.log(`共找到 ${jsonData.length} 个 markdown 文件`);
|
||||
|
||||
Reference in New Issue
Block a user