Skip to content

Commit

Permalink
remove console logs, commented code, change fs to fse
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJuanAndOnly99 committed Mar 7, 2024
1 parent d5464a7 commit b052b86
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions schema2Markdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fse = require('fs-extra');
const yaml = require('js-yaml');
const path = require('path');

Expand Down Expand Up @@ -77,8 +77,6 @@ function renderRef(contextRef) {
objectRef = "../../" + objectType + "/schemas/" + objectName;
}

console.log('from contextRef:', contextRef, 'to objectRef:', objectRef);

return `**Reference**: [${objectType}/${objectName}](${objectRef})\n\n`;
}

Expand Down Expand Up @@ -115,7 +113,6 @@ function generateObjectMD(schema, title, schemaFolderName, version) {
markdownContent += renderEnum(schema.enum);
}

console.log('hasAllOf/hasProperties', hasAllOf(schema.allOf), hasProperties(schema));
if (hasAllOf(schema.allOf) || hasProperties(schema)) {
// Extract properties, required fields, and $ref from the first allOf object
let root = schema;
Expand Down Expand Up @@ -156,11 +153,10 @@ function generateObjectMD(schema, title, schemaFolderName, version) {
}

const frontMatter = generateFrontMatter(objectName, schema.description);
console.log('frontMatter:', frontMatter);

const outputFileName = `./website/versioned_docs/version-${version}/${schemaFolderName}/schemas/${title.replace(/\s+/g, '')}.md`;

fs.outputFileSync(outputFileName, `---\n${yaml.dump(frontMatter)}\n---\n\n${markdownContent}`);
fse.outputFileSync(outputFileName, `---\n${yaml.dump(frontMatter)}\n---\n\n${markdownContent}`);

// objectName must not contain any spaces
if (objectName != null) {
Expand All @@ -184,7 +180,7 @@ function generateFrontMatter(title, description) {
}

function processSchemaFile(schemaFile, schemaFolderName, version) {
const schemaData = fs.readJSONSync(schemaFile);
const schemaData = fse.readJSONSync(schemaFile);

// if there is allOf, then it is an object
const allOfArray = schemaData.allOf;
Expand All @@ -198,13 +194,12 @@ function processSchemaFile(schemaFile, schemaFolderName, version) {
}
}

// return sidebarItems.flat().filter(item => !item.endsWith('undefined'));
return sidebarItems;
}

function parseSchemaFolder(schemaFolderName, version) {
// Read all files in the schema folder
const schemaFiles = fs.readdirSync("./schemas/"+schemaFolderName)
const schemaFiles = fse.readdirSync("./schemas/"+schemaFolderName)
.filter(file => file.endsWith('.json'))
.map(file => path.join("./schemas/"+schemaFolderName, file));

Expand Down Expand Up @@ -248,7 +243,7 @@ function main() {
sidebarObject.docs["FDC3 Standard"].push(sidebarContextObject)
sidebarObject.docs["FDC3 Standard"].push(sidebarApiObject)

fs.outputJSONSync(
fse.outputJSONSync(
`./website/versioned_sidebars/version-${version}-sidebars.json`,
sidebarObject, { spaces: 2 });
});
Expand Down

0 comments on commit b052b86

Please sign in to comment.