Comparing version 1.0.0 to 1.1.0
@@ -11,2 +11,3 @@ interface FileConfig { | ||
destination: string; | ||
basedir_only?: boolean; | ||
} | ||
@@ -13,0 +14,0 @@ export declare function fetchFile(config: FileConfig): Promise<void>; |
@@ -1,1 +0,1 @@ | ||
import{mkdirSync as A,writeFileSync as E} from"node:fs";import{basename as G} from"node:path";var x=()=>!!globalThis.Bun,z=()=>!!globalThis.Deno;var p=()=>x()?"bun":z()?"deno":"node";async function q(b,j){switch(p()){case"bun":await Bun.write(b,j);break;case"deno":if(j instanceof Response)j=await j.text();await Deno.writeTextFile(b,j);break;case"node":if(j instanceof Response)j=await j.text();E(b,j);break}}async function M(b){if(!b.branch)b.branch=(await(await fetch(`https://api.github.com/repos/${b.repo}`)).json()).default_branch;await q(`${b.destination}/${G(b.path)}`,await fetch(`https://raw.githubusercontent.com/${b.repo}/${b.branch}/${b.path}`))}async function H(b){const j=await(await fetch(`https://api.github.com/repos/${b.repo}/contents/${b.path??""}`)).json();A(`${b.destination}/${b.path??""}`,{recursive:!0});for(let k of j)switch(k.type){case"file":q(`${b.destination}/${k.path}`,await fetch(k.download_url));break;case"dir":H({repo:b.repo,path:k.path,destination:b.destination});break}}export{M as fetchFile,H as fetchDirectory}; | ||
import{mkdirSync as H,writeFileSync as I} from"node:fs";import{basename as J,dirname as K} from"node:path";var A=!!globalThis.Bun,B=!!globalThis.Deno,E=globalThis.process?.versions?.node&&!A,G=globalThis.window&&!B,v;switch(!0){case A:v="bun";break;case B:v="deno";break;case E:v="node";break;case G:v="browser";break;default:v="unknown";break}var M=!!globalThis.importScripts;async function C(u,j){switch(v){case"bun":await Bun.write(u,j);break;case"deno":await Deno.writeTextFile(u,await j.text());break;case"node":I(u,await j.text());break;default:throw new Error("Not supported")}}async function R(u){if(!u.branch)u.branch=(await(await fetch(`https://api.github.com/repos/${u.repo}`)).json()).default_branch;await C(`${u.destination}/${J(u.path)}`,await fetch(`https://raw.githubusercontent.com/${u.repo}/${u.branch}/${u.path}`))}async function L(u){if(u.basedir_only&&!u.path)throw"path must be specified when basedir_only is true";const j=await(await fetch(`https://api.github.com/repos/${u.repo}/contents/${u.path??""}`)).json(),q=u.basedir_only?K(u.path??""):"",z=`${u.destination}/${u.basedir_only?u.path?.replace(q,"")??"":u.path??""}`;H(z,{recursive:!0});for(let k of j)switch(k.type){case"file":C(`${u.destination}/${u.basedir_only?k.path.replace(q,""):k.path}`,await fetch(k.download_url));break;case"dir":L({repo:u.repo,path:k.path,destination:u.basedir_only?z:u.destination,basedir_only:u.basedir_only});break}}export{R as fetchFile,L as fetchDirectory}; |
{ | ||
"name": "fetchgit", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Easily download files and directories from a GitHub repository.", | ||
@@ -30,5 +30,5 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"bun-types": "latest", | ||
"runtimey": "^0.0.1" | ||
"@types/bun": "latest", | ||
"runtimey": "^0.0.2" | ||
} | ||
} |
@@ -24,4 +24,6 @@ # fetchgit | ||
Set `basedir_only` to `true` if you only want to create the directory without the parent sub-directories of path. | ||
### Fetching an entire repository | ||
@@ -28,0 +30,0 @@ |
Sorry, the diff of this file is not supported yet
5387
21
73