create-abi
Version:
Interactive CLI for create Abi.js projects.
5 lines (4 loc) • 3.22 kB
JavaScript
import s,{readdirSync as k,statSync as S}from"fs";import y from"os";import v,{basename as w,join as a,relative as f,resolve as u}from"path";import{fileURLToPath as l}from"url";import{copySync as C,ensureDirSync as N,pathExistsSync as E}from"fs-extra/esm";import J from"panam/pm";var P=W(),d=v.dirname(P);function A(n,t){S(n).isDirectory()?b(n,t):D(n,t)}function b(n,t){let r=k(n);N(t);for(let e of r)A(a(n,e),a(t,e))}function D(n,t){let r=w(n);E(t)?r.endsWith(".json")?R(t,n,!0):r.startsWith(".")&&r.endsWith("ignore")&&j(t,n,!0):C(n,t)}function R(n,t,r=!1){let e=_(i(n),i(t));return r&&h(n,e),e}function _(n,t){return x(JSON.parse(n),JSON.parse(t))}function x(n,t){for(let r of Object.keys(t)){let e=n[r],o=t[r];m(e)&&m(o)?n[r]=x(e,o):Array.isArray(e)&&Array.isArray(o)?n[r]=Array.from(new Set([...e,...o])):n[r]=o}return n}function m(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}function j(n,t,r=!1){let e=O(i(n),i(t));return r&&c(n,e),e}function O(n,t){return z(n.split(`
`),t.split(`
`)).join(`
`)}function z(n,t){let r=Array.from(new Set([...n.map(e=>e.trim()),...t.map(e=>e.trim())])).filter(e=>e!=="");return I(r)}function I(n){let t=[],r=!1;return n.forEach((e,o)=>{let g=e.startsWith("#");g&&!r&&o!==0&&t.push(""),t.push(e),r=g}),t}function W(){let r=new Error().stack?.match(/^Error\s+at[^\r\n]+\s+at *(?:[^\r\n(]+\((.+?)(?::\d+:\d+)?\)|(.+?)(?::\d+:\d+)?) *([\r\n]|$)/),e=r?.[1]||r?.[2];return e?.startsWith("file://")?l(e):e||l(import.meta.url)}function Y(){return!!(process.env.CI||process.env.GITHUB_ACTIONS)}function nn(){return!1}function T(n){return n.startsWith(process.env.HOME??"~/")}function tn(n){return T(n)?u(y.homedir(),n):u(process.cwd(),n)}function rn(n){return T(n)?f(y.homedir(),n):f(process.cwd(),n)}function en(n){return s.existsSync(n)&&s.readdirSync(n).length>0}var on=async n=>{let t=await s.promises.readdir(n);return await Promise.all(t.map(r=>s.promises.rm(a(n,r),{recursive:!0})))};function i(n){if(!s.existsSync(n))throw new Error(`File ${n} not found`);return s.readFileSync(n,{encoding:"utf8"}).toString()}function c(n,t){return s.writeFileSync(n,t,{encoding:"utf8"})}function $(n,t,r){let e=i(n);e=e.replace(t,r),c(n,e)}function p(n,t=d){return a(t,`${n}.json`)}function L(n,t,r,e){$(p(n,t),r,e)}function sn(n,t){L(n,t,/npm run/g,J.runCommand())}var M=/^(?:(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*)$/;function V(n){return n=n.trim().replace(/\\/g,"/").split("/").filter(Boolean).map(t=>t.toLowerCase().replace(/[^a-z0-9-_]/g,"-").replace(/^-+|-+$/g,"")).join("-"),n=n.normalize("NFD").replace(/[\u0300-\u036f]/g,""),n=n.replace(/[^a-zA-Z0-9\-._~/@]/g,"-"),n=n.replace(/^[-.]+|[-.]+$/g,""),n=n.replace(/[-.]{2,}/g,"-"),n=n.toLowerCase(),n}function B(n){return M.test(n)}function H(n){if(n=V(n),!B(n))throw new Error(`Invalid package name: ${n}`);return n}function F(n,t){let r=p(n,t);return JSON.parse(i(r))}function G(n,t,r){h(p(n,t),r)}function h(n,t){c(n,JSON.stringify(t,null,2))}function an(n,t="package",r=d){let e=H(n),o=F(t,r);o.name=e,G(t,r,o)}export{P as a,d as b,A as c,b as d,D as e,R as f,_ as g,x as h,j as i,O as j,z as k,W as l,Y as m,nn as n,T as o,tn as p,rn as q,en as r,on as s,p as t,sn as u,V as v,F as w,G as x,h as y,an as z};