UNPKG

clixion

Version:

A flexible framework for building CLI applications

2 lines (1 loc) 2.13 kB
import o from"node:fs";import g from"node:os";import d,{join as p,resolve as i,relative as a}from"node:path";import{fileURLToPath as c}from"node:url";import x from"which-pm-runs";var k=P(),u=d.dirname(k);function P(){let r=new Error().stack?.match(/^Error\s+at[^\r\n]+\s+at *(?:[^\r\n(]+\((.+?)(?::\d+:\d+)?\)|(.+?)(?::\d+:\d+)?) *([\r\n]|$)/),n=r?.[1]||r?.[2];return n?.startsWith("file://")?c(n):n||c(import.meta.url)}function F(){return!!(process.env.CI||process.env.GITHUB_ACTIONS)}function I(){return!1}function l(t){return t.startsWith(process.env.HOME??"~/")}function O(t){return l(t)?i(g.homedir(),t):i(process.cwd(),t)}function M(t){return l(t)?a(g.homedir(),t):a(process.cwd(),t)}function T(t){return o.existsSync(t)&&o.readdirSync(t).length>0}var j=async t=>{let e=await o.promises.readdir(t);return await Promise.all(e.map(r=>o.promises.rm(p(t,r),{recursive:!0})))};function f(t){if(!o.existsSync(t))throw new Error(`File ${t} not found`);return o.readFileSync(t,{encoding:"utf8"}).toString()}function m(t,e){return o.writeFileSync(t,e,{encoding:"utf8"})}function h(t,e,r){let n=f(t);n=n.replace(e,r),m(t,n)}function v(){return x()?.name||"npm"}function w(){let t=v();return t==="npm"||t==="bun"?`${t} run`:t}function s(t=u){return p(t,"package.json")}function N(t,e,r){h(s(t),e,r)}function A(t){N(t,/npm run/g,w())}var y=/^(?:(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*)$/;function C(t){return t=t.trim().replace(/\\/g,"/").split("/").filter(Boolean).map(e=>e.toLowerCase().replace(/[^a-z0-9-_]/g,"-").replace(/^-+|-+$/g,"")).join("-"),t=t.normalize("NFD").replace(/[\u0300-\u036f]/g,""),t=t.replace(/[^a-zA-Z0-9\-._~/@]/g,"-"),t=t.replace(/^[-.]+|[-.]+$/g,""),t=t.replace(/[-.]{2,}/g,"-"),t=t.toLowerCase(),t}function E(t){return y.test(t)}function R(t){if(t=C(t),!E(t))throw new Error(`Invalid package name: ${t}`);return t}function _(t){let e=s(t);return JSON.parse(f(e))}function J(t,e){m(s(t),JSON.stringify(e,null,2))}function B(t,e=u){let r=R(t),n=_(e);n.name=r,J(e,n)}export{k as a,u as b,P as c,F as d,I as e,l as f,O as g,M as h,T as i,j,v as k,w as l,s as m,A as n,C as o,_ as p,J as q,B as r};