Befor generating

This commit is contained in:
marys
2026-06-01 13:17:37 +02:00
parent 3383f4bf4a
commit 1aa1b5f625
6756 changed files with 649946 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
const path = require('path');
const fs = require('fs');
const definitionsDirectory = path.resolve(__dirname, '../../definitions');
const outputDirectory = path.resolve(__dirname, '../../schemas');
console.log(`Looking for separate definitions in the following directory: ${definitionsDirectory}`);
console.log(`Using the following output directory: ${outputDirectory}`);
/**
* When run, go through all versions that have split definitions and bundles them together.
*/
(async () => {
const versions = await fs.promises.readdir(definitionsDirectory);
console.log(`Ensuring output directory is present ${outputDirectory}`);
if (!fs.existsSync(outputDirectory)) {
await fs.promises.mkdir(outputDirectory);
}
console.log(`The following versions have separate definitions: ${versions.join(',')}`);
for (const version of versions) {
const Bundler = require("@hyperjump/json-schema-bundle");
try{
console.log(`Bundling the following version together: ${version}`);
const versionDir = path.resolve(definitionsDirectory, version);
const definitions = await fs.promises.readdir(versionDir);
const definitionFiles = definitions.filter((value) => {return !value.includes('asyncapi')}).map((file) => fs.readFileSync(path.resolve(versionDir, file)));
const definitionJson = definitionFiles.map((file) => JSON.parse(file));
for (const jsonFile of definitionJson) {
Bundler.add(jsonFile);
}
const filePathToBundle = `file://${versionDir}/asyncapi.json`;
const fileToBundle = await Bundler.get(filePathToBundle);
const bundledSchema = await Bundler.bundle(fileToBundle);
bundledSchema.description = `!!Auto generated!! \n Do not manually edit. ${bundledSchema.description ?? ''}`;
const outputFile = path.resolve(outputDirectory, `${version}.json`);
console.log(`Writing the bundled file to: ${outputFile}`);
await fs.promises.writeFile(outputFile, JSON.stringify(bundledSchema, null, 4));
}catch(e) {
console.log(e);
}
}
console.log('done');
})();