gitpick 3.27.0-canary.13 → 3.27.0-canary.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +25 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
for await (const line of spawn(...)) { ... }`);
|
|
4
|
-
`?
|
|
5
|
-
|
|
2
|
+
var wt=Object.defineProperty,oe=Object.defineProperties;var se=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var yt=Object.prototype.hasOwnProperty,bt=Object.prototype.propertyIsEnumerable;var O=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),tt=e=>{throw TypeError(e)};var X=(e,t,r)=>t in e?wt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,b=(e,t)=>{for(var r in t||(t={}))yt.call(t,r)&&X(e,r,t[r]);if(z)for(var r of z(t))bt.call(t,r)&&X(e,r,t[r]);return e},j=(e,t)=>oe(e,se(t));var et=(e,t)=>{var r={};for(var o in e)yt.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(e!=null&&z)for(var o of z(e))t.indexOf(o)<0&&bt.call(e,o)&&(r[o]=e[o]);return r};var ie=(e,t)=>{for(var r in t)wt(e,r,{get:t[r],enumerable:!0})};var xt=(e,t,r)=>X(e,typeof t!="symbol"?t+"":t,r),rt=(e,t,r)=>t.has(e)||tt("Cannot "+r);var l=(e,t,r)=>(rt(e,t,"read from private field"),r?r.call(e):t.get(e)),y=(e,t,r)=>t.has(e)?tt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),g=(e,t,r,o)=>(rt(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r),d=(e,t,r)=>(rt(e,t,"access private method"),r);var $t=(e,t,r,o)=>({set _(s){g(e,t,s,r)},get _(){return l(e,t,o)}});var E=function(e,t){this[0]=e,this[1]=t},ot=(e,t,r)=>{var o=(n,a,p,m)=>{try{var u=r[n](a),w=(a=u.value)instanceof E,x=u.done;Promise.resolve(w?a[0]:a).then(f=>w?o(n==="return"?n:"next",a[1]?{done:f.done,value:f.value}:f,p,m):p({value:f,done:x})).catch(f=>o("throw",f,p,m))}catch(f){m(f)}},s=n=>i[n]=a=>new Promise((p,m)=>o(n,a,p,m)),i={};return r=r.apply(e,t),i[O("asyncIterator")]=()=>i,s("next"),s("throw"),s("return"),i},vt=e=>{var t=e[O("asyncIterator")],r=!1,o,s={};return t==null?(t=e[O("iterator")](),o=i=>s[i]=n=>t[i](n)):(t=t.call(e),o=i=>s[i]=n=>{if(r){if(r=!1,i==="throw")throw n;return n}return r=!0,{done:!1,value:new E(new Promise(a=>{var p=t[i](n);p instanceof Object||tt("Object expected"),a(p)}),1)}}),s[O("iterator")]=()=>s,o("next"),"throw"in t?o("throw"):s.throw=i=>{throw i},"return"in t&&o("return"),s},K=(e,t,r)=>(t=e[O("asyncIterator")])?t.call(e):(e=e[O("iterator")](),t={},r=(o,s)=>(s=e[o])&&(t[o]=i=>new Promise((n,a,p)=>(i=s.call(e,i),p=i.done,Promise.resolve(i.value).then(m=>n({value:m,done:p}),a)))),r("next"),r("return"),t);import re from"fs";import{parseArgs as br}from"node:util";import xr from"path";import J from"node:fs";import yr from"node:os";import Kt from"node:path";import st from"node:fs";import kt from"node:path";var it=async(e,t)=>{let r=await st.promises.readdir(e,{withFileTypes:!0});await st.promises.mkdir(t,{recursive:!0});for(let o of r){if(o.name===".git")continue;let s=kt.join(e,o.name),i=kt.join(t,o.name);o.isDirectory()?await it(s,i):await st.promises.copyFile(s,i)}};import ne from"node:process";import{stripVTControlCharacters as ae}from"node:util";var St=e=>({start:ne.hrtime.bigint(),command:e.map(t=>ce(ae(t))).join(" "),state:{stdout:"",stderr:"",output:""}}),ce=e=>/[^\w./-]/.test(e)?`'${e.replaceAll("'","'\\''")}'`:e;var nt=function(o,s,i){return ot(this,arguments,function*(e,{state:t},r){if(t.isIterating===!1)throw new Error(`The subprocess must be iterated right away, for example:
|
|
3
|
+
for await (const line of spawn(...)) { ... }`);t.isIterating=!0;try{let{[r]:u}=yield new E(e.nodeChildProcess);if(!u)return;let w="";try{for(var n=K(u.iterator({destroyOnReturn:!1})),a,p,m;a=!(p=yield new E(n.next())).done;a=!1){let x=p.value;let f=`${w}${x}`.split(/\r?\n/);w=f.pop(),yield*vt(f)}}catch(p){m=[p]}finally{try{a&&(p=n.return)&&(yield new E(p.call(n)))}finally{if(m)throw m[0]}}w&&(yield w)}finally{yield new E(e)}})},Et=function(...e){return ot(this,null,function*(){try{let t=[];for(;e.length>0;){t=e.map((n,a)=>{var p;return(p=t[a])!=null?p:pe(n)});let[{value:r,done:o},s]=yield new E(Promise.race(t.map((n,a)=>Promise.all([n,a])))),[i]=e.splice(s,1);t.splice(s,1),o||(e.push(i),yield r)}}finally{yield new E(Promise.all(e.map(t=>t.return())))}})},pe=async e=>{try{return await e.next()}catch(t){await e.throw(t)}};import G from"node:path";import Ct from"node:process";import{fileURLToPath as le}from"node:url";var It=p=>{var m=p,{stdin:e,stdout:t,stderr:r,stdio:o=[e,t,r],env:s,preferLocal:i,cwd:n="."}=m,a=et(m,["stdin","stdout","stderr","stdio","env","preferLocal","cwd"]);var f;let u=n instanceof URL?le(n):G.resolve(n),w=s?b(b({},Ct.env),s):void 0,x=(f=o[0])==null?void 0:f.string;return j(b({},a),{input:x,stdio:x===void 0?o:["pipe",...o.slice(1)],env:i?he(w!=null?w:Ct.env,u):w,cwd:u})},he=(s,o)=>{var i=s,{Path:e="",PATH:t=e}=i,r=et(i,["Path","PATH"]);let n=t.split(G.delimiter),a=Bt([],G.resolve(o)).map(p=>G.join(p,"node_modules/.bin")).filter(p=>!n.includes(p));return j(b({},r),{PATH:[...a,t].filter(Boolean).join(G.delimiter)})},Bt=(e,t)=>e.at(-1)===t?e:Bt([...e,t],G.resolve(t,".."));import{pipeline as me}from"node:stream/promises";var Tt=async e=>{var o;let[[t,r]]=await Promise.all([Promise.allSettled(e),ue(e)]);if(r.reason)throw r.reason.pipedFrom=(o=t.reason)!=null?o:t.value,r.reason;if(t.reason)throw t.reason;return j(b({},r.value),{pipedFrom:t.value})},ue=async e=>{try{let[{stdout:t},{stdin:r}]=await Promise.all(e.map(({nodeChildProcess:o})=>o));if(r===null)throw new Error('The "stdin" option must be set on the first "spawn()" call in the pipeline.');if(t===null)throw new Error('The "stdout" option must be set on the last "spawn()" call in the pipeline.');me(t,r).catch(()=>{})}catch(t){throw await Promise.allSettled(e.map(({nodeChildProcess:r})=>fe(r))),t}},fe=async e=>{let{stdin:t}=await e;t.end()};import{on as ge,once as de}from"node:events";import we from"node:process";var jt=async(e,{input:t},r)=>{let o=await e;t!==void 0&&o.stdin.end(t);let s=de(o,"close");try{return await Promise.race([s,...o.stdio.filter(Boolean).map(i=>ye(i))]),be(r,Pt(o)),Rt(r)}catch(i){throw await Promise.allSettled([s]),ct(i,o,r)}},ye=async e=>{try{for(var t=K(ge(e,"error")),r,o,s;r=!(o=await t.next()).done;r=!1){let[i]=o.value;if(!["ERR_STREAM_PREMATURE_CLOSE","EPIPE"].includes(i==null?void 0:i.code))throw i}}catch(o){s=[o]}finally{try{r&&(o=t.return)&&await o.call(t)}finally{if(s)throw s[0]}}},be=({command:e},{exitCode:t,signalName:r})=>{if(r!==void 0)throw new P(`Command was terminated with ${r}: ${e}`);if(t!==void 0)throw new P(`Command failed with exit code ${t}: ${e}`)},ct=(e,t,r)=>Object.assign(xe(e,r),Pt(t),Rt(r)),xe=(e,{command:t})=>e instanceof P?e:new P(`Command failed: ${t}`,{cause:e}),P=class extends Error{constructor(){super(...arguments);xt(this,"name","SubprocessError")}},Pt=({exitCode:e,signalCode:t})=>b(b({},e<1?{}:{exitCode:e}),t===null?{}:{signalName:t}),Rt=({state:{stdout:e,stderr:t,output:r},command:o,start:s})=>({stdout:at(e),stderr:at(t),output:at(r),command:o,durationMs:Number(we.hrtime.bigint()-s)/1e6}),at=e=>e.at(-1)===`
|
|
4
|
+
`?e.slice(0,e.at(-2)==="\r"?-2:-1):e;import{spawn as Ce}from"node:child_process";import{once as Ie}from"node:events";import Ot from"node:process";import{stat as $e}from"node:fs/promises";import Dt from"node:path";import Ft from"node:process";var At=async(e,t,r)=>await ve(e,r)?[lt(e),t.map(o=>Ee(o)),j(b({},r),{shell:!0})]:[e,t,r],ve=async(e,{shell:t,cwd:r,env:o=Ft.env})=>Ft.platform==="win32"&&!t&&!await ke(e,r,o),ke=async(e,t,{Path:r="",PATH:o=r})=>{var s,i;return Mt.some(n=>e.toLowerCase().endsWith(n))||((i=pt[s=`${e}\0${t}\0${o}`])!=null?i:pt[s]=await Se(e,t,o))},pt={},Se=async(e,t,r)=>{let o=r.split(Dt.delimiter).filter(Boolean).map(s=>s.replace(/^"(.*)"$/,"$1"));try{await Promise.all(Mt.flatMap(s=>[t,...o].map(i=>`${Dt.resolve(i,e)}${s}`)).map(async s=>{try{await $e(s)}catch(i){return}throw 0}))}catch(s){return!0}return!1},Mt=[".exe",".com"],Ee=e=>lt(lt(`"${e.replaceAll(/(\\*)"/g,'$1$1\\"').replace(/(\\*)$/,"$1$1")}"`)),lt=e=>e.replaceAll(/([()\][%!^"`<>&|;, *?])/g,"^$1");var Wt=async(e,t,r,o)=>{try{[e,t]=["node","node.exe"].includes(e.toLowerCase())?[Ot.execPath,[...Ot.execArgv.filter(i=>!i.startsWith("--inspect")),...t]]:[e,t];let s=Ce(...await At(e,t,r));return Gt(s.stdout,o,"stdout"),Gt(s.stderr,o,"stderr"),s.once("error",()=>{}),await Ie(s,"spawn"),s}catch(s){throw ct(s,{},o)}},Gt=(e,{state:t},r)=>{e&&(e.setEncoding("utf8"),t.isIterating||(t.isIterating=!1,e.on("data",o=>{t[r]+=o,t.output+=o})))};function R(e,t,r,o){let[s=[],i={}]=Array.isArray(t)?[t,r]:[[],t],n=St([e,...s]),a=It(i),p=Wt(e,s,a,n),m=jt(p,a,n);Object.assign(m,{nodeChildProcess:p}),m=o?Tt([o,m]):m;let u=nt(m,n,"stdout"),w=nt(m,n,"stderr");return Object.assign(m,{nodeChildProcess:p,stdout:u,stderr:w,[Symbol.asyncIterator]:()=>Et(u,w),pipe:(x,f,q)=>R(x,f,q,m)})}import S from"node:process";import{stripVTControlCharacters as hr}from"node:util";var k={};ie(k,{bgBlack:()=>Ne,bgBlue:()=>Ve,bgBlueBright:()=>ar,bgCyan:()=>qe,bgCyanBright:()=>pr,bgGray:()=>Ke,bgGreen:()=>_e,bgGreenBright:()=>ir,bgMagenta:()=>Je,bgMagentaBright:()=>cr,bgRed:()=>He,bgRedBright:()=>sr,bgWhite:()=>ze,bgWhiteBright:()=>lr,bgYellow:()=>Ye,bgYellowBright:()=>nr,black:()=>Ge,blue:()=>B,blueBright:()=>tr,bold:()=>v,cyan:()=>D,cyanBright:()=>rr,dim:()=>Pe,gray:()=>Ue,green:()=>N,greenBright:()=>Ze,hidden:()=>Me,inverse:()=>Ae,italic:()=>Re,magenta:()=>Le,magentaBright:()=>er,overline:()=>Fe,red:()=>We,redBright:()=>Qe,reset:()=>je,strikethrough:()=>Oe,underline:()=>De,white:()=>mt,whiteBright:()=>or,yellow:()=>ht,yellowBright:()=>Xe});import Be from"node:tty";var Lt,Ut,Q,Nt,Ht,Te=(Ht=(Nt=(Q=(Ut=(Lt=Be)==null?void 0:Lt.WriteStream)==null?void 0:Ut.prototype)==null?void 0:Q.hasColors)==null?void 0:Nt.call(Q))!=null?Ht:!1,c=(e,t)=>{if(!Te)return s=>s;let r=`\x1B[${e}m`,o=`\x1B[${t}m`;return s=>{let i=s+"",n=i.indexOf(o);if(n===-1)return r+i+o;let a=r,p=0;for(;n!==-1;)a+=i.slice(p,n)+r,p=n+o.length,n=i.indexOf(o,p);return a+=i.slice(p)+o,a}},je=c(0,0),v=c(1,22),Pe=c(2,22),Re=c(3,23),De=c(4,24),Fe=c(53,55),Ae=c(7,27),Me=c(8,28),Oe=c(9,29),Ge=c(30,39),We=c(31,39),N=c(32,39),ht=c(33,39),B=c(34,39),Le=c(35,39),D=c(36,39),mt=c(37,39),Ue=c(90,39),Ne=c(40,49),He=c(41,49),_e=c(42,49),Ye=c(43,49),Ve=c(44,49),Je=c(45,49),qe=c(46,49),ze=c(47,49),Ke=c(100,49),Qe=c(91,39),Ze=c(92,39),Xe=c(93,39),tr=c(94,39),er=c(95,39),rr=c(96,39),or=c(97,39),sr=c(101,49),ir=c(102,49),nr=c(103,49),ar=c(104,49),cr=c(105,49),pr=c(106,49),lr=c(107,49);var V=S.platform!=="win32"||!!S.env.WT_SESSION,mr=e=>!!(e.isTTY&&S.env.TERM!=="dumb"&&!("CI"in S.env)),ur=k.blue(V?"\u2139":"i"),fr=k.green(V?"\u2714":"\u221A"),gr=k.yellow(V?"\u26A0":"\u203C"),dr=k.red(V?"\u2716\uFE0F":"\xD7"),wr={frames:V?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["-","\\","|","/"],interval:80},W,L,F,A,C,$,M,U,T,I,Y,h,H,_,Z,_t,Yt,Vt,Jt,qt,zt,ut=class{constructor(t={}){y(this,h);y(this,W);y(this,L);y(this,F,-1);y(this,A);y(this,C);y(this,$);y(this,M);y(this,U,0);y(this,T);y(this,I);y(this,Y,0);var o,s,i,n;let r=(o=t.spinner)!=null?o:wr;g(this,W,r.frames),g(this,L,r.interval),g(this,C,(s=t.text)!=null?s:""),g(this,$,(i=t.stream)!=null?i:S.stderr),g(this,M,(n=t.color)!=null?n:"cyan"),g(this,I,mr(l(this,$))),g(this,T,d(this,h,zt).bind(this))}start(t){return t&&g(this,C,t),this.isSpinning?this:(d(this,h,Yt).call(this),d(this,h,_).call(this),d(this,h,Jt).call(this),g(this,A,setInterval(()=>{d(this,h,_).call(this)},l(this,L))),this)}stop(t){return this.isSpinning?(clearInterval(l(this,A)),g(this,A,void 0),d(this,h,Vt).call(this),this.clear(),d(this,h,qt).call(this),t&&l(this,$).write(`${t}
|
|
5
|
+
`),this):this}success(t){return d(this,h,H).call(this,fr,t)}error(t){return d(this,h,H).call(this,dr,t)}warning(t){return d(this,h,H).call(this,gr,t)}info(t){return d(this,h,H).call(this,ur,t)}get isSpinning(){return l(this,A)!==void 0}get text(){return l(this,C)}set text(t){g(this,C,t!=null?t:""),d(this,h,_).call(this)}get color(){return l(this,M)}set color(t){g(this,M,t),d(this,h,_).call(this)}clear(){if(!l(this,I))return this;l(this,$).cursorTo(0);for(let t=0;t<l(this,U);t++)t>0&&l(this,$).moveCursor(0,-1),l(this,$).clearLine(1);return g(this,U,0),this}};W=new WeakMap,L=new WeakMap,F=new WeakMap,A=new WeakMap,C=new WeakMap,$=new WeakMap,M=new WeakMap,U=new WeakMap,T=new WeakMap,I=new WeakMap,Y=new WeakMap,h=new WeakSet,H=function(t,r){return this.stop(`${t} ${r!=null?r:l(this,C)}`)},_=function(){var i;let t=Date.now();(l(this,F)===-1||t-l(this,Y)>=l(this,L))&&(g(this,F,++$t(this,F)._%l(this,W).length),g(this,Y,t));let r=(i=k[l(this,M)])!=null?i:k.cyan,o=l(this,W)[l(this,F)],s=`${r(o)} ${l(this,C)}`;l(this,I)||(s+=`
|
|
6
|
+
`),this.clear(),d(this,h,Z).call(this,s),l(this,I)&&g(this,U,d(this,h,_t).call(this,s))},Z=function(t){l(this,$).write(t)},_t=function(t){var i;let r=(i=l(this,$).columns)!=null?i:80,o=hr(t).split(`
|
|
7
|
+
`),s=0;for(let n of o)s+=Math.max(1,Math.ceil(n.length/r));return s},Yt=function(){l(this,I)&&d(this,h,Z).call(this,"\x1B[?25l")},Vt=function(){l(this,I)&&d(this,h,Z).call(this,"\x1B[?25h")},Jt=function(){S.once("SIGINT",l(this,T)),S.once("SIGTERM",l(this,T))},qt=function(){S.off("SIGINT",l(this,T)),S.off("SIGTERM",l(this,T))},zt=function(t){this.isSpinning&&this.stop();let r=t==="SIGINT"?130:t==="SIGTERM"?143:1;S.exit(r)};function ft(e){return new ut(e)}var gt=async(e,t,r)=>{let o=ft();try{process.platform==="win32"&&await R("git",["config","--global","core.longpaths","true"]);let s=`https://${e.token?e.token+"@":e.token}github.com/${e.owner}/${e.repository}.git`,i=Kt.join(yr.tmpdir(),`${e.repository}-${Date.now()}${Math.random().toString(16).slice(2,6)}`);t.watch||o.start(`Picking ${e.type}${e.type==="repository"?" without .git":" from repository"}`);let n=performance.now();await R("git",["clone",s,i,"--depth","1","--single-branch","--branch",e.branch]);let a=Kt.join(i,e.path);(await J.promises.stat(a)).isDirectory()?(await J.promises.mkdir(r,{recursive:!0}),await it(a,r)):(await J.promises.mkdir(r,{recursive:!0}),await J.promises.copyFile(a,r+"/"+e.path.split("/").pop())),t.watch?console.info("Synced at "+new Date().toLocaleTimeString()):o.success(`Picked ${e.type}${e.type==="repository"?" without .git":" from repository"} in ${((performance.now()-n)/1e3).toFixed(2)} seconds!`),await J.promises.rm(i,{recursive:!0,force:!0})}catch(s){o.stop("Level 2: An error occurred while cloning!"),s instanceof Error?console.error("Error: "+s.message):console.error("Unexpected Error: "+JSON.stringify(s,null,2)),process.exit(1)}};function dt(e){if(typeof e=="number"||/^\d+$/.test(e))return typeof e=="number"?e:parseInt(e,10);let t=/(\d+)([hms])/g,r=0,o;for(;(o=t.exec(e))!==null;){let s=parseInt(o[1],10);switch(o[2]){case"h":r+=s*36e5;break;case"m":r+=s*6e4;break;case"s":r+=s*1e3;break}}return r}var Qt=async e=>{var s,i;let t=(await R("git",["ls-remote",e])).stdout,r=(s=t.match(/(.+)\s+HEAD/))==null?void 0:s[1],o=(i=t.match(new RegExp(`${r}\\s+refs/heads/(.+)`)))==null?void 0:i[1];if(!o)throw new Error("Could not determine default branch!");return o};async function Zt(e,{branch:t,target:r}){let o=/^https:\/\/([^@]+)@github\.com/,s=e.match(o),i="";s&&(i=s[1],e=e.replace(o,"https://github.com"));let n=["git@github.com:","https://github.com/","https://raw.githubusercontent.com/"];for(let q of n)if(e.startsWith(q)){e=e.replace(q,"");break}let a=e.split("/"),p=a[0],m=a[1].endsWith(".git")?a[1].slice(0,-4):a[1],u=a[2]==="blob"?"blob":a[2]==="tree"?"tree":a[2]+a[3]==="refsheads"?"raw":"repository",w=t||(u==="repository"?await Qt(`https://${i&&i+"@"}github.com/${p}/${m}`):u==="raw"?a[4]:a[3]),x=u?u==="raw"?a.slice(5).join("/"):a.slice(4).join("/"):a.slice(2).join("/")||"/",f=r||(u==="blob"?".":x.split("/").pop()||m);return{token:i,owner:p,repository:m,type:u,branch:w,path:x,target:f}}import{cancel as $r,confirm as vr,isCancel as kr}from"@clack/prompts";var te="gitpick",ee="3.27.0-canary.15";var Sr=`
|
|
8
|
+
${v("With GitPick, you can clone precisely what you need.")}
|
|
6
9
|
|
|
7
|
-
${
|
|
10
|
+
${D("gitpick <url>")} ${N("[target]")} ${B("[options]")}
|
|
8
11
|
|
|
9
|
-
${
|
|
12
|
+
${v("Hint:")} Target is optional, and follows default git clone behavior.
|
|
10
13
|
|
|
11
|
-
${
|
|
12
|
-
${
|
|
13
|
-
${
|
|
14
|
+
${v("Arguments:")}
|
|
15
|
+
${D("url")} GitHub URL with path to file/folder/repository
|
|
16
|
+
${N("target")} Directory to clone into (optional)
|
|
14
17
|
|
|
15
|
-
${
|
|
16
|
-
${
|
|
17
|
-
${
|
|
18
|
-
${
|
|
18
|
+
${v("Options:")}
|
|
19
|
+
${B("-b, --branch ")} Branch to clone
|
|
20
|
+
${B("-o, --overwrite")} Skip overwrite prompt
|
|
21
|
+
${B("-w, --watch [time]")} Watch the repository and sync every [time]
|
|
19
22
|
(e.g. 1h, 30m, 15s) default: 1m
|
|
20
|
-
${
|
|
21
|
-
${
|
|
23
|
+
${B("-h, --help")} display help for command
|
|
24
|
+
${B("-v, --version")} display the version number
|
|
22
25
|
|
|
23
|
-
${
|
|
26
|
+
${v("Examples:")}
|
|
24
27
|
$ gitpick <url>
|
|
25
28
|
$ gitpick <url> [target]
|
|
26
29
|
$ gitpick <url> [target] -b [branch]
|
|
27
30
|
$ gitpick <url> [target] -w [time]
|
|
28
31
|
$ gitpick <url> [target] -b [branch] -w [time]
|
|
29
32
|
|
|
30
|
-
\u{1F680} More awesome tools at ${
|
|
31
|
-
`));let
|
|
32
|
-
${
|
|
33
|
-
`)),
|
|
34
|
-
|
|
33
|
+
\u{1F680} More awesome tools at ${D("https://github.com/nrjdalal")}`,Er=e=>{try{return br(e)}catch(t){throw new Error(`Error parsing arguments: ${t.message}`)}},Cr=async()=>{try{let{positionals:e,values:t}=Er({allowPositionals:!0,options:{branch:{type:"string",short:"b"},overwrite:{type:"boolean",short:"o"},force:{type:"boolean",short:"f"},watch:{type:"string",short:"w"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}});e.length||(t.version&&(console.log(`${te}@${ee}`),process.exit(0)),console.log(Sr),process.exit(0)),e[0]==="clone"&&e.shift();let[r,o]=e,s={branch:t.branch,overwrite:t.overwrite,force:t.force,watch:t.watch};s.overwrite=s.overwrite||s.force,s.watch&&(typeof s.watch=="boolean"&&(s.watch="1m"),console.log(`\u{1F440} Watching every ${dt(s.watch)/1e3+"s"}
|
|
34
|
+
`));let i=await Zt(r,{branch:s.branch,target:o});console.log(mt(`
|
|
35
|
+
${v("GitPick")} - Clone specific directories or files from GitHub!
|
|
36
|
+
`)),console.info(`${v(i.owner)}/${v(i.repository)} ${N(`<${i.type}:${i.branch}>`)} ${i.type==="repository"?`> ${D(i.target)}`:`${ht(i.path)} > ${D(`${i.target}${i.type==="blob"?`/${i.path.split("/").pop()}`:""}`)}`}
|
|
37
|
+
`);let n=xr.resolve(i.target);if(s.watch&&(s.overwrite=!0),re.existsSync(n+(i.type==="blob"?"/"+i.path.split("/").pop():""))&&(await re.promises.readdir(n)).length&&!s.overwrite){let a=i.type==="tree"?"The target directory is not empty. Do you want to overwrite the files?":"The target file already exists. Do you want to overwrite the file?",p=await vr({message:a});kr(p)&&($r("Operation cancelled."),process.exit(0)),p||(console.info("Chose not to overwrite files."),process.exit(0)),console.info("You can use -o | --overwrite or -f | --force flag to skip this prompt next time.")}if(await gt(i,s,n),s.watch){let a=dt(s.watch);setInterval(async()=>await gt(i,s,n),a)}process.exit(0)}catch(e){console.error(`
|
|
38
|
+
Error: ${e.message}`),process.exit(1)}};Cr();
|