Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/docsbydoxdox/doxdox-fetch
Fetch utilities for doxdox server.
https://github.com/docsbydoxdox/doxdox-fetch
Last synced: about 2 months ago
JSON representation
Fetch utilities for doxdox server.
- Host: GitHub
- URL: https://github.com/docsbydoxdox/doxdox-fetch
- Owner: docsbydoxdox
- License: mit
- Created: 2022-02-27T07:26:09.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-13T00:01:58.000Z (9 months ago)
- Last Synced: 2024-11-28T15:18:42.600Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 546 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# doxdox-fetch
> Fetch utilities for doxdox server.
[![NPM version](https://img.shields.io/npm/v/doxdox-fetch?style=flat-square)](https://www.npmjs.org/package/doxdox-fetch)
[![NPM downloads per month](https://img.shields.io/npm/dm/doxdox-fetch?style=flat-square)](https://www.npmjs.org/package/doxdox-fetch)
[![doxdox documentation](https://img.shields.io/badge/doxdox-documentation-%23E85E95?style=flat-square)](https://doxdox.org)## Install
```bash
$ npm install doxdox-fetch --save
```## Usage
**.env**
```yaml
GITHUB_API_TOKEN_READONLY=xxxxx
```**package.json**
```json
{
"type": "module",
"dependencies": {
"doxdox-fetch": "2.0.0"
},
"devDependencies": {
"dotenv": "16.0.0"
},
"scripts": {
"test": "node -r dotenv/config index.js"
},
"private": true
}
```**index.js**
```typescript
import { downloadFile, getRepoData, parseFiles } from 'doxdox-fetch';import { parseString } from 'doxdox-parser-custom';
import { Doc } from 'doxdox-core';
(async () => {
const repoData = await getRepoData(username, repo, {
GITHUB_API_TOKEN: process.env.GITHUB_API_TOKEN_READONLY
});const selectedBranch =
branch && [repoData.default_branch, ...repoData.tags].includes(branch)
? branch
: repoData.default_branch;const files = await downloadFile(username, repo, selectedBranch, [
/.[jt]s$/,
/package.json$/,
/\.doxdoxignore$/
]);const jsFiles = files.filter(
({ path }) =>
path.match(/\.[jt]sx?$/) &&
!path.match(/\.min\.[jt]sx?$/) &&
!path.match(/\.test\.[jt]sx?$/) &&
!path.match(/^dist\//) &&
!path.match(/__tests__\//)
);const pkgFile = files.find(({ path }) => path.match(/^package\.json$/));
const pkgFileContents = JSON.parse(pkgFile?.content || '{}');
const doc: Doc = {
name: pkgFileContents.name || repoData.name,
description: pkgFileContents.description || repoData.description,
homepage: pkgFileContents.homepage || repoData.html_url,
files: await parseFiles(jsFiles, parseString)
};console.log(doc);
})();
```