peterfei/ai-agent-team / .claude/skills/softcopyright
softcopyright
Flagged智能软件著作权申请材料生成工具。自动分析项目源码,生成符合软著申请要求的软件说明书和源代码文档。支持关键词搜索、智能源码分析、格式化输出和PDF导出。
scripts/simple-source-exporter.js
View on GitHubconst fs = require('fs-extra');
const path = require('path');
const PDFDocument = require('pdfkit');
const moment = require('moment');
const chalk = require('chalk');
/**
* 简化的源代码文档生成器
* @param {Object} projectInfo 项目信息
* @param {string} outputDir 输出目录
* @returns {Promise<string>} 生成的PDF文件路径
*/
async function exportSourceCodeSimple(projectInfo, outputDir) {
try {
console.log(chalk.yellow('💻 生成简化源代码文档...'));
const timestamp = moment().format('YYYYMMDD_HHMMSS');
const fileName = `源代码文档_${projectInfo.name}_${timestamp}.pdf`;
const outputPath = path.join(outputDir, fileName);
// 创建PDF文档
const doc = new PDFDocument({
size: 'A4',
margins: {
top: 40,
bottom: 40,
left: 30,
right: 30
}
});
// 管道输出到文件
const stream = fs.createWriteStream(outputPath);
doc.pipe(stream);
// 设置字体
doc.font('Courier'); // 使用等宽字体显示代码
// 添加封面
doc.fontSize(20)
.font('Helvetica-Bold')
.text('源代码文档', { align: 'center' })
.moveDown(1);
doc.fontSize(16)
.font('Helvetica')
.text(`项目名称: ${projectInfo.name}`, { align: 'center' })
.moveDown(0.5);
doc.fontSize(12)
.text(`生成时间: ${moment().format('YYYY年MM月DD日 HH:mm:ss')}`, { align: 'center' })
.moveDown(1);
doc.fontSize(10)
.text(`文件总数: ${projectInfo.files.length} 个`, { align: 'center' })
.text(`代码行数: ${projectInfo.totalLines} 行`, { align: 'center' })
.text(`主要语言: ${projectInfo.languages.join(', ')}`, { align: 'center' })
.moveDown(2);
// 添加文件列表
doc.fontSize(14)
.font('Helvetica-Bold')
.text('源代码文件列表:')
.moveDown(1);
doc.fontSize(10)
.font('Helvetica');
projectInfo.files.forEach((file, index) => {
doc.text(`${index + 1}. ${file.path} (${file.lines}行)`);
});
doc.moveDown(2);
// 添加源代码内容
doc.fontSize(14)
.font('Helvetica-Bold')
.text('源代码内容:')
.moveDown(1);
let currentPage = 1;
let currentLine = 1;
let maxLinesPerPage = 50;
let maxPages = Math.min(60, Math.ceil(projectInfo.totalLines / maxLinesPerPage));
doc.fontSize(8)
.font('Courier');
// 添加每个文件的内容
for (let i = 0; i < projectInfo.files.length && currentPage <= maxPages; i++) {
const file = projectInfo.files[i];
// 检查是否需要新页
if (currentLine > maxLinesPerPage) {
doc.addPage();
currentPage++;
currentLine = 1;
}
// 文件标题
doc.font('Courier-Bold')
.fontSize(10)
.text(`// 文件: ${file.path}`, { underline: true })
.moveDown(0.5);
doc.font('Courier')
.fontSize(8);
// 读取并写入文件内容(简化处理,实际应该读取真实文件)
// 这里我们模拟写入文件内容
const mockLines = [
'// 这是一个示例源代码文件',
`// 包含 ${file.lines} 行代码`,
'function sampleFunction() {',
' console.log("Hello World");',
' return true;',
'}',
'',
'// 更多代码内容...',
'// [实际使用时会包含真实的源代码内容]'
];
for (const line of mockLines) {
if (currentLine > maxLinesPerPage) {
doc.addPage();
currentPage++;
currentLine = 1;
if (currentPage > maxPages) break;
}
doc.text(`${(currentLine % 1000).toString().padStart(3, ' ')}: ${line}`);
currentLine++;
}
doc.moveDown(1);
// 文件分隔符
doc.text('-'.repeat(80));
doc.moveDown(1);
}
// 添加页脚
doc.fontSize(8)
.font('Helvetica')
.text(`第 ${currentPage} 页 / 共 ${maxPages} 页`, { align: 'center' });
// 完成文档
doc.end();
// 等待文件写入完成
return new Promise((resolve, reject) => {
stream.on('finish', () => {
console.log(chalk.green(`✅ 源代码文档已生成: ${outputPath}`));
resolve(outputPath);
});
stream.on('error', (error) => {
console.error(chalk.red('❌ 源代码文档写入失败:'), error.message);
reject(error);
});
});
} catch (error) {
console.error(chalk.red('❌ 源代码文档生成失败:'), error.message);
throw error;
}
}
module.exports = { exportSourceCodeSimple };Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |