doxdox-fetch
v2.0.0
Published
> Fetch utilities for doxdox server.
Downloads
4
Readme
doxdox-fetch
Fetch utilities for doxdox server.
Install
$ npm install doxdox-fetch --save
Usage
.env
GITHUB_API_TOKEN_READONLY=xxxxx
package.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
import { downloadFile, getRepoData, parseFiles } from 'doxdox-fetch';
import { parseString } from 'doxdox-parser-custom';
import { Doc } from 'doxdox-core/dist/types';
(async () => {
const repoData = await getRepoData(username, repo, {
GITHUB_API_TOKEN: process.env.GITHUB_API_TOKEN_READONLY
});
const currentBranch =
branch && [repoData.default_branch, ...repoData.tags].includes(branch)
? branch
: repoData.default_branch;
const files = await downloadFile(username, repo, currentBranch, [
/.[jt]sx?$/,
/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);
})();