MCPcopy
hub / github.com/asyncapi/spec / convertExample

Function convertExample

scripts/converter/index.js:13–32  ·  view source on GitHub ↗

* This function converts a single example file into a newer version and overwrite the old one. * * @param {*} exampleFile full path to file

(exampleFile)

Source from the content-addressed store, hash-verified

11 * @param {*} exampleFile full path to file
12 */
13function convertExample(exampleFile) {
14 console.warn(`Converting: ${exampleFile}`);
15 const document = fs.readFileSync(exampleFile, 'utf-8');
16 const loadedDocument = jsYaml.load(document);
17 if(loadedDocument.asyncapi === undefined) {
18 //Probably encountered a common file (used in other files), ignore
19 console.error(`___________________________________________________________________________________
20 !!!Manual change required!!!
21
22 ${exampleFile} is a shared resource among other AsyncAPI documents, make sure to manually inspect this!
23
24___________________________________________________________________________________`);
25 return;
26 } else if(loadedDocument.asyncapi === toVersion) {
27 console.warn(`${exampleFile} is already version ${toVersion}`);
28 return;
29 }
30 const convertedDocument = convert(document, toVersion, { });
31 fs.writeFileSync(exampleFile, convertedDocument);
32}
33
34/**
35 * Convert all examples within a single directory and nested directories.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…