Skip to content

Commit a4cf076

Browse files
committed
Invalid url error fix; stats.success
1 parent 16cba19 commit a4cf076

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-directory-downloader",
3-
"version": "1.2.0",
3+
"version": "1.2.2",
44
"description": "Download just a sub directory from a GitHub repo",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default async function download(source: string, saveTo: string, config?:
113113
const [, user, repository, ref, dir] = urlParserRegex.exec(new URL(source).pathname) ?? [];
114114

115115
if (!user || !repository) {
116-
console.error('Invalid url');
116+
console.error('Invalid url. It must match: ', urlParserRegex);
117117
return;
118118
}
119119

@@ -161,7 +161,11 @@ export default async function download(source: string, saveTo: string, config?:
161161
};
162162

163163
let downloaded = 0;
164-
const stats: { files: Record<string, string>; downloaded: number } = { files: {}, downloaded: 0 };
164+
const stats: {
165+
files: Record<string, string>;
166+
downloaded: number;
167+
success: boolean;
168+
} = { files: {}, downloaded: 0, success: false };
165169

166170
const download = async (file: TreeItem) => {
167171
let response;
@@ -211,5 +215,8 @@ export default async function download(source: string, saveTo: string, config?:
211215
console.log(`Downloaded ${downloaded}/${files.length} files`);
212216

213217
stats.downloaded = downloaded;
218+
219+
if (files.length === downloaded) stats.success = true;
220+
214221
return stats;
215222
}

tests/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ describe('download', async function () {
1212

1313
expect(Boolean(stats)).to.be.true;
1414

15+
expect(stats?.success).to.be.true;
16+
1517
expect(stats?.downloaded).to.be.eql(Object.keys(stats?.files ?? {}).length);
1618

1719
await fs.remove(tempDir);

0 commit comments

Comments
 (0)