Skip to content

Commit

Permalink
Merge branch 'master' into samz/fix-generate-from-template
Browse files Browse the repository at this point in the history
  • Loading branch information
asyncapi-bot authored May 15, 2024
2 parents 11c27a1 + 01f068a commit 4a82c4e
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions scripts/fetch-asyncapi-example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */

const request = require('request');
const fetch = require('node-fetch');
const fs = require('fs');
const unzipper = require('unzipper');
const path = require('path');
Expand All @@ -23,14 +23,28 @@ const EXAMPLE_DIRECTORY = path.join(__dirname, '../assets/examples');
const TEMP_ZIP_NAME = 'spec-examples.zip';

const fetchAsyncAPIExamplesFromExternalURL = () => {
return new Promise((resolve, reject) => {
request(SPEC_EXAMPLES_ZIP_URL)
.pipe(fs.createWriteStream(TEMP_ZIP_NAME))
.on('close', () => {
console.log('Fetched ZIP file');
resolve();
}).on('error', reject);
});
try {
return new Promise((resolve, reject) => {
fetch(SPEC_EXAMPLES_ZIP_URL)
.then((res) => {
if (res.status !== 200) {
reject(new Error(`Failed to fetch examples from ${SPEC_EXAMPLES_ZIP_URL}`));
}
const file = fs.createWriteStream(TEMP_ZIP_NAME);
res.body.pipe(file);
file.on('close', () => {
console.log('Fetched ZIP file');
file.close();
resolve();
}).on('error', (err) => {
reject(err);
});
})
.catch(reject);
});
} catch (error) {
console.error(error);
}
};

const unzipAsyncAPIExamples = async () => {
Expand Down

0 comments on commit 4a82c4e

Please sign in to comment.