Skip to content

Commit

Permalink
docs: improve current API
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxken committed Aug 15, 2024
1 parent 2245e6c commit 666111f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ console.log(scanner.location);

## API

Both `download` and `downloadAndExtract` functions use the same set of options.

```ts
export interface DownloadOptions {
interface DownloadOptions {
/**
* The destination (location) to extract the tar.gz
*
Expand All @@ -58,34 +60,36 @@ export interface DownloadOptions {
*/
token?: string;
}
```

export interface DownloadResult {
### download(repository: string, options?: DownloadOptions): Promise< DownloadResult >
Download the tar.gz archive of the GIT repository.

```ts
interface DownloadResult {
/** Archive or repository location on disk */
location: string;
/** Github repository name */
repository: string;
/** Github organization name */
organization: string;
/** Github branch name */
branch: string;
}
```

export function download(
repo: string,
options?: DownloadOptions
): Promise<DownloadResult>;
### downloadAndExtract(repository: string, options?: DownloadExtractOptions): Promise< DownloadResult >
Use download but extract the tar.gz archive.

export interface DownloadExtractOptions extends DownloadOptions {
```ts
interface DownloadExtractOptions extends DownloadOptions {
/**
* Remove the tar.gz archive after a succesfull extraction
*
* @default true
*/
removeArchive?: boolean;
}

export function downloadAndExtract(
repo: string,
options?: DownloadExtractOptions
): Promise<DownloadResult>;
```

## Contributors ✨
Expand Down
7 changes: 5 additions & 2 deletions src/functions/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface DownloadResult {
repository: string;
/** Github organization name */
organization: string;
/** Github branch name */
branch: string;
}

/**
Expand Down Expand Up @@ -67,7 +69,7 @@ export async function download(
headers: {
"User-Agent": "NodeSecure",
"Accept-Encoding": "gzip, deflate",
Authorization: `token ${token}`
Authorization: typeof token === "string" ? `token ${token}` : void 0
},
maxRedirections: 1
});
Expand All @@ -76,6 +78,7 @@ export async function download(
return {
location,
organization,
repository: repo
repository: repo,
branch
};
}

0 comments on commit 666111f

Please sign in to comment.