UNPKG

@stacksjs/launchpad

Version:
12 lines (11 loc) 7.26 kB
#!/usr/bin/env bun // @bun import{x as V,y}from"./chunk-wnwbsmkf.js";import{N as G}from"./chunk-83b6axd0.js";import"./chunk-kd525svk.js";import"./chunk-6qxbw28k.js";import{Ka as F,La as w,xa as L}from"./chunk-wkk6vc0r.js";import{Ya as $}from"./chunk-f8dcmgkp.js";import"./chunk-fhet42vs.js";import"./chunk-b9hx8gsj.js";import{bb as R,cb as S}from"./chunk-8pxdwzvm.js";import{spawnSync as U}from"child_process";import W from"process";import{parseArgs as v}from"util";import C from"fs";import A from"path";function D(){let E=[],q=new $("/usr/local/bin");if(q.isDirectory())E.push(q);let K=$.home().join(".local","bin");if(K.isDirectory())E.push(K);return E}async function I(E){let[q]=E.split("@"),K=L(q),J=F(q);if(!J)return console.error(`\u274C Package '${q}' not found in registry`),!1;if(!J.programs||J.programs.length===0)return console.error(`\u274C Package '${q}' does not provide any programs`),!1;let M=D();if(M.length===0)return console.error("\u274C No binary directories found (checked /usr/local/bin and ~/.local/bin)"),!1;console.log(`\uD83D\uDDD1\uFE0F Uninstalling ${q} (\x1B[3m${K}\x1B[0m)...`);let z=[],O=[],Y=!1;for(let H of J.programs){let Z=!1;for(let j of M){let X=j.join(H);if(X.exists()&&!X.isDirectory()){Z=!0,Y=!0;try{await C.promises.unlink(X.string),z.push({program:H,location:j.string}),console.log(` \uD83D\uDDD1\uFE0F Removed ${H} from ${j.string}`)}catch(Q){if(Q instanceof Error&&"code"in Q&&Q.code==="EACCES")console.log(` \u26A0\uFE0F Permission denied: ${H} in ${j.string} (try with sudo)`);else return console.error(` \u274C Failed to remove ${H} from ${j.string}: ${Q}`),!1}}}if(!Z)O.push(H)}if(z.length>0){let H=z.length===1?"binary":"binaries",Z=q!==K?`${q} (\x1B[3m${K}\x1B[0m)`:q;console.log(`\u2705 Successfully uninstalled ${Z}`),console.log(` Removed ${z.length} ${H}:`);let j=z.reduce((X,Q)=>{if(!X[Q.location])X[Q.location]=[];return X[Q.location].push(Q.program),X},{});for(let[X,Q]of Object.entries(j))console.log(` \u2022 ${X}: ${Q.join(", ")}`)}if(O.length>0){let H=O.length===1?"binary was":"binaries were";console.log(`\u26A0\uFE0F ${O.length} expected ${H} not found: ${O.join(", ")}`),console.log(" (May have been previously removed or installed elsewhere)")}if(!Y)return console.log(`\u2139\uFE0F No binaries were found for ${q} - package may not be installed`),console.log(` (Checked: ${M.map((H)=>H.string).join(", ")})`),!1;return!0}async function d(){console.log("\uD83D\uDDD1\uFE0F Uninstalling all Launchpad packages and data...");try{let E=[new $("/usr/local"),$.home().join(".local")],q=0,K=[];for(let J of E){if(!J.isDirectory())continue;let M=[J.join("bin"),J.join("lib"),J.join("share"),J.join("pkgs")],z=0;for(let O of M)if(O.isDirectory())await C.promises.rm(O.string,{recursive:!0,force:!0}),z++,q++,console.log(` \uD83D\uDDD1\uFE0F Removed ${A.basename(O.string)} directory from ${J.string}`);if(z>0)K.push(J.string)}if(q>0)console.log(`\u2705 Successfully uninstalled all Launchpad data (${q} directories removed)`),console.log(` Cleaned locations: ${K.join(", ")}`);else console.log("\u2139\uFE0F No Launchpad installations found to remove")}catch(E){throw console.error("\u274C Error during complete uninstallation:",E),E}}async function p(E=W.argv.slice(2)){let q=v({args:E,options:{help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"},pin:{type:"boolean",short:"p"}},allowPositionals:!0}),K=q.positionals||[];if(q.values.help||K[0]==="help"){let z=U("pkgx",["glow","https://raw.githubusercontent.com/stacksjs/launchpad/main/README.md"],{stdio:"inherit"});W.exit(z.status??0)}else if(q.values.version){console.log("launchpad 0.0.0+dev");return}let J=K[0],M=K.slice(1);switch(J){case"install":case"i":{let z=w().string,O=await G(M,z);console.log(O.join(` `))}break;case"local-install":case"li":if(w().string!=="/usr/local")await G(M,$.home().join(".local").string);else console.error("deprecated: use `launchpad install` without `sudo` instead");break;case"stub":case"shim":await T(M,w().string);break;case"uninstall":case"rm":{let z=!0;for(let O of M)if(!await I(O))z=!1;W.exit(z?0:1)}break;case"list":case"ls":for await(let z of V())console.log(z);break;case"update":case"up":case"upgrade":await N(M);break;case"pin":console.error("\x1B[31mU EARLY! soz, not implemented\x1B[0m"),W.exit(1);break;case"outdated":await y();break;default:if(E.length===0)console.error("https://github.com/stacksjs/launchpad");else console.error("invalid usage");W.exit(2)}}async function T(E,q){await G(E,q),console.warn(`Shims created for packages: ${E.join(", ")}`)}async function N(E,q){if(E&&E.length>0)await h(E,q);else await b(q)}async function h(E,q){let{getLatestVersion:K,getPackageInfo:J}=await import("./chunk-83b6axd0.js"),{list:M}=await import("./chunk-wnwbsmkf.js"),z=w().string,O=await M(z);console.log(`\uD83D\uDD0D Checking for updates to ${E.join(", ")}...`);let Y=[];for(let j of E){let X=J(j);if(!X){console.warn(`\u26A0\uFE0F Package '${j}' not found in registry`);continue}let Q=O.find((B)=>B.project===X.domain||B.project===j);if(!Q){console.log(`\uD83D\uDCE6 ${j} is not installed - use 'launchpad install ${j}' instead`);continue}let x=K(j);if(!x){console.warn(`\u26A0\uFE0F Could not determine latest version for ${j}`);continue}let _=Q.version.toString();if(q?.latest||_!==x)Y.push({name:j,currentVersion:_,latestVersion:x});else console.log(`\u2705 ${j} is already up to date (${_})`)}if(Y.length===0){console.log("\uD83C\uDF89 All specified packages are up to date!");return}if(q?.dryRun){console.log(` \uD83D\uDD0D Packages that would be updated:`),Y.forEach((j)=>{console.log(` \u2022 ${j.name}: ${j.currentVersion} \u2192 ${j.latestVersion}`)});return}console.log(` \uD83D\uDE80 Updating ${Y.length} package(s)...`);let H=Y.map((j)=>q?.latest?j.name:`${j.name}@${j.latestVersion}`);if((await G(H,z)).length>0)console.log(` \uD83C\uDF89 Successfully updated ${Y.length} package(s):`),Y.forEach((j)=>{console.log(` \u2705 ${j.name}: ${j.currentVersion} \u2192 ${j.latestVersion}`)});else console.log("\u26A0\uFE0F No packages were updated")}async function b(E){let{getLatestVersion:q}=await import("./chunk-83b6axd0.js"),{list:K}=await import("./chunk-wnwbsmkf.js"),J=w().string,M=await K(J);if(M.length===0){console.log("\uD83D\uDCED No packages installed");return}console.log(`\uD83D\uDD0D Checking ${M.length} installed packages for updates...`);let z=[];for(let H of M){let Z=q(H.project);if(!Z){console.warn(`\u26A0\uFE0F Could not determine latest version for ${H.project}`);continue}let j=H.version.toString();if(E?.latest||j!==Z)z.push({name:H.project,currentVersion:j,latestVersion:Z})}if(z.length===0){console.log("\uD83C\uDF89 All packages are up to date!");return}if(E?.dryRun){console.log(` \uD83D\uDD0D ${z.length} package(s) would be updated:`),z.forEach((H)=>{console.log(` \u2022 ${H.name}: ${H.currentVersion} \u2192 ${H.latestVersion}`)});return}console.log(` \uD83D\uDE80 Updating ${z.length} package(s)...`);let O=z.map((H)=>E?.latest?H.name:`${H.name}@${H.latestVersion}`);if((await G(O,J)).length>0)console.log(` \uD83C\uDF89 Successfully updated ${z.length} package(s)`);else console.log("\u26A0\uFE0F No packages were updated")}export{N as update,T as shim,p as run}; export{I as p,d as q,p as r,T as s,N as t};