Skip to content

Commit

Permalink
Merge pull request #25543 from mshima/download
Browse files Browse the repository at this point in the history
switch download command to use axios
  • Loading branch information
deepu105 committed Mar 19, 2024
2 parents a8ba4be + 7b8e16c commit 5c85ee5
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions cli/download.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fs from 'fs';
import { get } from 'https';
import { writeFile } from 'fs/promises';
import path from 'path';
import { inspect } from 'util';
import axios from 'axios';

import { logger } from './utils.mjs';
import { packageJson } from '../lib/index.js';

const downloadFile = (url: string, filename: string): Promise<string> => {
return new Promise((resolve, reject) => {
logger.verboseInfo(`Downloading file: ${url}`);
get(url, response => {
if (response.statusCode !== 200) {
reject(new Error(`Error downloading ${url}: ${response.statusCode} - ${response.statusMessage}`));
return;
}

logger.debug(`Creating file: ${path.join(filename)}`);
const fileStream = fs.createWriteStream(`${filename}`);
fileStream.on('finish', () => fileStream.close());
fileStream.on('close', () => resolve(filename));
response.pipe(fileStream);
}).on('error', e => {
reject(e);
});
});
const downloadFile = async (url: string, filename: string): Promise<string> => {
logger.verboseInfo(`Downloading file: ${url}`);
const response = await axios.get(url);
if (response.status !== 200) {
throw new Error(`Error downloading ${url}: ${response.status} - ${response.statusText}`);
}
logger.debug(`Creating file: ${path.join(filename)}`);
await writeFile(filename, response.data, 'utf8');
return filename;
};

export type DownloadJdlOptions = { skipSampleRepository?: boolean };
Expand Down

0 comments on commit 5c85ee5

Please sign in to comment.