@begit/core
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -1,2 +0,2 @@ | ||
import{join as g}from"path";import{createWriteStream as x}from"fs";import{mkdir as b}from"fs/promises";import{Readable as u}from"stream";import{finished as A}from"stream/promises";import{homedir as L,tmpdir as E}from"os";import{dirname as R,join as m}from"path";var $=()=>{let a=process.env.XDG_CACHE_HOME??E();return m(a,".begit")},p=()=>m($(),"cache"),l=async(a,r,t)=>{t=t??"HEAD";let e=await fetch(`https://github.com/${a}/${r}/tarball/${t}`);return{body:e.body,name:e.url.split("/").pop()}},h=async(a,r)=>{await b(R(a.toString()),{recursive:!0});let t=x(a);await A(u.fromWeb(r.body).pipe(t))},d=async(a,r)=>(await(await fetch(`https://api.github.com/repos/${a}/${r}/commits?per_page=1`)).json())[0].sha;import{existsSync as C}from"fs";import{extract as D,list as S}from"tar";import{mkdir as T,unlink as w}from"fs/promises";var k=async a=>{let{owner:r,name:t,branch:e}=a,n=await d(r,t),o=g(p(),`${r}-${t}-${n}.tar.gz`);if(C(o))return o;let i=await l(r,t,e);return await h(o,i),o},F=async a=>{let r=[];return await S({file:a,onentry:t=>r.push(t.path)}),r},O=async(a,r,t=null,e=!1)=>{t&&(t=t?.startsWith("/")?t:`/${t}`,t=t?.endsWith("/")?t:`${t}/`),await T(r,{recursive:!0});let o=(await F(a)).find(s=>t?s.includes(t):!1);if(t&&!o)throw new Error("Subdirectory not found");let i=o?o.split("/").length-1:1;await new Promise((s,y)=>D({file:a.toString(),strip:i,C:r,k:!e},o?[o]:void 0,c=>{c&&y(c),s()}))},f=async({repo:a,dest:r,cwd:t,opts:e={cache:!0}})=>{let n=e.cache;t=t??process.cwd(),r=r??a.name;let o=await k(a);await O(o,g(t,r),a.subdir),n||await w(o)},B=async a=>{try{await f(a)}catch(r){if(r.tarCode!=="TAR_ABORT")throw r;let t=r.file;await w(t),await f(a)}};export{f as downloadAndExtract,B as downloadRepo,k as downloadToFile,O as extractFile}; | ||
import{join as d}from"path";import{createWriteStream as y}from"fs";import{mkdir as w}from"fs/promises";import{Readable as x}from"stream";import{finished as b}from"stream/promises";import{homedir as v,tmpdir as u}from"os";import{dirname as A,join as s}from"path";var E=()=>{let a=process.env.XDG_CACHE_HOME??u();return s(a,".begit")},c=()=>s(E(),"cache"),m=async(a,r,t)=>{t=t??"HEAD";let e=await fetch(`https://github.com/${a}/${r}/tarball/${t}`);return{body:e.body,name:e.url.split("/").pop()}},p=async(a,r)=>{await w(A(a.toString()),{recursive:!0});let t=y(a);await b(x.fromWeb(r.body).pipe(t))},l=async(a,r)=>(await(await fetch(`https://api.github.com/repos/${a}/${r}/commits?per_page=1`)).json())[0].sha;import{existsSync as R}from"fs";import{extract as $}from"tar/extract";import{list as C}from"tar/list";import{mkdir as D,unlink as f}from"fs/promises";var S=async a=>{let{owner:r,name:t,branch:e}=a,n=await l(r,t),o=d(c(),`${r}-${t}-${n}.tar.gz`);if(R(o))return o;let i=await m(r,t,e);return await p(o,i),o},T=async a=>{let r=[];return await C({file:a,onentry:t=>r.push(t.path)}),r},k=async(a,r,t=null,e=!1)=>{t&&(t=t?.startsWith("/")?t:`/${t}`,t=t?.endsWith("/")?t:`${t}/`),await D(r,{recursive:!0});let o=(await T(a)).find(g=>t?g.includes(t):!1);if(t&&!o)throw new Error("Subdirectory not found");let i=o?o.split("/").length-1:1;await $({file:a.toString(),strip:i,C:r,k:!e},o?[o]:void 0)},h=async({repo:a,dest:r,cwd:t,opts:e={cache:!0}})=>{let n=e.cache;t=t??process.cwd(),r=r??a.name;let o=await S(a);await k(o,d(t,r),a.subdir),n||await f(o)},z=async a=>{try{await h(a)}catch(r){if(r.tarCode!=="TAR_ABORT")throw r;let t=r.file;await f(t),await h(a)}};export{h as downloadAndExtract,z as downloadRepo,S as downloadToFile,k as extractFile}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@begit/core", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Blazingly fast tool for cloning git repositories, with no reliance on local `git`, or `tar` installs", | ||
@@ -20,16 +20,20 @@ "author": "Thomas Beer", | ||
"types": "./types/index.d.ts", | ||
"default": "./dist/index.js", | ||
"import": "./dist/index.js" | ||
"import": "./dist/index.js", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"git", | ||
"template", | ||
"scaffolding" | ||
], | ||
"devDependencies": { | ||
"@types/node": "^20.12.6", | ||
"@types/node": "^20.12.7", | ||
"@types/tar": "^6.1.12", | ||
"tsup": "^8.0.2", | ||
"typescript": "^5.4.4", | ||
"typescript": "^5.4.5", | ||
"vitest": "^1.4.0" | ||
}, | ||
"dependencies": { | ||
"tar": "^6.2.1" | ||
"tar": "^7.0.0" | ||
}, | ||
@@ -36,0 +40,0 @@ "publishConfig": { |
@@ -6,4 +6,4 @@ # Begit | ||
```ts | ||
import { downloadAndExtract } from "@begit/core"; | ||
await downloadAndExtract({ | ||
import { downloadRepo } from "@begit/core"; | ||
await downloadRepo({ | ||
repo: { | ||
@@ -18,1 +18,5 @@ owner: "Tommypop2", | ||
``` | ||
The code above downloads this repository into a folder named `cool_project`. | ||
Alternatively, `downloadAndExtract` could be used in place of `downloadRepo` to opt out of automatically attempting to handle errors |
@@ -10,2 +10,9 @@ export type Repository = { | ||
export declare const downloadToFile: (repo: Repository) => Promise<string>; | ||
/** | ||
* Extracts a tarball to a given path | ||
* @param tarPath Path to the tarfile to be extracted | ||
* @param dest Destination folder, into which the contents of the tarball will be extracted | ||
* @param subdir Folder within the tarball to extract | ||
* @param overwrite Whether or not to overwrite existing files in the target directory | ||
*/ | ||
export declare const extractFile: (tarPath: string, dest: string, subdir?: string | null, overwrite?: boolean) => Promise<void>; | ||
@@ -21,3 +28,9 @@ export type Options = { | ||
}; | ||
/** | ||
* Downloads given repository to a folder. | ||
*/ | ||
export declare const downloadAndExtract: ({ repo, dest, cwd, opts, }: DownloadAndExtract) => Promise<void>; | ||
/** | ||
* Wrapper around `downloadAndExtract`, which automatically attempts to re-download the tarball if extraction fails | ||
*/ | ||
export declare const downloadRepo: (opts: DownloadAndExtract) => Promise<void>; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14320
58
21
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@isaacs/fs-minipass@4.0.1(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedchownr@3.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedminizlib@3.0.1(transitive)
+ Addedmkdirp@3.0.1(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedrimraf@5.0.10(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedtar@7.4.3(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
+ Addedyallist@5.0.0(transitive)
- Removedchownr@2.0.0(transitive)
- Removedfs-minipass@2.1.0(transitive)
- Removedminipass@3.3.65.0.0(transitive)
- Removedminizlib@2.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedtar@6.2.1(transitive)
- Removedyallist@4.0.0(transitive)
Updatedtar@^7.0.0