UNPKG

@ycmd/commands

Version:

LSK.js CLI Creds is the easiest way to manage GitHub / Gitlab secrets and credentials

12 lines (10 loc) 3.31 kB
import { promisify } from 'util'; import { resolve, join } from 'path'; import { existsSync, watch, stat, readdir } from 'fs'; import { exec } from 'child_process'; import { getShortPath } from 'ycmd'; import { Err } from '@lsk4/err'; var v=Object.defineProperty;var o=(t,r)=>v(t,"name",{value:r,configurable:!0});var T=(t,r)=>()=>(t&&(r=t(t=0)),r);var $=(t,r)=>{for(var e in r)v(t,e,{get:r[e],enumerable:!0});};var p=T(()=>{});var W={};$(W,{run:()=>X,watch:()=>Q});async function L(t,r,e=""){await J(t).then(s=>Promise.all(s.map(u=>{let n=join(t,u);return q(n).then(i=>{if(i.isDirectory())return r(join(e,u),n,i),L(n,r,join(e,u))})})));}async function K(t,r){let e={};try{e[t]=watch(t,{recursive:!0},r.bind(0,t));}catch(s){if(s.code!=="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM")throw s;e[t]=watch(t,r.bind(0,t)),await L(t,(u,n)=>{e[n]=watch(n,r.bind(0,n));});}return e}async function Q(t,r,e={}){let s=resolve(".",e.cwd||"."),u=new Set(t.map(m=>resolve(s,m)).filter(existsSync)),n=["node_modules"].concat(e.ignore||[]).map(m=>new RegExp(m,"i")),i=0,f=new Set,c=new Map;async function a(){if(await r(),--i)return a()}o(a,"handle");async function d(m,C,S){if(n.some(U=>U.test(S)))return;let g=join(m,S);if(!f.has(g)){if(i++)return i=1;e.clear&&console.clear(),f.add(g),await a(),f.delete(g);}}o(d,"onChange");let R,y,h;for(R of u){y=await K(R,d);for(h in y)c.set(h,y[h]);}e.eager&&await r();}async function X(){try{let t=await k.apply(0,arguments);t.stdout&&process.stdout.write(t.stdout),t.stderr&&process.stderr.write(t.stderr);}catch(t){console.log(`[ERROR] ${t.message}`),t.stdout&&process.stdout.write(t.stdout),t.stderr&&process.stderr.write(t.stderr);}}var k,q,J,b=T(()=>{p();k=promisify(exec),q=promisify(stat),J=promisify(readdir);o(L,"walk");o(K,"setup");o(Q,"watch");o(X,"run");});p();p();var H=o(t=>t.default||t,"undefault"),j={a:!0,E:!0,z:!0,v:!0,progress:!1,"delete-after":!0,perms:!0},x=o(({excludeNodeModules:t=!0,excludeGit:r=!0}={})=>{let e=[".DS_Store",t?null:"node_modules",r?null:".git"];return t&&e.push("node_modules"),r&&e.push(".git"),e},"rsyncExcludes"),P=o(async(t,r,{log:e,...s}={})=>{let u=x(),n=H(await import('rsync')),i={...j,...s},f=new n().flags(i).source(t).destination(r).exclude(u);return e&&e.trace("[copy]",getShortPath(t),"~>",getShortPath(r)),e&&e.trace("[copy]",f.command()),f.output(c=>{let a=c.toString().trim();a.includes("total size is ")||a.startsWith("building file list")||a.startsWith("done")||e&&e.trace("[copy]","[progress]",c.toString().trim());},()=>{}),f.execute((c,a,d)=>{if(c)throw e&&e.error({code:a,err:c,cmd:d}),new Err(c,{code:a,cmd:d});e&&e.info("[copy]",getShortPath(t),"~>",getShortPath(r));})},"rsync");var Y=o(t=>t.default||t,"undefault"),Z=o((t,r)=>{let e;return (...s)=>{clearTimeout(e),e=setTimeout(()=>t(...s),r);}},"debounce"),yt=o(async(t,r,{log:e,isWatch:s,isSilent:u,onExec:n}={})=>{let i=resolve(t.replace("~",process.env.HOME||"~")),f=resolve(r.replace("~",process.env.HOME||"~")),c=Z(async()=>{await P(`${i}/`,`${f}/`,{log:u?null:e}),n&&await n();},100);if(await c(),s){e&&e.debug("[watch]",getShortPath(i),"~>",getShortPath(f));let{watch:a}=Y(await Promise.resolve().then(()=>(b(),W)));await a([i],()=>c(),{ignore:x()});}},"copyWatch"); export { yt as copyWatch }; //# sourceMappingURL=out.js.map //# sourceMappingURL=_copyWatch.js.map