UNPKG

@ycmd/commands

Version:

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

14 lines (12 loc) 5.47 kB
import { promisify } from 'util'; import { resolve, join } from 'path'; import { existsSync, watch, stat, readdir } from 'fs'; import { exec } from 'child_process'; import { Err } from '@lsk4/err'; import { map } from 'fishbird'; import { writeFile } from 'fs/promises'; import { isCI, isDev, createCommand, readJson, getShortPath } from 'ycmd'; var D=Object.defineProperty;var a=(e,o)=>D(e,"name",{value:o,configurable:!0});var P=(e,o)=>()=>(e&&(o=e(e=0)),o);var I=(e,o)=>{for(var t in o)D(e,t,{get:o[t],enumerable:!0});};var p=P(()=>{});var J={};I(J,{run:()=>oe,watch:()=>te});async function F(e,o,t=""){await G(e).then(r=>Promise.all(r.map(f=>{let n=join(e,f);return Z(n).then(i=>{if(i.isDirectory())return o(join(t,f),n,i),F(n,o,join(t,f))})})));}async function ee(e,o){let t={};try{t[e]=watch(e,{recursive:!0},o.bind(0,e));}catch(r){if(r.code!=="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM")throw r;t[e]=watch(e,o.bind(0,e)),await F(e,(f,n)=>{t[n]=watch(n,o.bind(0,n));});}return t}async function te(e,o,t={}){let r=resolve(".",t.cwd||"."),f=new Set(e.map(m=>resolve(r,m)).filter(existsSync)),n=["node_modules"].concat(t.ignore||[]).map(m=>new RegExp(m,"i")),i=0,u=new Set,s=new Map;async function c(){if(await o(),--i)return c()}a(c,"handle");async function l(m,ue,v){if(n.some(H=>H.test(v)))return;let E=join(m,v);if(!u.has(E)){if(i++)return i=1;t.clear&&console.clear(),u.add(E),await c(),u.delete(E);}}a(l,"onChange");let d,k,x;for(d of f){k=await ee(d,l);for(x in k)s.set(x,k[x]);}t.eager&&await o();}async function oe(){try{let e=await X.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 X,Z,G,M=P(()=>{p();X=promisify(exec),Z=promisify(stat),G=promisify(readdir);a(F,"walk");a(ee,"setup");a(te,"watch");a(oe,"run");});p();p();p();var q=a(e=>e.default||e,"undefault"),B={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"),R=a(async(e,o,{log:t,...r}={})=>{let f=S(),n=q(await import('rsync')),i={...B,...r},u=new n().flags(i).source(e).destination(o).exclude(f);return t&&t.trace("[copy]",getShortPath(e),"~>",getShortPath(o)),t&&t.trace("[copy]",u.command()),u.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());},()=>{}),u.execute((s,c,l)=>{if(s)throw t&&t.error({code:c,err:s,cmd:l}),new Err(s,{code:c,cmd:l});t&&t.info("[copy]",getShortPath(e),"~>",getShortPath(o));})},"rsync");var re=a(e=>e.default||e,"undefault"),ne=a((e,o)=>{let t;return (...r)=>{clearTimeout(t),t=setTimeout(()=>e(...r),o);}},"debounce"),A=a(async(e,o,{log:t,isWatch:r,isSilent:f,onExec:n}={})=>{let i=resolve(e.replace("~",process.env.HOME||"~")),u=resolve(o.replace("~",process.env.HOME||"~")),s=ne(async()=>{await R(`${i}/`,`${u}/`,{log:f?null:t}),n&&await n();},100);if(await s(),r){t&&t.debug("[watch]",getShortPath(i),"~>",getShortPath(u));let{watch:c}=re(await Promise.resolve().then(()=>(M(),J)));await c([i],()=>s(),{ignore:S()});}},"copyWatch");p();var L={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 N={isSilent:!!+process.env.YCMD_SILENT||isCI,isBail:isCI,isProd:!!+process.env.YCMD_PROD||!isDev,isCjs:!0,libDir:"lib",cjsDir:"cjs"};var Ue=createCommand({command:"link <from> [to...]",describe:"package to package",builder:e=>e.options({silent:L.silent}),async main({log:e,argv:o}){let{silent:t=N.isSilent}=o,r=o.from,f=o.to,n=resolve(`${r.replace("~",process.env.HOME||"~")}/package.json`),i=await readJson(n);if(!i)throw e.error("package.json not found"),new Err("package.json not found");let u=i?.name;if(!u)throw e.error("package name not found"),new Err("package name not found");if(!f.length)throw e.error("to not found"),new Err("to not found");await map(f,async s=>{let c=`${s}/node_modules/${u}`;if(!await readJson(`${s}/package.json`))throw e.error("package.json not found"),new Err("package.json not found");t||e.debug("[link]",getShortPath(r),"~>",getShortPath(c)),await A(r,c,{log:e,isSilent:t,isWatch:!0,async onExec(){let d=await readJson(`${s}/package.json`);d["//"]+="/",writeFile(`${s}/package.json`,JSON.stringify(d,null,2));}});});}}); export { Ue as default }; //# sourceMappingURL=out.js.map //# sourceMappingURL=link.js.map