Skip to content

Commit

Permalink
fix loading of custom config
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamsi committed Jun 30, 2024
1 parent 69bae99 commit 3794b1b
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 23 deletions.
18 changes: 18 additions & 0 deletions examples/custom-admin-ui-logo/app/(admin)/.admin/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable */
import * as view0 from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view'
import * as view1 from '@keystone-6/core/fields/types/text/views'
import * as view2 from '@keystone-6/core/fields/types/select/views'
import * as view3 from '@keystone-6/core/fields/types/checkbox/views'
import * as view4 from '@keystone-6/core/fields/types/relationship/views'
import * as view5 from '@keystone-6/core/fields/types/timestamp/views'

import * as adminConfig from '../config'

export const config = {
lazyMetadataQuery: {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"keystone","loc":{"start":22,"end":30}},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"adminMeta","loc":{"start":39,"end":48}},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"lists","loc":{"start":59,"end":64}},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"key","loc":{"start":77,"end":80}},"arguments":[],"directives":[],"loc":{"start":77,"end":80}},{"kind":"Field","name":{"kind":"Name","value":"isHidden","loc":{"start":91,"end":99}},"arguments":[],"directives":[],"loc":{"start":91,"end":99}},{"kind":"Field","name":{"kind":"Name","value":"fields","loc":{"start":110,"end":116}},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"path","loc":{"start":131,"end":135}},"arguments":[],"directives":[],"loc":{"start":131,"end":135}},{"kind":"Field","name":{"kind":"Name","value":"createView","loc":{"start":148,"end":158}},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"fieldMode","loc":{"start":175,"end":184}},"arguments":[],"directives":[],"loc":{"start":175,"end":184}}],"loc":{"start":159,"end":198}},"loc":{"start":148,"end":198}}],"loc":{"start":117,"end":210}},"loc":{"start":110,"end":210}}],"loc":{"start":65,"end":220}},"loc":{"start":59,"end":220}}],"loc":{"start":49,"end":228}},"loc":{"start":39,"end":228}}],"loc":{"start":31,"end":234}},"loc":{"start":22,"end":234}}]}}]},
fieldViews: [view0,view1,view2,view3,view4,view5],
adminMetaHash: '1mrsjib',
adminConfig,
apiPath: '/api/graphql',
adminPath: '',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use client'
import { ItemPage } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage'

export default ItemPage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use client'
import { CreateItemPage } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage'

export default CreateItemPage
4 changes: 4 additions & 0 deletions examples/custom-admin-ui-logo/app/(admin)/[listKey]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use client'
import { ListPage } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage'

export default ListPage
1 change: 1 addition & 0 deletions examples/custom-admin-ui-logo/app/(admin)/config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { components } from '../admin/config'
16 changes: 16 additions & 0 deletions examples/custom-admin-ui-logo/app/(admin)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client'
import { Layout } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App'
import { config } from './.admin'


export default function AdminLayout ({
children,
}: {
children: React.ReactNode
}) {
return (
<Layout config={config as any}>
{children}
</Layout>
)
}
4 changes: 4 additions & 0 deletions examples/custom-admin-ui-logo/app/(admin)/no-access/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use client'
import { getNoAccessPage } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/pages/NoAccessPage'

export default getNoAccessPage({ sessionsEnabled: false })
2 changes: 2 additions & 0 deletions examples/custom-admin-ui-logo/app/(admin)/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use client'
export { HomePage as default } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage'
11 changes: 11 additions & 0 deletions examples/custom-admin-ui-logo/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function RootLayout ({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
5 changes: 5 additions & 0 deletions examples/custom-admin-ui-logo/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
14 changes: 14 additions & 0 deletions examples/custom-admin-ui-logo/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// you don't need this if you're building something outside of the Keystone repo

export default {
experimental: {
// without this, 'Error: Expected Upload to be a GraphQL nullable type.'
serverComponentsExternalPackages: ['graphql'],
},
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
}
34 changes: 34 additions & 0 deletions examples/custom-admin-ui-logo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [
{
"name": "next"
}
]
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
44 changes: 24 additions & 20 deletions packages/core/src/admin-ui/system/generateAdminUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ function getDoesAdminConfigExist (adminPath: string) {

export async function writeAdminFile (file: AdminFileToWrite, projectAdminPath: string) {
const outputFilename = Path.join(projectAdminPath, file.outputPath)
const overwrite = file.overwrite || !(await fse.exists(outputFilename))

if (!overwrite) {
return Path.normalize(outputFilename)
}

if (file.mode === 'copy') {
if (!Path.isAbsolute(file.inputPath)) {
throw new Error(
`An inputPath of "${file.inputPath}" was provided to copy but inputPaths must be absolute`
)
}
await fse.ensureDir(Path.dirname(outputFilename))
if (file.overwrite && !(await fse.exists(outputFilename))) {
// TODO: should we use copyFile or copy?
await fs.copyFile(file.inputPath, outputFilename)
}
// TODO: should we use copyFile or copy?
await fs.copyFile(file.inputPath, outputFilename)
}
let content: undefined | string
try {
Expand Down Expand Up @@ -86,22 +90,22 @@ export async function generateAdminUI (
// this won't clear out empty directories, this is fine since:
// - they won't create pages in Admin UI which is really what this deleting is about avoiding
// - we'll remove them when the user restarts the process
if (isLiveReload) {
const ignoredDir = Path.resolve(projectAdminPath, '.next')
const ignoredFiles = new Set(
[
...adminFiles.map(x => x.outputPath),
...uniqueFiles,
'next-env.d.ts',
'pages/api/__keystone_api_build.js',
].map(x => Path.resolve(projectAdminPath, x))
)
// if (isLiveReload) {
// const ignoredDir = Path.resolve(projectAdminPath, '.next')
// const ignoredFiles = new Set(
// [
// ...adminFiles.map(x => x.outputPath),
// ...uniqueFiles,
// 'next-env.d.ts',
// 'pages/api/__keystone_api_build.js',
// ].map(x => Path.resolve(projectAdminPath, x))
// )

const entries = await walk(projectAdminPath, {
deepFilter: entry => entry.path !== ignoredDir,
entryFilter: entry => entry.dirent.isFile() && !ignoredFiles.has(entry.path),
})
// const entries = await walk(projectAdminPath, {
// deepFilter: entry => entry.path !== ignoredDir,
// entryFilter: entry => entry.dirent.isFile() && !ignoredFiles.has(entry.path),
// })

await Promise.all(entries.map(entry => fs.rm(entry.path, { recursive: true })))
}
// await Promise.all(entries.map(entry => fs.rm(entry.path, { recursive: true })))
// }
}
6 changes: 5 additions & 1 deletion packages/core/src/scripts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type Flags = {
server: boolean
ui: boolean
withMigrations: boolean
resetAdmin: boolean
}

function defaultFlags (flags: Partial<Flags>, defaults: Partial<Flags>) {
Expand Down Expand Up @@ -66,6 +67,9 @@ export async function cli (cwd: string, argv: string[]) {
--no-db-push (dev)
don't push any updates of your Prisma schema to your database
--reset-admin (dev)
reset generated admin files
--no-prisma (build, dev)
don't build or validate the prisma schema
Expand All @@ -87,7 +91,7 @@ export async function cli (cwd: string, argv: string[]) {
const command = input.join(' ') || 'dev'

if (command === 'dev') {
return dev(cwd, defaultFlags(flags, { dbPush: true, prisma: true, server: true, ui: true }))
return dev(cwd, defaultFlags(flags, { dbPush: true, prisma: true, server: true, ui: true, resetAdmin: false }))
}

if (command === 'migrate create') {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function resolvablePromise<T> () {

export async function dev (
cwd: string,
{ dbPush, prisma, server, ui }: Pick<Flags, 'dbPush' | 'prisma' | 'server' | 'ui'>
{ dbPush, prisma, server, ui, resetAdmin }: Pick<Flags, 'dbPush' | 'prisma' | 'server' | 'ui' | 'resetAdmin'>
) {
console.log('✨ Starting Keystone')
let lastPromise = resolvablePromise<IteratorResult<BuildResult>>()
Expand Down Expand Up @@ -264,7 +264,9 @@ export async function dev (
let nextApp
if (!system.config.ui?.isDisabled && ui) {
const paths = system.getPaths(cwd)
await fsp.rm(paths.admin, { recursive: true, force: true })
if (resetAdmin) {
await fsp.rm(paths.admin, { recursive: true, force: true })
}

console.log('✨ Generating Admin UI code')
await generateAdminUI(system.config, system.graphQLSchema, system.adminMeta, paths.admin, false)
Expand Down

0 comments on commit 3794b1b

Please sign in to comment.