constatic
Version:
Constatic is a CLI for creating and managing modern TypeScript projects, providing an organized structure and features that streamline development.
2 lines (1 loc) • 738 B
JavaScript
import{Result as r}from"#lib/result.js";import{execSync as o,spawn as u}from"node:child_process";class g{get agent(){const e=(process.env.npm_config_user_agent??"").toLowerCase();for(const t of["npm","bun","yarn","pnpm"])if(e.startsWith(t))return t;return"npm"}get isBun(){return this.agent==="bun"}run(e,...t){return new Promise(s=>{const i=u(this.agent,t,{cwd:e,env:{...process.env,NODE_ENV:"development",DISABLE_OPENCOLLECTIVE:"1"}});i.on("exit",n=>s(n===0?r.ok(n,"code"):r.fail("fail",n??void 0))),i.on("error",n=>s(r.fail(n.message,1)))})}isRepoDirty(e){try{return o("git status --porcelain",{encoding:"utf-8",cwd:e,stdio:"pipe"}).trim()!==""}catch(t){return!t?.toString?.().includes("not a git repository")}}}export{g as CLIShell};