@ycmd/commands
Version:
LSK.js CLI Creds is the easiest way to manage GitHub / Gitlab secrets and credentials
14 lines (11 loc) • 4.87 kB
JavaScript
;
var util = require('util');
var path = require('path');
var fs = require('fs');
var child_process = require('child_process');
var ycmd = require('ycmd');
var err = require('@lsk4/err');
var D=Object.defineProperty;var s=(t,r)=>D(t,"name",{value:r,configurable:!0});var v=(t,r)=>()=>(t&&(r=t(t=0)),r);var z=(t,r)=>{for(var e in r)D(t,e,{get:r[e],enumerable:!0});};var a=v(()=>{});var L={};z(L,{run:()=>Z,watch:()=>X});async function U(t,r,e=""){await K(t).then(i=>Promise.all(i.map(n=>{let o=path.join(t,n);return J(o).then(c=>{if(c.isDirectory())return r(path.join(e,n),o,c),U(o,r,path.join(e,n))})})));}async function Q(t,r){let e={};try{e[t]=fs.watch(t,{recursive:!0},r.bind(0,t));}catch(i){if(i.code!=="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM")throw i;e[t]=fs.watch(t,r.bind(0,t)),await U(t,(n,o)=>{e[o]=fs.watch(o,r.bind(0,o));});}return e}async function X(t,r,e={}){let i=path.resolve(".",e.cwd||"."),n=new Set(t.map(p=>path.resolve(i,p)).filter(fs.existsSync)),o=["node_modules"].concat(e.ignore||[]).map(p=>new RegExp(p,"i")),c=0,l=new Set,u=new Map;async function f(){if(await r(),--c)return f()}s(f,"handle");async function m(p,ot,O){if(o.some(F=>F.test(O)))return;let g=path.join(p,O);if(!l.has(g)){if(c++)return c=1;e.clear&&console.clear(),l.add(g),await f(),l.delete(g);}}s(m,"onChange");let _,h,b;for(_ of n){h=await Q(_,m);for(b in h)u.set(b,h[b]);}e.eager&&await r();}async function Z(){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,J,K,P=v(()=>{a();k=util.promisify(child_process.exec),J=util.promisify(fs.stat),K=util.promisify(fs.readdir);s(U,"walk");s(Q,"setup");s(X,"watch");s(Z,"run");});a();a();a();var q=s(t=>t.default||t,"undefault"),B={a:!0,E:!0,z:!0,v:!0,progress:!1,"delete-after":!0,perms:!0},x=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"),M=s(async(t,r,{log:e,...i}={})=>{let n=x(),o=q(await import('rsync')),c={...B,...i},l=new o().flags(c).source(t).destination(r).exclude(n);return e&&e.trace("[copy]",ycmd.getShortPath(t),"~>",ycmd.getShortPath(r)),e&&e.trace("[copy]",l.command()),l.output(u=>{let f=u.toString().trim();f.includes("total size is ")||f.startsWith("building file list")||f.startsWith("done")||e&&e.trace("[copy]","[progress]",u.toString().trim());},()=>{}),l.execute((u,f,m)=>{if(u)throw e&&e.error({code:f,err:u,cmd:m}),new err.Err(u,{code:f,cmd:m});e&&e.info("[copy]",ycmd.getShortPath(t),"~>",ycmd.getShortPath(r));})},"rsync");var G=s(t=>t.default||t,"undefault"),tt=s((t,r)=>{let e;return (...i)=>{clearTimeout(e),e=setTimeout(()=>t(...i),r);}},"debounce"),A=s(async(t,r,{log:e,isWatch:i,isSilent:n,onExec:o}={})=>{let c=path.resolve(t.replace("~",process.env.HOME||"~")),l=path.resolve(r.replace("~",process.env.HOME||"~")),u=tt(async()=>{await M(`${c}/`,`${l}/`,{log:n?null:e}),o&&await o();},100);if(await u(),i){e&&e.debug("[watch]",ycmd.getShortPath(c),"~>",ycmd.getShortPath(l));let{watch:f}=G(await Promise.resolve().then(()=>(P(),L)));await f([c],()=>u(),{ignore:x()});}},"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 C={isSilent:!!+process.env.YCMD_SILENT||ycmd.isCI,isBail:ycmd.isCI,isProd:!!+process.env.YCMD_PROD||!ycmd.isDev,isCjs:!0,libDir:"lib",cjsDir:"cjs"};var Wt=ycmd.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=C.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 A(n,o,{log:t,isSilent:e,isWatch:i});}});
module.exports = Wt;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=copy.js.map