// @bun
var{defineProperty:W,getOwnPropertyNames:$,getOwnPropertyDescriptor:A}=Object,H=Object.prototype.hasOwnProperty;function I(w){return this[w]}var k=(w)=>{var q=(X??=new WeakMap).get(w),z;if(q)return q;if(q=W({},"__esModule",{value:!0}),w&&typeof w==="object"||typeof w==="function"){for(var B of $(w))if(!H.call(q,B))W(q,B,{get:I.bind(w,B),enumerable:!(z=A(w,B))||z.enumerable})}return X.set(w,q),q},X;var O=(w)=>w;function R(w,q){this[w]=O.bind(null,q)}var v=(w,q)=>{for(var z in q)W(w,z,{get:q[z],enumerable:!0,configurable:!0,set:R.bind(q,z)})};var b=(w,q)=>()=>(w&&(q=w(w=0)),q);var x=import.meta.require;import Q from"fs";import L from"path";function F(w){let q=[];if(q.push("[build]"),q.push(`  command = "${E(w.build.command)}"`),q.push(`  publish = "${E(w.build.publish)}"`),w.build.functions)q.push(`  functions = "${E(w.build.functions)}"`);if(w.build.edge_functions)q.push(`  edge_functions = "${E(w.build.edge_functions)}"`);if(w.build.environment&&Object.keys(w.build.environment).length>0){q.push(""),q.push("[build.environment]");for(let[z,B]of Object.entries(w.build.environment))q.push(`  ${z} = "${E(B)}"`)}if(w.functions){if(q.push(""),q.push("[functions]"),w.functions.directory)q.push(`  directory = "${E(w.functions.directory)}"`);if(w.functions.node_bundler)q.push(`  node_bundler = "${w.functions.node_bundler}"`);if(w.functions.external_node_modules&&w.functions.external_node_modules.length>0)q.push(`  external_node_modules = [${w.functions.external_node_modules.map((z)=>`"${z}"`).join(", ")}]`)}if(w.edge_functions&&w.edge_functions.length>0){q.push("");for(let z of w.edge_functions)q.push("[[edge_functions]]"),q.push(`  function = "${E(z.function)}"`),q.push(`  path = "${E(z.path)}"`)}if(w.redirects&&w.redirects.length>0){q.push("");for(let z of w.redirects){if(q.push("[[redirects]]"),q.push(`  from = "${E(z.from)}"`),q.push(`  to = "${E(z.to)}"`),z.status!==void 0)q.push(`  status = ${z.status}`);if(z.force!==void 0)q.push(`  force = ${z.force}`);if(z.conditions&&Object.keys(z.conditions).length>0){q.push("  [redirects.conditions]");for(let[B,G]of Object.entries(z.conditions))q.push(`    ${B} = "${E(G)}"`)}}}if(w.headers&&w.headers.length>0){q.push("");for(let z of w.headers){q.push("[[headers]]"),q.push(`  for = "${E(z.for)}"`),q.push("  [headers.values]");for(let[B,G]of Object.entries(z.values))q.push(`    ${B} = "${E(G)}"`)}}if(w.plugins&&w.plugins.length>0){q.push("");for(let z of w.plugins)if(q.push("[[plugins]]"),q.push(`  package = "${E(z.package)}"`),z.inputs&&Object.keys(z.inputs).length>0){q.push("  [plugins.inputs]");for(let[B,G]of Object.entries(z.inputs))if(typeof G==="string")q.push(`    ${B} = "${E(G)}"`);else if(typeof G==="boolean"||typeof G==="number")q.push(`    ${B} = ${G}`)}}if(w.context&&Object.keys(w.context).length>0)for(let[z,B]of Object.entries(w.context)){if(q.push(""),q.push(`[context.${z}]`),B.command)q.push(`  command = "${E(B.command)}"`);if(B.publish)q.push(`  publish = "${E(B.publish)}"`);if(B.environment&&Object.keys(B.environment).length>0){q.push(`  [context.${z}.environment]`);for(let[G,U]of Object.entries(B.environment))q.push(`    ${G} = "${E(U)}"`)}}return q.join(`
`)+`
`}function E(w){return w.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}async function D(w){let q={framework:"stx",buildCommand:"bun run build",outputDir:"dist"},z=L.join(w,"package.json");if(await Bun.file(z).exists())try{let K=JSON.parse(await Bun.file(z).text());if(K.scripts?.build)q.buildCommand="bun run build";let M={...K.dependencies,...K.devDependencies};if(M["@stacksjs/stx"]||M.stx)q.framework="stx"}catch{}let B=L.join(w,"stx.config.ts"),G=L.join(w,".config","stx.config.ts");if(await Bun.file(B).exists()||await Bun.file(G).exists())q.framework="stx";let U=["dist","build","out","public",".output"];for(let K of U){let M=L.join(w,K);if(Q.existsSync(M)&&Q.statSync(M).isDirectory()){q.outputDir=K;break}}let Y=["functions","netlify/functions","api"];for(let K of Y){let M=L.join(w,K);if(Q.existsSync(M)&&Q.statSync(M).isDirectory()){q.functionsDir=K;break}}let Z=L.join(w,"netlify","edge-functions");if(Q.existsSync(Z))q.edgeFunctionsDir="netlify/edge-functions";let V=L.join(w,q.outputDir||"dist");if(Q.existsSync(V)){let K=Q.existsSync(L.join(V,"index.html")),M=Q.readdirSync(V).filter((_)=>_.endsWith(".html"));q.isSPA=K&&M.length===1}return q}function N(w={}){let q={build:{command:w.buildCommand||"bun run build",publish:w.outputDir||"dist"}};if(w.functionsDir)q.build.functions=w.functionsDir,q.functions={directory:w.functionsDir,node_bundler:"esbuild"};if(w.edgeFunctionsDir)q.build.edge_functions=w.edgeFunctionsDir;if(q.headers=[{for:"/*",values:{"X-Frame-Options":"DENY","X-Content-Type-Options":"nosniff","X-XSS-Protection":"1; mode=block","Referrer-Policy":"strict-origin-when-cross-origin"}},{for:"/assets/*",values:{"Cache-Control":"public, max-age=31536000, immutable"}}],w.isSPA!==!1)q.redirects=[{from:"/*",to:"/index.html",status:200}];return q.context={production:{environment:{NODE_ENV:"production"}},"deploy-preview":{environment:{NODE_ENV:"development"}}},q}async function T(w,q){let z=await D(w),B=q||N(z),G=F(B),U=L.join(w,"netlify.toml");return await Bun.write(U,G),U}function u(w){return Q.existsSync(L.join(w,"netlify.toml"))}async function m(w){let q=L.join(w,"netlify.toml");if(!await Bun.file(q).exists())return null;return Bun.file(q).text()}var J=()=>{};J();export{T as writeNetlifyConfig,m as readNetlifyConfig,u as hasNetlifyConfig,F as generateNetlifyToml,D as detectProjectConfig,N as createDefaultNetlifyConfig};
