@ycmd/commands
Version:
LSK.js CLI Creds is the easiest way to manage GitHub / Gitlab secrets and credentials
12 lines (10 loc) • 4.8 kB
JavaScript
import { promisify } from 'util';
import { resolve, join } from 'path';
import { existsSync, watch, stat, readdir } from 'fs';
import { exec } from 'child_process';
import { isCI, isDev, createCommand, getShortPath } from 'ycmd';
import { Err } from '@lsk4/err';
var T=Object.defineProperty;var s=(t,r)=>T(t,"name",{value:r,configurable:!0});var v=(t,r)=>()=>(t&&(r=t(t=0)),r);var $=(t,r)=>{for(var e in r)T(t,e,{get:r[e],enumerable:!0});};var a=v(()=>{});var F={};$(F,{run:()=>G,watch:()=>Z});async function A(t,r,e=""){await Q(t).then(i=>Promise.all(i.map(n=>{let o=join(t,n);return K(o).then(c=>{if(c.isDirectory())return r(join(e,n),o,c),A(o,r,join(e,n))})})));}async function X(t,r){let e={};try{e[t]=watch(t,{recursive:!0},r.bind(0,t));}catch(i){if(i.code!=="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM")throw i;e[t]=watch(t,r.bind(0,t)),await A(t,(n,o)=>{e[o]=watch(o,r.bind(0,o));});}return e}async function Z(t,r,e={}){let i=resolve(".",e.cwd||"."),n=new Set(t.map(p=>resolve(i,p)).filter(existsSync)),o=["node_modules"].concat(e.ignore||[]).map(p=>new RegExp(p,"i")),c=0,f=new Set,u=new Map;async function l(){if(await r(),--c)return l()}s(l,"handle");async function y(p,st,D){if(o.some(U=>U.test(D)))return;let x=join(p,D);if(!f.has(x)){if(c++)return c=1;e.clear&&console.clear(),f.add(x),await l(),f.delete(x);}}s(y,"onChange");let O,b,g;for(O of n){b=await X(O,y);for(g in b)u.set(g,b[g]);}e.eager&&await r();}async function G(){try{let t=await J.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 J,K,Q,L=v(()=>{a();J=promisify(exec),K=promisify(stat),Q=promisify(readdir);s(A,"walk");s(X,"setup");s(Z,"watch");s(G,"run");});a();a();a();var B=s(t=>t.default||t,"undefault"),H={a:!0,E:!0,z:!0,v:!0,progress:!1,"delete-after":!0,perms:!0},E=s(({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=s(async(t,r,{log:e,...i}={})=>{let n=E(),o=B(await import('rsync')),c={...H,...i},f=new o().flags(c).source(t).destination(r).exclude(n);return e&&e.trace("[copy]",getShortPath(t),"~>",getShortPath(r)),e&&e.trace("[copy]",f.command()),f.output(u=>{let l=u.toString().trim();l.includes("total size is ")||l.startsWith("building file list")||l.startsWith("done")||e&&e.trace("[copy]","[progress]",u.toString().trim());},()=>{}),f.execute((u,l,y)=>{if(u)throw e&&e.error({code:l,err:u,cmd:y}),new Err(u,{code:l,cmd:y});e&&e.info("[copy]",getShortPath(t),"~>",getShortPath(r));})},"rsync");var tt=s(t=>t.default||t,"undefault"),et=s((t,r)=>{let e;return (...i)=>{clearTimeout(e),e=setTimeout(()=>t(...i),r);}},"debounce"),C=s(async(t,r,{log:e,isWatch:i,isSilent:n,onExec:o}={})=>{let c=resolve(t.replace("~",process.env.HOME||"~")),f=resolve(r.replace("~",process.env.HOME||"~")),u=et(async()=>{await P(`${c}/`,`${f}/`,{log:n?null:e}),o&&await o();},100);if(await u(),i){e&&e.debug("[watch]",getShortPath(c),"~>",getShortPath(f));let{watch:l}=tt(await Promise.resolve().then(()=>(L(),F)));await l([c],()=>u(),{ignore:E()});}},"copyWatch");a();var R={watch:{alias:"w",describe:"monitor files for changes",type:"boolean",default:!1},prod:{alias:"p",describe:"enable code optimization for production",type:"boolean",default:!1},silent:{alias:["s","q","quiet"],describe:"run in silent mode, show errors only",type:"boolean",default:!1},exec:{alias:"e",describe:"executes after compilation",type:["boolean","string"],default:!1},dry:{alias:["d","dry-run","without-publish"],describe:"run in dry mode, without publishing",type:"boolean",default:!1},dist:{describe:"specify the output directory",type:"string"},force:{alias:["f"],describe:"force to run",type:"boolean",default:!1},dts:{describe:"generate dts files",type:"boolean",default:!0},yes:{alias:["y"],describe:"automatically say yes to all prompts",type:"boolean",default:!1},bail:{alias:"b",describe:"stop running after the first failure",type:"boolean",default:!1},clean:{alias:"c",describe:"clean the output directory before building",type:"boolean",default:!1}};a();var I={isSilent:!!+process.env.YCMD_SILENT||isCI,isBail:isCI,isProd:!!+process.env.YCMD_PROD||!isDev,isCjs:!0,libDir:"lib",cjsDir:"cjs"};var Mt=createCommand({command:"copy [-w][-s] <from> <to>",describe:"copy with watch",builder:t=>t.options({watch:R.watch,silent:R.silent}),async main({log:t,argv:r}){let{silent:e=I.isSilent,watch:i=!0}=r,n=r.from,o=r.to;if(!n)throw new Error("from not found");if(!o)throw new Error("to not found");await C(n,o,{log:t,isSilent:e,isWatch:i});}});
export { Mt as default };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=copy.js.map