1- import { createWriteStream , readdirSync , readFileSync , writeFileSync } from 'fs' ;
1+ import {
2+ createWriteStream ,
3+ readdirSync ,
4+ readFileSync ,
5+ writeFileSync ,
6+ } from 'fs' ;
27import * as http from 'http' ;
8+ import * as https from 'https' ;
39import * as yaml from 'js-yaml' ;
410import { mkdirSync } from 'mkdir-recursive' ;
511import { basename , dirname , extname , resolve as pathResolve } from 'path' ;
612import { config } from '../models/config.model' ;
713
814const getExtensionRegex = / ( \. [ a - z 0 - 9 ] + ) .* / i;
15+ const isHttpsRegex = / ^ h t t p s / i;
916
1017export function getAllFoldersFrom ( path ) {
1118 return readdirSync ( path , { withFileTypes : true } )
12- . filter ( el => el . isDirectory ( ) )
13- . map ( el => el . name ) ;
19+ . filter ( ( el ) => el . isDirectory ( ) )
20+ . map ( ( el ) => el . name ) ;
1421}
1522
1623export function makeDir ( dest ) : void {
@@ -22,7 +29,8 @@ export async function downloadFile(url, dest): Promise<string> {
2229 return new Promise ( ( resolve , error ) => {
2330 try {
2431 const file = createWriteStream ( dest ) ;
25- http . get ( url , function ( response ) {
32+ const protocol = isHttpsRegex . test ( url ) ? https : http ;
33+ protocol . get ( url , function ( response ) {
2634 response . pipe ( file ) ;
2735 file . on ( 'finish' , ( ) => {
2836 file . close ( ) ;
0 commit comments