chore: get dev:generate-types to work again (#5750)

This commit is contained in:
Alessio Gravili
2024-04-09 14:12:23 -04:00
committed by GitHub
parent 59681b211b
commit abf285d713
3 changed files with 53 additions and 16 deletions

View File

@@ -1 +1,2 @@
export { generateTypes } from '../bin/generateTypes.js'
export { importConfig, importWithoutClientFiles } from '../utilities/importWithoutClientFiles.js'

View File

@@ -13,6 +13,12 @@
export type BlockColumns =
| {
text?: string | null
subArray?:
| {
requiredText: string
id?: string | null
}[]
| null
id?: string | null
}[]
| null
@@ -202,7 +208,7 @@ export interface User {
hash?: string | null
loginAttempts?: number | null
lockUntil?: string | null
password: string | null
password?: string | null
}
/**
* This interface was referenced by `Config`'s JSON-Schema
@@ -247,12 +253,6 @@ export interface ArrayField {
id?: string | null
}[]
| null
rowLabelAsFunction?:
| {
title?: string | null
id?: string | null
}[]
| null
rowLabelAsComponent?:
| {
title?: string | null
@@ -774,6 +774,7 @@ export interface IndexedField {
text: string
uniqueText?: string | null
uniqueRequiredText: string
localizedUniqueRequiredText: string
/**
* @minItems 2
* @maxItems 2
@@ -1115,14 +1116,25 @@ export interface Upload {
id: string
text?: string | null
media?: string | Upload | null
richText?:
| {
richText?: {
root: {
type: string
children: {
type: string
version: number
[k: string]: unknown
}[]
| null
direction: ('ltr' | 'rtl') | null
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''
indent: number
version: number
}
[k: string]: unknown
} | null
updatedAt: string
createdAt: string
url?: string | null
thumbnailURL?: string | null
filename?: string | null
mimeType?: string | null
filesize?: number | null
@@ -1140,6 +1152,7 @@ export interface Uploads2 {
updatedAt: string
createdAt: string
url?: string | null
thumbnailURL?: string | null
filename?: string | null
mimeType?: string | null
filesize?: number | null
@@ -1153,14 +1166,25 @@ export interface Uploads2 {
export interface Uploads3 {
id: string
media?: string | Uploads3 | null
richText?:
| {
richText?: {
root: {
type: string
children: {
type: string
version: number
[k: string]: unknown
}[]
| null
direction: ('ltr' | 'rtl') | null
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''
indent: number
version: number
}
[k: string]: unknown
} | null
updatedAt: string
createdAt: string
url?: string | null
thumbnailURL?: string | null
filename?: string | null
mimeType?: string | null
filesize?: number | null

View File

@@ -1,29 +1,41 @@
import fs from 'fs'
import path from 'path'
import { generateTypes } from 'payload/node'
import { generateTypes } from '../packages/payload/src/bin/generateTypes.js'
import { setTestEnvPaths } from './helpers/setTestEnvPaths.js'
const [testConfigDir] = process.argv.slice(2)
import { fileURLToPath } from 'url'
import { load } from './loader/load.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
const loadConfig = async (configPath: string) => {
const configPromise = await load(configPath)
return configPromise.default
}
let testDir
if (testConfigDir) {
testDir = path.resolve(dirname, testConfigDir)
const config = await loadConfig(path.resolve(testDir, 'config.ts'))
setTestEnvPaths(testDir)
generateTypes()
generateTypes(config)
} else {
// Generate types for entire directory
testDir = dirname
const config = await loadConfig(path.resolve(testDir, 'config.ts'))
fs.readdirSync(dirname, { withFileTypes: true })
.filter((f) => f.isDirectory())
.forEach((dir) => {
const suiteDir = path.resolve(testDir, dir.name)
const configFound = setTestEnvPaths(suiteDir)
if (configFound) generateTypes()
if (configFound) generateTypes(config)
})
}