{"version":3,"file":"generate-document-model-DhDQ_06X.mjs","sources":["../src/services/generate-document-model.ts"],"sourcesContent":["import {\n  generateAllDocumentModels,\n  generateDocumentModel,\n  loadDocumentModel,\n} from \"@powerhousedao/codegen\";\nimport { buildTsMorphProject } from \"@powerhousedao/codegen/utils\";\nimport {\n  extractDocumentModelDocuments,\n  generateDocumentModelFromDocument,\n  getDocument,\n  saveSpec,\n} from \"@powerhousedao/vetra/codegen\";\nimport type { DocumentModelDocument } from \"@powerhousedao/shared/document-model\";\nimport { dirname, join } from \"node:path\";\nimport type { GenerateDocumentModelArgs } from \"../types.js\";\n\nexport async function startGenerateDocumentModel(\n  args: GenerateDocumentModelArgs,\n  projectDir: string,\n) {\n  const { 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 = extractDocumentModelDocuments(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 generateAllDocumentModels(project);\n  } else if (document) {\n    if (document.endsWith(\".phd\")) {\n      const doc = (await getDocument(document)) as DocumentModelDocument;\n      await generateDocumentModelFromDocument(doc, project);\n    } else {\n      const state = await loadDocumentModel(document);\n      await generateDocumentModel(state, project);\n    }\n  } else if (dir) {\n    const documentModelDirName = dirname(dir);\n    const documentModelFileName = `${documentModelDirName}.json`;\n    const documentModelFilePath = join(dir, documentModelFileName);\n    const state = await loadDocumentModel(documentModelFilePath);\n    await generateDocumentModel(state, project);\n  } else {\n    console.log(\n      \"Please specify one of `document`, `dir`, `all`, or `extract`.\",\n    );\n    return;\n  }\n  await project.save();\n}\n"],"names":[],"mappings":";;;;;;;AAgBA,eAAsB,2BACpB,MACA,YACA;CACA,MAAM,EAAE,UAAU,KAAK,KAAK,SAAS,UAAU;CAC/C,IAAI,OACF,QAAQ,IAAI,EAAE,KAAK,CAAC;CAEtB,MAAM,UAAU,oBAAoB,UAAU;CAC9C,IAAI,SAAS;EACX,MAAM,OAAO,8BAA8B,OAAO;EAClD,KAAK,MAAM,OAAO,MAAM;GACtB,MAAM,OAAO,MAAM,SAAS,KAAK,UAAU;GAC3C,QAAQ,IAAI,SAAS,MAAM;EAC7B;EACA;CACF;CACA,IAAI,KACF,MAAM,0BAA0B,OAAO;MAClC,IAAI,UAAU;EACnB,IAAI,SAAS,SAAS,MAAM,GAAG;GAC7B,MAAM,MAAO,MAAM,YAAY,QAAQ;GACvC,MAAM,kCAAkC,KAAK,OAAO;EACtD,OAAO;GACL,MAAM,QAAQ,MAAM,kBAAkB,QAAQ;GAC9C,MAAM,sBAAsB,OAAO,OAAO;EAC5C;CACF,OAAO,IAAI,KAAK;EAEd,MAAM,wBAAwB,GADD,QAAQ,GACe,EAAE;EACtD,MAAM,wBAAwB,KAAK,KAAK,qBAAqB;EAC7D,MAAM,QAAQ,MAAM,kBAAkB,qBAAqB;EAC3D,MAAM,sBAAsB,OAAO,OAAO;CAC5C,OAAO;EACL,QAAQ,IACN,+DACF;EACA;CACF;CACA,MAAM,QAAQ,KAAK;AACrB","debug_id":"52f5688d-6e33-5a44-a55b-802d5da44b75"}