Skip to content

Commit 410cd04

Browse files
Added support for https
1 parent 12e8c27 commit 410cd04

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Added
10+
- Support for https remote files
911
## [2.3.2] - 2021-01-09
1012
### Addded
1113
- `--config-file` parameter

src/utils/files.util.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import { createWriteStream, readdirSync, readFileSync, writeFileSync } from 'fs';
1+
import {
2+
createWriteStream,
3+
readdirSync,
4+
readFileSync,
5+
writeFileSync,
6+
} from 'fs';
27
import * as http from 'http';
8+
import * as https from 'https';
39
import * as yaml from 'js-yaml';
410
import { mkdirSync } from 'mkdir-recursive';
511
import { basename, dirname, extname, resolve as pathResolve } from 'path';
612
import { config } from '../models/config.model';
713

814
const getExtensionRegex = /(\.[a-z0-9]+).*/i;
15+
const isHttpsRegex = /^https/i;
916

1017
export 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

1623
export 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

Comments
 (0)