Skip to content

Commit 58187bd

Browse files
authored
Fix a bug (#14)
1 parent ca9fd72 commit 58187bd

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

commands/setup_theme.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@ async function downloadFile(url, outputPath) {
1818
}
1919

2020
const fileStream = fs.createWriteStream(outputPath);
21-
const totalSize = parseInt(response.headers.get('content-length'), 10);
22-
const progressBar = new ProgressBar('Downloading [:bar] :percent :etas', {
23-
complete: '=',
24-
incomplete: ' ',
25-
width: 40,
26-
total: totalSize,
27-
});
21+
const contentLength = response.headers.get('content-length');
22+
let totalSize = parseInt(contentLength, 10);
2823

29-
response.body.on('data', (chunk) => {
30-
progressBar.tick(chunk.length);
31-
});
24+
if (isNaN(totalSize)) {
25+
console.warn(
26+
'Warning: Size of the file is unknown. Progress bar will not be shown.'
27+
);
28+
} else {
29+
const progressBar = new ProgressBar('Downloading [:bar] :percent :etas', {
30+
complete: '=',
31+
incomplete: ' ',
32+
width: 40,
33+
total: totalSize,
34+
});
35+
36+
response.body.on('data', (chunk) => {
37+
progressBar.tick(chunk.length);
38+
});
39+
}
3240

3341
await new Promise((resolve, reject) => {
3442
response.body.pipe(fileStream);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@webredone/trb-cli",
3-
"version": "3.0.4",
3+
"version": "3.0.5",
44
"description": "TRB-CLI is a handy Node.js CLI that automates the process of managing blocks in a Theme Redone WordPress theme",
55
"main": "index.js",
66
"type": "module",

0 commit comments

Comments
 (0)