wwwfiberdirekt/fix_final.py

73 lines
2.2 KiB
Python

#!/usr/bin/env python3
import re
# Fix 1: Clean up debug globals in payload.config.ts
path = 'src/payload.config.ts'
with open(path) as f: c = f.read()
old = """ globals: (() => {
const g = [Header, Footer, AnnouncementBar, PopupAnnouncement]
g.forEach((x, i) => { if (!x || !x.slug) console.error('UNDEFINED GLOBAL at index', i, ':', ['Header','Footer','AnnouncementBar','PopupAnnouncement'][i]) })
return g.filter(x => x && x.slug)
})(),"""
new = " globals: [Header, Footer, AnnouncementBar, PopupAnnouncement],"
if old in c:
c = c.replace(old, new)
with open(path, 'w') as f: f.write(c)
print('✓ Cleaned up globals debug code')
else:
print('⚠ Pattern not found in payload.config.ts - may already be clean')
for line in c.split('\n'):
if 'globals' in line:
print(' ', repr(line))
# Fix 2: Restore formBuilderPlugin in plugins/index.ts
path = 'src/plugins/index.ts'
with open(path) as f: c = f.read()
if 'formBuilderPlugin' not in c:
# Add import
c = c.replace(
"import { nestedDocsPlugin }",
"import { formBuilderPlugin } from '@payloadcms/plugin-form-builder'\nimport { FixedToolbarFeature, HeadingFeature, lexicalEditor } from '@payloadcms/richtext-lexical'\nimport { nestedDocsPlugin }"
)
# Add plugin before searchPlugin
c = c.replace(
" searchPlugin({",
""" formBuilderPlugin({
fields: {
payment: false,
},
formOverrides: {
fields: ({ defaultFields }) => {
return defaultFields.map((field) => {
if ('name' in field && field.name === 'confirmationMessage') {
return {
...field,
editor: lexicalEditor({
features: ({ rootFeatures }) => {
return [
...rootFeatures,
FixedToolbarFeature(),
HeadingFeature({ enabledHeadingSizes: ['h1', 'h2', 'h3', 'h4'] }),
]
},
}),
}
}
return field
})
},
},
}),
searchPlugin({"""
)
with open(path, 'w') as f: f.write(c)
print('✓ Restored formBuilderPlugin')
else:
print('✓ formBuilderPlugin already present')
print('\nDone. Restart dev server.')