Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use node-fetch instead of request #1422

Merged
merged 5 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading