mirror of
https://github.com/lainbo/component-party.git
synced 2026-04-05 13:09:03 +08:00
improve doc
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { FRAMEWORKS } from '../config.cjs';
|
||||
|
||||
async function main() {
|
||||
const srcDirs = fs.readdirSync('src');
|
||||
|
||||
let rootReadmeContent = fs.readFileSync("README.base.md") + "\n\n";
|
||||
let rootReadmeContent = fs.readFileSync('README.base.md') + '\n\n';
|
||||
|
||||
for(const framework of FRAMEWORKS){
|
||||
fs.writeFileSync(`docs/by-framework/${framework.id}.md`, `# Component Party for ${framework.title}\n\n`)
|
||||
}
|
||||
// for (const framework of FRAMEWORKS) {
|
||||
// fs.writeFileSync(
|
||||
// `docs/by-framework/${framework.id}.md`,
|
||||
// `# Component Party for ${framework.title}\n\n`
|
||||
// );
|
||||
// }
|
||||
|
||||
for (const srcDir of srcDirs) {
|
||||
const sectionDir = `src/${srcDir}`;
|
||||
@@ -17,40 +21,51 @@ async function main() {
|
||||
|
||||
// write section title
|
||||
fileContent += `# ${dirNameToTitle(srcDir)}\n`;
|
||||
for(const framework of FRAMEWORKS){
|
||||
fs.appendFileSync(`docs/by-framework/${framework.id}.md`, `# ${dirNameToTitle(srcDir)}\n`)
|
||||
}
|
||||
// for (const framework of FRAMEWORKS) {
|
||||
// fs.appendFileSync(`docs/by-framework/${framework.id}.md`, `# ${dirNameToTitle(srcDir)}\n`);
|
||||
// }
|
||||
|
||||
for (const subSectionDir of subSectionDirs) {
|
||||
|
||||
// write subsection title
|
||||
fileContent += `## ${dirNameToTitle(subSectionDir)}\n`;
|
||||
for(const framework of FRAMEWORKS){
|
||||
fs.appendFileSync(`docs/by-framework/${framework.id}.md`, `## ${dirNameToTitle(subSectionDir)}\n`)
|
||||
}
|
||||
// for (const framework of FRAMEWORKS) {
|
||||
// fs.appendFileSync(
|
||||
// `docs/by-framework/${framework.id}.md`,
|
||||
// `## ${dirNameToTitle(subSectionDir)}\n`
|
||||
// );
|
||||
// }
|
||||
const frameworkDirs = fs
|
||||
.readdirSync(`${sectionDir}/${subSectionDir}`)
|
||||
.filter((path) => !path.includes('.'));
|
||||
|
||||
|
||||
for (const frameworkDir of frameworkDirs) {
|
||||
fileContent += `### ${FRAMEWORKS.find((f) => f.id === frameworkDir).title}\n`;
|
||||
const files = fs.readdirSync(`${sectionDir}/${subSectionDir}/${frameworkDir}`);
|
||||
|
||||
for (const file of files) {
|
||||
const frameworkFileContent = `\`\`\`${
|
||||
FRAMEWORKS.find((f) => f.id === frameworkDir).ext
|
||||
}\n${fs.readFileSync(
|
||||
|
||||
const parsedFile = path.parse(file);
|
||||
function addSnippetWrap(content) {
|
||||
return `\`\`\`${
|
||||
FRAMEWORKS.find((f) => f.id === frameworkDir).ext
|
||||
}\n${content}\n\`\`\`\n\n`;
|
||||
}
|
||||
console.log(parsedFile)
|
||||
const currentFileContent = fs.readFileSync(
|
||||
`${sectionDir}/${subSectionDir}/${frameworkDir}/${file}`
|
||||
)}\n\`\`\`\n\n`;
|
||||
);
|
||||
|
||||
fileContent += frameworkFileContent
|
||||
const frameworkFileContent =
|
||||
parsedFile.ext === '.md' ? `${currentFileContent}\n` : addSnippetWrap(currentFileContent);
|
||||
|
||||
fs.appendFileSync(`docs/by-framework/${frameworkDir}.md`, frameworkFileContent)
|
||||
fileContent += frameworkFileContent;
|
||||
|
||||
//fs.appendFileSync(`docs/by-framework/${frameworkDir}.md`, frameworkFileContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(`${sectionDir}/README.md`, fileContent, 'utf-8');
|
||||
//fs.writeFileSync(`${sectionDir}/README.md`, fileContent, 'utf-8');
|
||||
|
||||
rootReadmeContent += `${fileContent
|
||||
.split('\n')
|
||||
@@ -58,6 +73,7 @@ async function main() {
|
||||
.join('\n')}\n`;
|
||||
}
|
||||
|
||||
// create /README.md
|
||||
fs.writeFileSync(`README.md`, rootReadmeContent, 'utf-8');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user