Skip to content

Commit

Permalink
refactor!: migrate to TypeScript and enhance API (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxken authored Aug 15, 2024
1 parent 8e27959 commit f51b342
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 324 deletions.
7 changes: 0 additions & 7 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ docs/
temp/
.vscode/
jsdoc/
dist/
55 changes: 11 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[![OpenSSF
Scorecard](https://api.securityscorecards.dev/projects/github.com/NodeSecure/github/badge?style=for-the-badge)](https://api.securityscorecards.dev/projects/github.com/NodeSecure/github)
![MIT](https://img.shields.io/github/license/NodeSecure/github.svg?style=for-the-badge)
![known vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/NodeSecure/github?style=for-the-badge)
![build](https://img.shields.io/github/actions/workflow/status/NodeSecure/github/node.js.yml?style=for-the-badge)

Download and (optionaly) extract github repository archive.
Expand Down Expand Up @@ -34,12 +33,6 @@ console.log(utils.location);

const scanner = await github.downloadAndExtract("NodeSecure.scanner");
console.log(scanner.location);

const contributors = await github.getContributorsLastActivities(
"NodeSecure",
"scanner"
);
console.log(contributors);
```

## API
Expand All @@ -66,15 +59,6 @@ export interface DownloadOptions {
token?: string;
}

export type ExtractOptions = DownloadOptions & {
/**
* Remove the tar.gz archive after a succesfull extraction
*
* @default true
*/
removeArchive?: boolean;
};

export interface DownloadResult {
/** Archive or repository location on disk */
location: string;
Expand All @@ -84,41 +68,24 @@ export interface DownloadResult {
organization: string;
}

export interface GetContributorsLastActivities {
token?: string;
}

export interface GetContributorsLastActivitiesResult {
[key: string]: {
repository: string;
actualRepo: boolean;
lastActivity: string;
}[];
}
export function download(
repo: string,
options?: DownloadOptions
): Promise<DownloadResult>;

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

export function downloadAndExtract(
repo: string,
options?: ExtractOptions
options?: DownloadExtractOptions
): Promise<DownloadResult>;
export function getContributorsLastActivities(
owner: string,
repository: string,
options?: GetContributorsLastActivities
): Promise<GetContributorsLastActivitiesResult | null>;
export function setToken(githubToken: string): void;
```

### Private repositories

To work with private repositories you can either setup a `GITHUB_TOKEN` system variable or use `setToken` method:

```js
import * as github from "@nodesecure/github";

github.setToken("...");
```

## Contributors ✨
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { typescriptConfig } from "@openally/config.eslint";

export default typescriptConfig();
59 changes: 0 additions & 59 deletions index.d.ts

This file was deleted.

156 changes: 0 additions & 156 deletions index.js

This file was deleted.

21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
"version": "1.2.0",
"description": "Download repository from github",
"type": "module",
"exports": "./index.js",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"prepublishOnly": "pkg-ok",
"test": "node -r dotenv --test",
"build": "tsc",
"prepublishOnly": "npm run build",
"lint": "eslint src",
"test": "glob -c \"tsx --test\" \"./test/**/*.spec.ts\"",
"coverage": "c8 -r html npm test"
},
"repository": {
Expand All @@ -20,8 +23,7 @@
"archive"
],
"files": [
"index.js",
"index.d.ts"
"dist"
],
"author": "GENTILHOMME Thomas <[email protected]>",
"license": "MIT",
Expand All @@ -34,12 +36,15 @@
"tar-fs": "^3.0.5"
},
"devDependencies": {
"@nodesecure/eslint-config": "^1.9.0",
"@openally/config.eslint": "^1.0.0",
"@openally/config.typescript": "^1.0.3",
"@slimio/is": "^2.0.0",
"@types/node": "^22.3.0",
"@types/tar-fs": "^2.0.4",
"c8": "^10.1.2",
"dotenv": "^16.0.2",
"eslint": "^9.5.0",
"pkg-ok": "^3.0.0"
"tsx": "^4.17.0",
"typescript": "^5.5.4"
},
"engines": {
"node": ">=18"
Expand Down
Loading

0 comments on commit f51b342

Please sign in to comment.