UNPKG

@stacksjs/launchpad

Version:
10 lines (9 loc) 1.84 kB
// @bun import"./chunk-8pxdwzvm.js";import{existsSync as R,readFileSync as U,writeFileSync as P}from"fs";import{homedir as V,platform as W}from"os";import{join as K}from"path";import Q from"process";async function X(G,{dryrun:B}){let D=!1,I=Y();for(let[A,E]of I)try{let q="";if(R(A))q=U(A,"utf8");let M=q.includes("# https://github.com/stacksjs/launchpad")||q.includes("# Added by launchpad")||q.includes('eval "$(launchpad dev:shellcode)"')||q.includes("LAUNCHPAD_SHELL_INTEGRATION=1");if(G==="install"){if(M){console.error("hook already integrated:",A);continue}if(!B){let N=q.replace(/\n+$/,` `);P(A,`${N} # Added by launchpad ${E} # https://github.com/stacksjs/launchpad `)}D=!0,console.error(`${A} << \`${E}\``)}else if(G==="uninstall"){if(!M)continue;let T=q.split(` `).filter((J)=>!J.includes("# https://github.com/stacksjs/launchpad")&&!J.includes("# Added by launchpad")&&!J.trim().startsWith("LAUNCHPAD_SHELL_INTEGRATION=1 eval")&&J.trim()!=='eval "$(launchpad dev:shellcode)"');if(!B)P(A,T.join(` `));D=!0,console.error("removed hook:",A)}}catch(q){console.error(`Failed to process ${A}:`,q instanceof Error?q.message:q)}if(B&&D)console.error("%cthis was a dry-run. %cnothing was changed.","color: #5f5fff","color: initial");else switch(G){case"uninstall":if(!D)console.error("nothing to deintegrate found");break;case"install":if(D)console.log("now %crestart your terminal%c for `launchpad` hooks to take effect","color: #5f5fff","color: initial")}}function Y(){let B=V(),D=Q.env.ZDOTDIR||B,I=[K(D,".zshrc"),'eval "$(launchpad dev:shellcode)"'],E=[I,[K(B,".bashrc"),'eval "$(launchpad dev:shellcode)"'],[K(B,".bash_profile"),'eval "$(launchpad dev:shellcode)"']].filter(([q])=>R(q));if(E.length===0){if(W()==="darwin")return[I];console.error("no `.shellrc` files found"),Q.exit(1)}return E}export{X as default}; export{X as A};