var M=Object.defineProperty;var j=(o,s)=>M(o,"name",{value:s,configurable:!0});import{createRequire as N}from"node:module";import{l as b,M as d,z as P}from"../packem_shared/readFileSync-DseCu8sg-DEq4Fn3a.js";import{H as v,E as w,j as K}from"./config.js";import{p as e}from"./bin.js";import{A as q}from"../packem_shared/pm-runner-DmKT2FqF.js";import{O as G}from"../packem_shared/build-scripts-DE6U8jVq.js";import{N as E}from"../packem_shared/native-config-sync-DBkJ-hsF.js";import{E as A}from"../packem_shared/min-release-age-DKMW2N_v.js";const B=N(import.meta.url),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,C=j(o=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[s,t]=h.versions.node.split(".").map(Number);if(s>22||s===22&&t>=3||s===20&&t>=16)return h.getBuiltinModule(o)}return B(o)},"__cjs_getBuiltinModule"),{execFileSync:I}=C("node:child_process"),{createInterface:F}=C("node:readline");var L=Object.defineProperty,u=j((o,s)=>L(o,"name",{value:s,configurable:!0}),"f");const Y=u(o=>{const s=[];return b(d(o,"turbo.json"))&&s.push("turborepo"),b(d(o,"nx.json"))&&s.push("nx"),b(d(o,".moon"))&&s.push("moon"),s},"detectExistingTools"),T=u((o,s)=>new Promise(t=>{o.question(s,i=>{t(i.trim())})}),"ask"),m=u(async(o,s,t=!0)=>{const i=await T(o,`${s} ${t?"[Y/n]":"[y/N]"} `);return i===""?t:i.toLowerCase()==="y"||i.toLowerCase()==="yes"},"confirm"),k=u((o,s)=>{const t=[],i=Object.entries(s.allowBuilds).filter(([,l])=>l).map(([l])=>`                    "${l}": true,`).join(`
`),a=[`            installScripts: {
                allow: ${i?`{
${i}
                }`:"{}"},
            },`];s.minimumReleaseAge!==void 0&&a.push(`            firstSeen: {
                minutes: ${String(s.minimumReleaseAge)},
            },`);let n=`        policies: {
${a.join(`
`)}
        },`;return s.enableSocket&&(n+=`
        socket: { enabled: true },`),s.enableDepsDev&&(n+=`
        depsDev: { enabled: true },`),t.push(`    security: {
${n}
    },`),s.staged&&t.push(`    staged: {
        "*": ["vis lint --staged --fix", "vis fmt --staged"],
    },`),`import { defineConfig } from "@visulima/vis/config";

export default defineConfig({
${t.join(`

`)}
});
`},"generateConfigContent"),z=u(async(o,s,t)=>{const i=F({input:process.stdin,output:process.stdout});e.info(`
  vis init — interactive setup
`);const a=await m(i,"  Enable Socket.dev security scanning?");a&&(e.success("    Socket.dev enabled — scores, alerts, and supply chain data active."),process.env.VIS_SOCKET_TOKEN||e.notice("    Set VIS_SOCKET_TOKEN for a custom API token (optional).")),e.info("");const n=await m(i,"  Enable Google deps.dev (OpenSSF Scorecard + GHSA advisories)?");n&&e.success("    deps.dev enabled — Scorecard signals and advisories merged into the security report."),e.info("");const l=await m(i,"  Scan for packages with build scripts?"),g={};if(l){e.info("    Scanning node_modules...");const c=G(o,{});if(c.length>0){e.info(`    Found ${String(c.length)} package${c.length===1?"":"s"} with build scripts:
`);for(const r of c){const f=await m(i,`    Allow ${r}?`,!1),x=r.split(" (")[0]??r;g[x]=f,f&&e.success(`      ✓ ${x} approved`)}}else e.info("    No packages with build scripts found.")}e.info("");const O=await m(i,"  Enforce a minimum release age (block freshly-published versions)?");let p;if(O){const c=await T(i,`    Minimum age in minutes (default ${String(v)} = 2 days): `),r=c===""?v:Number.parseInt(c,10);p=Number.isFinite(r)&&r>0?r:v,e.success(`    minimumReleaseAge: ${String(p)} minutes`)}e.info("");const S=await m(i,"  Set up pre-commit hooks (lint-staged)?",!1);let y=!1;(s.name==="pnpm"||s.name==="yarn"||s.name==="npm"||s.name==="bun")&&(e.info(""),y=await m(i,`  Sync security settings to ${s.name} config?`));const $=Y(o);if($.length>0&&(e.info(""),e.info(`  Detected existing tools: ${$.join(", ")}`),await m(i,`  Run \`vis migrate\` for ${$.join(", ")}?`,!1))){i.close();const[c,...r]=s.name==="pnpm"?["pnpm","exec"]:s.name==="yarn"?["yarn","exec"]:s.name==="bun"?["bunx"]:["npx"];for(const f of $){e.info(`    Migrating from ${f}...`);try{I(c,[...r,"vis","migrate",f],{cwd:o,stdio:"inherit"})}catch{e.warn(`    Migration from ${f} had issues — run \`vis migrate ${f}\` manually.`)}}if(b(t))e.success(`Migrated config written to ${t}`);else{const f=k(s.name,{allowBuilds:g,enableDepsDev:n,enableSocket:a,minimumReleaseAge:p,staged:S});w(t,f),e.success(`Created ${t}`)}e.notice("  Run 'vis doctor' to see your project's full health status.");return}i.close(),e.info("");const D=k(s.name,{allowBuilds:g,enableDepsDev:n,enableSocket:a,minimumReleaseAge:p,staged:S});if(w(t,D),e.success(`Created ${t}`),y){const c=Object.fromEntries(Object.entries(g).filter(([,r])=>r));for(const r of E(s.name,o,c))e.success(`  ${r}`);for(const r of A(s.name,o,p))e.success(`  ${r}`)}e.info(""),e.info("  Setup complete. Your config:");const _=[a&&"Socket.dev",n&&"deps.dev"].filter(Boolean);e.info(`    Security:      ${_.length>0?`${_.join(" + ")} enabled`:"defaults only"}`),e.info(`    Build scripts: ${Object.values(g).filter(Boolean).length} approved`),e.info(`    Min age:       ${p===void 0?"not enforced":`${String(p)} minutes`}`),e.info(`    Git hooks:     ${S?"lint-staged configured":"not configured"}`),e.info(`    PM sync:       ${y?"done":"skipped"}`),e.info(""),e.notice("  Run 'vis doctor' to see your project's full health status."),e.info("")},"runInteractiveInit"),H=u((o,s,t,i)=>{const a=k(s.name,{allowBuilds:{},enableDepsDev:!1,enableSocket:!1,minimumReleaseAge:v,staged:!1});if(w(i,a),e.success(`Created ${i}`),e.info("  Secure defaults are applied automatically by defineConfig()."),t.syncNative){for(const n of E(s.name,o,{}))e.success(`  ${n}`);for(const n of A(s.name,o,v))e.success(`  ${n}`)}e.info(""),e.notice("Run 'vis doctor' for a full health check, or 'vis init' in a terminal for guided setup.")},"runStaticInit"),R=u((o,s,t)=>{const i=d(o,".."),a=d(s,"node_modules","@visulima","vis","schemas",t),n=P(i,a),l=n===""?`./${t}`:n.split(/[/\\]/u).join("/");return l.startsWith(".")?l:`./${l}`},"buildSchemaRef"),V=u((o,s)=>{const t=R(d(o,"project.json"),s,"project.schema.json"),i=R(d(o,"vis.config.ts"),s,"vis-config.schema.json");e.info(""),e.info("Paste these into your config files to get editor IntelliSense:"),e.info(""),e.info(`  project.json    → "$schema": "${t}"`),e.info(`  vis.config.ts   → see ${i} (vis.config.ts is TypeScript; use the import path directly)`),e.info(""),e.notice("For nested project.json files, the `..` depth changes — run `vis migrate nx` to auto-rewrite all of them.")},"printSchemaPaths"),te=u(async({options:o,workspaceRoot:s})=>{const t=s??process.cwd();if(o.schema){V(t,t);return}const i=q(t),a=K(t);if(a&&!o.force){e.warn(`Config already exists: ${a}`),e.notice("Use --force to overwrite, or edit the existing file.");return}const n=a??d(t,"vis.config.ts");process.stdin.isTTY&&o.interactive!==!1?await z(t,i,n):H(t,i,o,n)},"execute");export{R as buildSchemaRefForTesting,te as default};
