UNPKG

@ycmd/commands

Version:

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

16 lines (13 loc) 5.6 kB
'use strict'; var util = require('util'); var path = require('path'); var fs = require('fs'); var child_process = require('child_process'); var err = require('@lsk4/err'); var fishbird = require('fishbird'); var promises = require('fs/promises'); var ycmd = require('ycmd'); var R=Object.defineProperty;var a=(e,o)=>R(e,"name",{value:o,configurable:!0});var v=(e,o)=>()=>(e&&(o=e(e=0)),o);var N=(e,o)=>{for(var t in o)R(e,t,{get:o[t],enumerable:!0});};var p=v(()=>{});var P={};N(P,{run:()=>te,watch:()=>ee});async function M(e,o,t=""){await Z(e).then(r=>Promise.all(r.map(u=>{let n=path.join(e,u);return X(n).then(i=>{if(i.isDirectory())return o(path.join(t,u),n,i),M(n,o,path.join(t,u))})})));}async function G(e,o){let t={};try{t[e]=fs.watch(e,{recursive:!0},o.bind(0,e));}catch(r){if(r.code!=="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM")throw r;t[e]=fs.watch(e,o.bind(0,e)),await M(e,(u,n)=>{t[n]=fs.watch(n,o.bind(0,n));});}return t}async function ee(e,o,t={}){let r=path.resolve(".",t.cwd||"."),u=new Set(e.map(m=>path.resolve(r,m)).filter(fs.existsSync)),n=["node_modules"].concat(t.ignore||[]).map(m=>new RegExp(m,"i")),i=0,f=new Set,s=new Map;async function c(){if(await o(),--i)return c()}a(c,"handle");async function l(m,ue,O){if(n.some(C=>C.test(O)))return;let x=path.join(m,O);if(!f.has(x)){if(i++)return i=1;t.clear&&console.clear(),f.add(x),await c(),f.delete(x);}}a(l,"onChange");let d,g,k;for(d of u){g=await G(d,l);for(k in g)s.set(k,g[k]);}t.eager&&await o();}async function te(){try{let e=await Q.apply(0,arguments);e.stdout&&process.stdout.write(e.stdout),e.stderr&&process.stderr.write(e.stderr);}catch(e){console.log(`[ERROR] ${e.message}`),e.stdout&&process.stdout.write(e.stdout),e.stderr&&process.stderr.write(e.stderr);}}var Q,X,Z,U=v(()=>{p();Q=util.promisify(child_process.exec),X=util.promisify(fs.stat),Z=util.promisify(fs.readdir);a(M,"walk");a(G,"setup");a(ee,"watch");a(te,"run");});p();p();p();var H=a(e=>e.default||e,"undefault"),q={a:!0,E:!0,z:!0,v:!0,progress:!1,"delete-after":!0,perms:!0},S=a(({excludeNodeModules:e=!0,excludeGit:o=!0}={})=>{let t=[".DS_Store",e?null:"node_modules",o?null:".git"];return e&&t.push("node_modules"),o&&t.push(".git"),t},"rsyncExcludes"),$=a(async(e,o,{log:t,...r}={})=>{let u=S(),n=H(await import('rsync')),i={...q,...r},f=new n().flags(i).source(e).destination(o).exclude(u);return t&&t.trace("[copy]",ycmd.getShortPath(e),"~>",ycmd.getShortPath(o)),t&&t.trace("[copy]",f.command()),f.output(s=>{let c=s.toString().trim();c.includes("total size is ")||c.startsWith("building file list")||c.startsWith("done")||t&&t.trace("[copy]","[progress]",s.toString().trim());},()=>{}),f.execute((s,c,l)=>{if(s)throw t&&t.error({code:c,err:s,cmd:l}),new err.Err(s,{code:c,cmd:l});t&&t.info("[copy]",ycmd.getShortPath(e),"~>",ycmd.getShortPath(o));})},"rsync");var oe=a(e=>e.default||e,"undefault"),re=a((e,o)=>{let t;return (...r)=>{clearTimeout(t),t=setTimeout(()=>e(...r),o);}},"debounce"),W=a(async(e,o,{log:t,isWatch:r,isSilent:u,onExec:n}={})=>{let i=path.resolve(e.replace("~",process.env.HOME||"~")),f=path.resolve(o.replace("~",process.env.HOME||"~")),s=re(async()=>{await $(`${i}/`,`${f}/`,{log:u?null:t}),n&&await n();},100);if(await s(),r){t&&t.debug("[watch]",ycmd.getShortPath(i),"~>",ycmd.getShortPath(f));let{watch:c}=oe(await Promise.resolve().then(()=>(U(),P)));await c([i],()=>s(),{ignore:S()});}},"copyWatch");p();var A={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}};p();var I={isSilent:!!+process.env.YCMD_SILENT||ycmd.isCI,isBail:ycmd.isCI,isProd:!!+process.env.YCMD_PROD||!ycmd.isDev,isCjs:!0,libDir:"lib",cjsDir:"cjs"};var ze=ycmd.createCommand({command:"link <from> [to...]",describe:"package to package",builder:e=>e.options({silent:A.silent}),async main({log:e,argv:o}){let{silent:t=I.isSilent}=o,r=o.from,u=o.to,n=path.resolve(`${r.replace("~",process.env.HOME||"~")}/package.json`),i=await ycmd.readJson(n);if(!i)throw e.error("package.json not found"),new err.Err("package.json not found");let f=i?.name;if(!f)throw e.error("package name not found"),new err.Err("package name not found");if(!u.length)throw e.error("to not found"),new err.Err("to not found");await fishbird.map(u,async s=>{let c=`${s}/node_modules/${f}`;if(!await ycmd.readJson(`${s}/package.json`))throw e.error("package.json not found"),new err.Err("package.json not found");t||e.debug("[link]",ycmd.getShortPath(r),"~>",ycmd.getShortPath(c)),await W(r,c,{log:e,isSilent:t,isWatch:!0,async onExec(){let d=await ycmd.readJson(`${s}/package.json`);d["//"]+="/",promises.writeFile(`${s}/package.json`,JSON.stringify(d,null,2));}});});}}); module.exports = ze; //# sourceMappingURL=out.js.map //# sourceMappingURL=link.js.map