{"version":3,"file":"validate-growi-plugin-directive.cjs","sources":["../../../../../src/v4/server/utils/common/validate-growi-plugin-directive.ts"],"sourcesContent":["import type { GrowiPluginType } from '@growi/core';\n\nimport {\n  type GrowiPluginValidationData,\n  GrowiPluginValidationError,\n} from '../../../../model/index.js';\nimport { importPackageJson } from './import-package-json.js';\n\nexport const validateGrowiDirective = (\n  projectDirRoot: string,\n  expectedPluginType?: GrowiPluginType,\n): GrowiPluginValidationData => {\n  const pkg = importPackageJson(projectDirRoot);\n\n  const { growiPlugin } = pkg;\n\n  const data: GrowiPluginValidationData = {\n    projectDirRoot,\n    schemaVersion: Number.NaN,\n    growiPlugin,\n  };\n\n  if (growiPlugin == null) {\n    throw new GrowiPluginValidationError(\n      \"The package.json does not have 'growiPlugin' directive.\",\n      data,\n    );\n  }\n\n  // schema version checking\n  const schemaVersion = Number(growiPlugin.schemaVersion);\n  data.schemaVersion = schemaVersion;\n  if (Number.isNaN(schemaVersion) || schemaVersion < 4) {\n    throw new GrowiPluginValidationError(\n      \"The growiPlugin directive must have a valid 'schemaVersion' directive.\",\n      data,\n    );\n  }\n\n  const types: GrowiPluginType[] = growiPlugin.types;\n  data.actualPluginTypes = types;\n  if (types == null) {\n    throw new GrowiPluginValidationError(\n      \"The growiPlugin directive does not have 'types' directive.\",\n      data,\n    );\n  }\n\n  // type checking\n  if (expectedPluginType != null) {\n    data.expectedPluginType = expectedPluginType;\n\n    if (!types.includes(expectedPluginType)) {\n      throw new GrowiPluginValidationError(\n        \"The growiPlugin directive does not have expected plugin type in 'types' directive.\",\n        data,\n      );\n    }\n  }\n\n  return data;\n};\n"],"names":["validateGrowiDirective","projectDirRoot","expectedPluginType","pkg","importPackageJson","growiPlugin","data","GrowiPluginValidationError","schemaVersion","types"],"mappings":"8LAQaA,EAAyB,CACpCC,EACAC,IAC8B,CAC9B,MAAMC,EAAMC,EAAAA,kBAAkBH,CAAc,EAEtC,CAAE,YAAAI,GAAgBF,EAElBG,EAAkC,CACtC,eAAAL,EACA,cAAe,OAAO,IACtB,YAAAI,CAAA,EAGF,GAAIA,GAAe,KACjB,MAAM,IAAIE,EAAAA,2BACR,0DACAD,CAAA,EAKJ,MAAME,EAAgB,OAAOH,EAAY,aAAa,EAEtD,GADAC,EAAK,cAAgBE,EACjB,OAAO,MAAMA,CAAa,GAAKA,EAAgB,EACjD,MAAM,IAAID,EAAAA,2BACR,yEACAD,CAAA,EAIJ,MAAMG,EAA2BJ,EAAY,MAE7C,GADAC,EAAK,kBAAoBG,EACrBA,GAAS,KACX,MAAM,IAAIF,EAAAA,2BACR,6DACAD,CAAA,EAKJ,GAAIJ,GAAsB,OACxBI,EAAK,mBAAqBJ,EAEtB,CAACO,EAAM,SAASP,CAAkB,GACpC,MAAM,IAAIK,EAAAA,2BACR,qFACAD,CAAA,EAKN,OAAOA,CACT"}