/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@evoleo/create-warp-app@1.2.6/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
#!/usr/bin/env node
const inquirer=require("inquirer"),shell=require("shelljs"),chalk=require("chalk"),https=require("follow-redirects").https,fs=require("fs"),unzipper=require("unzipper"),path=require("path");shell.config.silent=!0;const projectNameQuestion=[{type:"input",name:"projectName",message:"What's your project name?",default:"Empty"}],questions=[{type:"list",name:"serverTemplate",message:"Select server-side template:",choices:["JavaScript","TypeScript"]},{type:"list",name:"clientTemplate",message:"Select client-side template:",choices:["GameMaker","JavaScript (experimental)"]}];inquirer.prompt(projectNameQuestion).then((({projectName:e})=>{fs.existsSync(e)?fs.readdirSync(e).length>0&&(console.log(chalk.red(`Directory "${e}/" already exists and is not empty!`)),process.exit(1)):fs.mkdirSync(e),inquirer.prompt(questions).then((t=>{const{serverTemplate:r,clientTemplate:n}=t,i=shell.exec("curl -s https://api.github.com/repos/evolutionleo/Warp/releases/latest"),a=JSON.parse(i).assets.map((e=>e.browser_download_url));let l;switch(r){case"JavaScript":l="JSServer.zip";break;case"TypeScript":l="TSServer.zip";break;default:throw new Error("Unknown Server Template: "+r)}const s=a.find((e=>e.endsWith(l)));let o;switch(s||(console.log(chalk.red(`Failed to find the chosen client template in the latest release (${l})`)),process.exit(1)),n){case"GameMaker":o="GMClient.zip";break;case"JavaScript (experimental)":o="WebClient.zip";break;default:throw new Error("Unknown Client Template: "+r)}const c=a.find((e=>e.endsWith(o)));c||(console.log(chalk.red(`Failed to find the chosen client template in the latest release (${o})`)),process.exit(1));const p=()=>{console.log(chalk.white("Unzipping "+l+"...")),unzipper.Open.file(path.join(e,l)).then((t=>t.extract({path:path.join(__dirname,e,"Server/")}))).then((()=>{console.log(chalk.white("Done.")),fs.rmSync(path.join(e,l))}))},h=fs.createWriteStream(path.join(e,l)),m=https.get(s);console.log(chalk.white("Downloading the server from"),chalk.blueBright(s)+chalk.white("...")),m.on("response",(e=>{e.pipe(h),e.on("close",p)}));const u=()=>{console.log(chalk.white("Unzipping "+o+"...")),unzipper.Open.file(path.join(e,o)).then((t=>t.extract({path:path.join(__dirname,e,"Client/")}))).then((()=>{if("GameMaker"===n){const t="Client.yyp",r=path.join(e,"Client/",t),n=fs.readFileSync(r,"utf8"),i=r.replace(t,e+".yyp");fs.renameSync(r,i),fs.writeFileSync(i,n.replace("Client",e));const a="Client.resource_order",l=path.join(e,"Client/",a),s=fs.readFileSync(l,"utf8"),o=l.replace(t,e+".resource_order");fs.renameSync(l,o),fs.writeFileSync(o,s.replace("Client",e))}console.log(chalk.white("Done.")),fs.rmSync(path.join(e,o))}))},d=fs.createWriteStream(path.join(e,o)),f=https.get(c);console.log(chalk.white("Downloading the client from"),chalk.blueBright(c)+chalk.white("...")),f.on("response",(e=>{e.pipe(d),e.on("close",u)}))}))}));
//# sourceMappingURL=/sm/38ea4dcf5dd87bac06eae9e053bc5b1f6c5a4e3839446b4b9e015be0be429357.map