import path from "node:path"
import fs from "node:fs"

import { buildPacks, SYSTEM_PACK_DEFINITIONS } from "./pack-builder.mjs"

const rootDir = path.resolve(import.meta.dirname, "..")
const packageJson = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"))
const systemJson = JSON.parse(fs.readFileSync(path.join(rootDir, "system.json"), "utf8"))

await buildPacks({
  sourceRoot: path.join(rootDir, "packs-src"),
  outputRoot: path.join(rootDir, "packs"),
  packDefinitions: SYSTEM_PACK_DEFINITIONS,
  documentSystemId: systemJson.id,
  documentSystemVersion: packageJson.version,
  coreVersion: String(systemJson.compatibility?.verified ?? systemJson.compatibility?.minimum ?? ""),
})
