#! /usr/bin/env node
import e from"path";import n from"fs";import{fileURLToPath as f}from"url";import{spawnSync as d}from"child_process";const j=f(import.meta.url),y=e.dirname(j),r=process.argv[2]||"my-app",S=process.cwd(),o=e.join(S,r);n.existsSync(o)&&(console.error(`Directory ${o} already exists`),process.exit(1));const c=e.join(y,"../template");n.mkdirSync(o),n.readdirSync(c).forEach(a=>{const i=e.join(c,a),t=e.basename(i);if(t!=="package.json"&&t!=="package-lock.json")n.cpSync(i,e.join(o,t),{recursive:!0});else{const l=n.readFileSync(i,"utf8"),s=JSON.parse(l);s.name=r,t==="package-lock.json"&&(s.packages[""].name=r);const m=JSON.stringify(s,null,2),p=e.join(o,t);n.writeFileSync(p,m)}}),d("npm",["install"],{cwd:o,shell:!0,stdio:"inherit"});
