UNPKG

@prisma/dev

Version:

A local Prisma Postgres server for development and testing

2 lines (1 loc) 2.04 kB
import{createWriteStream as y,WriteStream as w}from"fs";import{access as A,chmod as D,constants as x,mkdir as P,readdir as E,readFile as T,writeFile as _}from"fs/promises";import{promisify as F}from"util";import{unzip as O}from"zlib";import o from"path";import f from"os";import c from"process";var n=f.homedir(),a=f.tmpdir(),{env:e}=c,m=t=>{let r=o.join(n,"Library");return{data:o.join(r,"Application Support",t),config:o.join(r,"Preferences",t),cache:o.join(r,"Caches",t),log:o.join(r,"Logs",t),temp:o.join(a,t)}},h=t=>{let r=e.APPDATA||o.join(n,"AppData","Roaming"),i=e.LOCALAPPDATA||o.join(n,"AppData","Local");return{data:o.join(i,t,"Data"),config:o.join(r,t,"Config"),cache:o.join(i,t,"Cache"),log:o.join(i,t,"Log"),temp:o.join(a,t)}},j=t=>{let r=o.basename(n);return{data:o.join(e.XDG_DATA_HOME||o.join(n,".local","share"),t),config:o.join(e.XDG_CONFIG_HOME||o.join(n,".config"),t),cache:o.join(e.XDG_CACHE_HOME||o.join(n,".cache"),t),log:o.join(e.XDG_STATE_HOME||o.join(n,".local","state"),t),temp:o.join(a,r,t)}};function p(t,{suffix:r="nodejs"}={}){if(typeof t!="string")throw new TypeError(`Expected a string, got ${typeof t}`);return r&&(t+=`-${r}`),c.platform==="darwin"?m(t):c.platform==="win32"?h(t):j(t)}var g=p("prisma-dev"),L=F(O);function W(t,r){return`${g.cache}/engine/${t}/${r}`}function X(t){return`${g.data}/${t}`}async function B(t){try{return await A(t,x.F_OK),!0}catch(r){if(u(r))return!1;throw r}}async function R(t,r){let i=await L(t);await _(r,i),await D(r,"755")}async function z(t,r){await t.stream().pipeTo(w.toWeb(y(r,{encoding:"utf-8"})))}function u(t){return t!=null&&typeof t=="object"&&"code"in t&&t.code==="ENOENT"}async function I(t){try{return await T(t,{encoding:"utf-8"})}catch(r){if(u(r))return null;throw r}}async function J(t){await P(t,{recursive:!0})}async function K(t){try{return(await E(t,{withFileTypes:!0})).reduce((i,s)=>(s.isDirectory()&&!s.name.startsWith(".")&&i.push(s.name),i),[])}catch(r){if(u(r))return[];throw r}}export{W as a,X as b,B as c,R as d,z as e,I as f,J as g,K as h};