38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
const path = require('path')
|
||
|
||
function fail(message) {
|
||
console.error(`[prisma-check] ${message}`)
|
||
process.exit(1)
|
||
}
|
||
|
||
let prismaModulePath
|
||
let Prisma
|
||
|
||
try {
|
||
prismaModulePath = require.resolve('@prisma/client')
|
||
;({ Prisma } = require('@prisma/client'))
|
||
} catch (error) {
|
||
fail(`无法加载 @prisma/client:${error instanceof Error ? error.message : String(error)}`)
|
||
}
|
||
|
||
const panelScalarFields = Prisma?.PanelScalarFieldEnum
|
||
if (!panelScalarFields || typeof panelScalarFields !== 'object') {
|
||
fail('未找到 PanelScalarFieldEnum,请先执行 npm run prisma:generate')
|
||
}
|
||
|
||
if (!Object.prototype.hasOwnProperty.call(panelScalarFields, 'assemblySemantic')) {
|
||
fail(
|
||
[
|
||
'检测到 Prisma Client 与 schema 不一致:缺少 Panel.assemblySemantic 字段。',
|
||
'请先执行:npm run prisma:generate',
|
||
`当前加载路径:${prismaModulePath}`,
|
||
].join(' '),
|
||
)
|
||
}
|
||
|
||
console.log(
|
||
`[prisma-check] ok: Panel.assemblySemantic 已存在(@prisma/client: ${path.normalize(
|
||
prismaModulePath,
|
||
)})`,
|
||
)
|