Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Jul 17, 2024
1 parent 10b5ae5 commit a6282fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
20 changes: 8 additions & 12 deletions packages/core/src/admin-ui/system/generateAdminUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export async function generateAdminUI (

// Write out the built-in admin UI files. Don't overwrite any user-defined pages.
const configFileExists = getDoesAdminConfigExist()
let adminFiles = writeAdminFiles(config, graphQLSchema, adminMeta, configFileExists)

// Add files to pages/ which point to any files which exist in admin/pages
const adminConfigDir = Path.join(process.cwd(), 'admin')
Expand All @@ -112,11 +111,10 @@ export async function generateAdminUI (
entryFilter: entry => entry.dirent.isFile() && pageExtensions.has(Path.extname(entry.name)),
})
} catch (err: any) {
if (err.code !== 'ENOENT') {
throw err
}
if (err.code !== 'ENOENT') throw err
}

let adminFiles = writeAdminFiles(config, graphQLSchema, adminMeta, configFileExists)
for (const { path } of userPagesEntries) {
const outputFilename = Path.relative(adminConfigDir, path)
const importPath = Path.relative(
Expand Down Expand Up @@ -145,14 +143,12 @@ export async function generateAdminUI (
// - 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))
)
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,
Expand Down
28 changes: 13 additions & 15 deletions packages/core/src/admin-ui/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as Path from 'path'
import type { GraphQLSchema } from 'graphql'
import { type GraphQLSchema } from 'graphql'
import {
type AdminFileToWrite,
type __ResolvedKeystoneConfig
} from '../../types'
import type { AdminMetaRootVal } from '../../lib/create-admin-meta'
import { type AdminMetaRootVal } from '../../lib/create-admin-meta'
import { appTemplate } from './app'
import { homeTemplate } from './home'
import { listTemplate } from './list'
Expand All @@ -15,26 +14,25 @@ import { nextConfigTemplate } from './next-config'

const pkgDir = Path.dirname(require.resolve('@keystone-6/core/package.json'))

export const writeAdminFiles = (
config: __ResolvedKeystoneConfig,
export function writeAdminFiles (config: __ResolvedKeystoneConfig,
graphQLSchema: GraphQLSchema,
adminMeta: AdminMetaRootVal,
configFileExists: boolean
): AdminFileToWrite[] => {
) {
return [
{
mode: 'write',
mode: 'write' as const,
src: nextConfigTemplate(config.ui?.basePath),
outputPath: 'next.config.js',
},
{
mode: 'copy',
mode: 'copy' as const,
inputPath: Path.join(pkgDir, 'static', 'favicon.ico'),
outputPath: 'public/favicon.ico',
},
{ mode: 'write', src: noAccessTemplate(config.session), outputPath: 'pages/no-access.js' },
{ mode: 'write' as const, src: noAccessTemplate(config.session), outputPath: 'pages/no-access.js' },
{
mode: 'write',
mode: 'write' as const,
src: appTemplate(
adminMeta,
graphQLSchema,
Expand All @@ -43,11 +41,11 @@ export const writeAdminFiles = (
),
outputPath: 'pages/_app.js',
},
{ mode: 'write', src: homeTemplate, outputPath: 'pages/index.js' },
...adminMeta.lists.flatMap(({ path, key }): AdminFileToWrite[] => [
{ mode: 'write', src: listTemplate(key), outputPath: `pages/${path}/index.js` },
{ mode: 'write', src: itemTemplate(key), outputPath: `pages/${path}/[id].js` },
{ mode: 'write', src: createItemTemplate(key), outputPath: `pages/${path}/create.js` },
{ mode: 'write' as const, src: homeTemplate, outputPath: 'pages/index.js' },
...adminMeta.lists.flatMap(({ path, key }) => [
{ mode: 'write' as const, src: listTemplate(key), outputPath: `pages/${path}/index.js` },
{ mode: 'write' as const, src: itemTemplate(key), outputPath: `pages/${path}/[id].js` },
{ mode: 'write' as const, src: createItemTemplate(key), outputPath: `pages/${path}/create.js` },
]),
]
}

0 comments on commit a6282fa

Please sign in to comment.