{"version":3,"file":"generate-subgraph-Dm27O59o.mjs","sources":["../src/services/generate-subgraph.ts"],"sourcesContent":["import {\n  detectFeatures,\n  generateAllSubgraphs,\n  generateSubgraph,\n  syncFeatureDependencies,\n} from \"@powerhousedao/codegen\";\nimport {\n  buildTsMorphProject,\n  getSubgraphMetadata,\n} from \"@powerhousedao/codegen/utils\";\nimport {\n  extractSubgraphDocuments,\n  generateSubgraphFromDocument,\n  getDocument,\n  saveSpec,\n} from \"@powerhousedao/vetra/codegen\";\nimport type { SubgraphModuleDocument } from \"@powerhousedao/vetra/document-models/subgraph-module\";\nimport { dirname } from \"node:path\";\nimport type { GenerateSubgraphArgs } from \"../types.js\";\nimport { installAddedDependencies } from \"../utils/install-added-dependencies.js\";\n\nexport async function startGenerateSubgraph(\n  args: GenerateSubgraphArgs,\n  projectDir: string,\n) {\n  const { name, document, dir, all, extract, debug } = args;\n  if (debug) {\n    console.log({ args });\n  }\n  const project = buildTsMorphProject(projectDir);\n  if (extract) {\n    const docs = extractSubgraphDocuments(project);\n    for (const doc of docs) {\n      const path = await saveSpec(doc, projectDir);\n      console.log(`Wrote ${path}`);\n    }\n    return;\n  }\n  if (all) {\n    await generateAllSubgraphs(project);\n  } else if (document) {\n    const doc = (await getDocument(document)) as SubgraphModuleDocument;\n    await generateSubgraphFromDocument(doc, project);\n  } else if (name) {\n    await generateSubgraph(name, project);\n  } else if (dir) {\n    const { subgraphName } = getSubgraphMetadata(project, dirname(dir));\n    if (!subgraphName) {\n      throw new Error(`Failed to get data for subgraph in dir \"${dir}\"`);\n    }\n    await generateSubgraph(subgraphName, project);\n  } else {\n    console.log(\n      \"Please specify one of `name`, `document`, `dir`, `all`, or `extract`.\",\n    );\n    return;\n  }\n  await project.save();\n  const added = await syncFeatureDependencies(\n    detectFeatures(projectDir),\n    projectDir,\n  );\n  await installAddedDependencies(added, projectDir, args.skipInstall);\n}\n"],"names":[],"mappings":";;;;;;;;AAqBA,eAAsB,sBACpB,MACA,YACA;CACA,MAAM,EAAE,MAAM,UAAU,KAAK,KAAK,SAAS,UAAU;CACrD,IAAI,OACF,QAAQ,IAAI,EAAE,KAAK,CAAC;CAEtB,MAAM,UAAU,oBAAoB,UAAU;CAC9C,IAAI,SAAS;EACX,MAAM,OAAO,yBAAyB,OAAO;EAC7C,KAAK,MAAM,OAAO,MAAM;GACtB,MAAM,OAAO,MAAM,SAAS,KAAK,UAAU;GAC3C,QAAQ,IAAI,SAAS,MAAM;EAC7B;EACA;CACF;CACA,IAAI,KACF,MAAM,qBAAqB,OAAO;MAC7B,IAAI,UAAU;EACnB,MAAM,MAAO,MAAM,YAAY,QAAQ;EACvC,MAAM,6BAA6B,KAAK,OAAO;CACjD,OAAO,IAAI,MACT,MAAM,iBAAiB,MAAM,OAAO;MAC/B,IAAI,KAAK;EACd,MAAM,EAAE,iBAAiB,oBAAoB,SAAS,QAAQ,GAAG,CAAC;EAClE,IAAI,CAAC,cACH,MAAM,IAAI,MAAM,2CAA2C,IAAI,EAAE;EAEnE,MAAM,iBAAiB,cAAc,OAAO;CAC9C,OAAO;EACL,QAAQ,IACN,uEACF;EACA;CACF;CACA,MAAM,QAAQ,KAAK;CACnB,MAAM,QAAQ,MAAM,wBAClB,eAAe,UAAU,GACzB,UACF;CACA,MAAM,yBAAyB,OAAO,YAAY,KAAK,WAAW;AACpE","debug_id":"e6f7e480-790a-5892-8662-eb9ba2632ed4"}