mirror of
https://github.com/lainbo/component-party.git
synced 2026-04-05 13:09:03 +08:00
feat(contentGen): just change files without rm generatedContentDir to not break dev watch
This commit is contained in:
@@ -13,6 +13,15 @@ import {
|
||||
mustUseAngularHighlighter,
|
||||
} from "./angularHighlighter.js";
|
||||
|
||||
async function pathExists(path) {
|
||||
try {
|
||||
await fs.access(path);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default async function generateContent() {
|
||||
const highlighter = await getHighlighter({
|
||||
theme: componentPartyShikiTheme,
|
||||
@@ -57,7 +66,9 @@ export default async function generateContent() {
|
||||
|
||||
const frameworksDirPath = path.join(snippetsDirPath, snippetDirName);
|
||||
const frameworkIds = await fs.readdir(frameworksDirPath);
|
||||
for (const frameworkId of frameworkIds) {
|
||||
|
||||
await Promise.all(
|
||||
frameworkIds.map(async (frameworkId) => {
|
||||
const frameworkSnippet = {
|
||||
frameworkId,
|
||||
snippetId,
|
||||
@@ -87,7 +98,11 @@ export default async function generateContent() {
|
||||
frameworkSnippet.markdownFiles.push(file);
|
||||
} else {
|
||||
file.contentHtml = mustUseAngularHighlighter(content)
|
||||
? highlightAngularComponent(highlighter.codeToHtml, content, ext)
|
||||
? highlightAngularComponent(
|
||||
highlighter.codeToHtml,
|
||||
content,
|
||||
ext
|
||||
)
|
||||
: highlighter.codeToHtml(content, { lang: ext });
|
||||
|
||||
frameworkSnippet.files.push(file);
|
||||
@@ -110,7 +125,8 @@ export default async function generateContent() {
|
||||
}
|
||||
|
||||
byFrameworkId[frameworkId].push(frameworkSnippet);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,9 +134,11 @@ export default async function generateContent() {
|
||||
const frameworkDirPath = path.join(generatedContentDirPath, "framework");
|
||||
const treeFilePath = path.join(generatedContentDirPath, "tree.js");
|
||||
const frameworkIndexPath = path.join(frameworkDirPath, "index.js");
|
||||
await fs.rm(generatedContentDirPath, { recursive: true, force: true });
|
||||
const commentDisclaimer = `// File generated from "node scripts/generateContent.js", DO NOT EDIT/COMMIT`;
|
||||
|
||||
if (!(await pathExists(generatedContentDirPath))) {
|
||||
await fs.mkdir(generatedContentDirPath, { recursive: true });
|
||||
const commentDisclaimer = `// File generated from "node scripts/generateContent.js", DO NOT EDIT`;
|
||||
}
|
||||
|
||||
await writeJsFile(
|
||||
treeFilePath,
|
||||
@@ -131,17 +149,25 @@ export default async function generateContent() {
|
||||
`
|
||||
);
|
||||
|
||||
if (!(await pathExists(frameworkDirPath))) {
|
||||
await fs.mkdir(frameworkDirPath, { recursive: true });
|
||||
for (const frameworkId of Object.keys(byFrameworkId)) {
|
||||
const frameworkFilePath = path.join(frameworkDirPath, `${frameworkId}.js`);
|
||||
await writeJsFile(
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
Object.keys(byFrameworkId).map((frameworkId) => {
|
||||
const frameworkFilePath = path.join(
|
||||
frameworkDirPath,
|
||||
`${frameworkId}.js`
|
||||
);
|
||||
return writeJsFile(
|
||||
frameworkFilePath,
|
||||
`
|
||||
${commentDisclaimer}
|
||||
export default ${JSON.stringify(byFrameworkId[frameworkId], null, 2)}
|
||||
`
|
||||
);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
await writeJsFile(
|
||||
frameworkIndexPath,
|
||||
|
||||
Reference in New Issue
Block a user