Skip to content

Commit 83ac5f3

Browse files
authored
Add --quiet flag to keystone CLI (#9682)
Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com>
1 parent 4bae32f commit 83ac5f3

35 files changed

+376
-384
lines changed

.changeset/add-quiet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@keystone-6/core": minor
3+
---
4+
5+
Add a `--quiet' flag to `keystone` CLI commands, suppressing most output except for errors
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export { createExpressServer } from '../lib/createExpressServer'
2-
export { createSystem } from '../lib/createSystem'
1+
export { buildArtifacts, generateArtifacts } from '../artifacts'
2+
export { createExpressServer } from '../lib/express'
33
export { withMigrate } from '../lib/migrations'
4-
export { generateArtifacts, getArtifacts } from '../artifacts'
4+
export { createSystem } from '../lib/system'
55
export { ExitError } from '../scripts/utils'

packages/core/src/admin-ui/system/generateAdminUI.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { type Entry, walk as _walk } from '@nodelib/fs.walk'
2+
import fse from 'fs-extra'
3+
import fs from 'node:fs/promises'
14
import Path from 'node:path'
25
import { promisify } from 'node:util'
3-
import fs from 'node:fs/promises'
4-
import fse from 'fs-extra'
5-
import { type Entry, walk as _walk } from '@nodelib/fs.walk'
6+
7+
import type { AdminMetaSource } from '../../lib/admin-meta'
68
import type { AdminFileToWrite, KeystoneConfig } from '../../types'
79
import { writeAdminFiles } from '../templates'
8-
import type { AdminMetaSource } from '../../lib/create-admin-meta'
910

1011
const walk = promisify(_walk)
1112

packages/core/src/admin-ui/templates/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Path from 'path'
1+
import Path from 'node:path'
22
import resolve from 'resolve'
33

4-
import type { AdminMetaSource } from '../../lib/create-admin-meta'
4+
import type { AdminMetaSource } from '../../lib/admin-meta'
55
import type { KeystoneConfig } from '../../types'
66

77
function doesConfigExist(path: string[]) {

packages/core/src/admin-ui/templates/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import path from 'path'
1+
import path from 'node:path'
2+
3+
import type { AdminMetaSource } from '../../lib/admin-meta'
24
import type { KeystoneConfig } from '../../types'
3-
import type { AdminMetaSource } from '../../lib/create-admin-meta'
45
import { appTemplate } from './app'
6+
import { createItemTemplate } from './create-item'
57
import { homeTemplate } from './home'
6-
import { listTemplate } from './list'
78
import { itemTemplate } from './item'
8-
import { noAccessTemplate } from './no-access'
9-
import { createItemTemplate } from './create-item'
9+
import { listTemplate } from './list'
1010
import { nextConfigTemplate } from './next-config'
11+
import { noAccessTemplate } from './no-access'
1112

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

packages/core/src/artifacts.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
import type { ChildProcess } from 'node:child_process'
12
import fs from 'node:fs/promises'
23
import path from 'node:path'
3-
import type { ChildProcess } from 'node:child_process'
44

5+
import { formatSchema, getGenerators } from '@prisma/internals'
56
import { printSchema } from 'graphql'
6-
import { getGenerators, formatSchema } from '@prisma/internals'
7-
import { ExitError } from './scripts/utils'
8-
import { initialiseLists } from './lib/core/initialise-lists'
9-
import { type System, getSystemPaths } from './lib/createSystem'
107
import { printPrismaSchema } from './lib/core/prisma-schema-printer'
8+
import type { System } from './lib/system'
119
import { printGeneratedTypes } from './lib/typescript-schema-printer'
1210

1311
export function getFormattedGraphQLSchema(schema: string) {
@@ -30,32 +28,29 @@ async function readFileOrUndefined(path: string) {
3028

3129
export async function validateArtifacts(cwd: string, system: System) {
3230
const paths = system.getPaths(cwd)
33-
const artifacts = await getArtifacts(system)
31+
const artifacts = await buildArtifacts(system)
3432
const [writtenGraphQLSchema, writtenPrismaSchema] = await Promise.all([
3533
readFileOrUndefined(paths.schema.graphql),
3634
readFileOrUndefined(paths.schema.prisma),
3735
])
3836

3937
if (writtenGraphQLSchema !== artifacts.graphql && writtenPrismaSchema !== artifacts.prisma) {
40-
console.error('Your Prisma and GraphQL schemas are not up to date')
41-
throw new ExitError(1)
38+
throw new Error('Your Prisma and GraphQL schemas are not up to date')
4239
}
4340

4441
if (writtenGraphQLSchema !== artifacts.graphql) {
45-
console.error('Your GraphQL schema is not up to date')
46-
throw new ExitError(1)
42+
throw new Error('Your GraphQL schema is not up to date')
4743
}
4844

4945
if (writtenPrismaSchema !== artifacts.prisma) {
50-
console.error('Your Prisma schema is not up to date')
51-
throw new ExitError(1)
46+
throw new Error('Your Prisma schema is not up to date')
5247
}
5348
}
5449

55-
export async function getArtifacts(system: System) {
56-
const lists = initialiseLists(system.config)
50+
// exported for tests
51+
export async function buildArtifacts(system: System) {
5752
const prismaSchema = await formatSchema({
58-
schemas: [[system.config.db.prismaSchemaPath, printPrismaSchema(system.config, lists)]],
53+
schemas: [[system.config.db.prismaSchemaPath, printPrismaSchema(system.config, system.lists)]],
5954
})
6055

6156
return {
@@ -65,15 +60,15 @@ export async function getArtifacts(system: System) {
6560
}
6661

6762
export async function generateArtifacts(cwd: string, system: System) {
68-
const paths = getSystemPaths(cwd, system.config)
69-
const artifacts = await getArtifacts(system)
63+
const paths = system.getPaths(cwd)
64+
const artifacts = await buildArtifacts(system)
7065
await fs.writeFile(paths.schema.graphql, artifacts.graphql)
7166
await fs.writeFile(paths.schema.prisma, artifacts.prisma)
7267
return artifacts
7368
}
7469

7570
export async function generateTypes(cwd: string, system: System) {
76-
const paths = getSystemPaths(cwd, system.config)
71+
const paths = system.getPaths(cwd)
7772
const schema = printGeneratedTypes(
7873
paths.types.relativePrismaPath,
7974
system.graphQLSchemaSudo,
@@ -84,7 +79,7 @@ export async function generateTypes(cwd: string, system: System) {
8479
}
8580

8681
export async function generatePrismaClient(cwd: string, system: System) {
87-
const paths = getSystemPaths(cwd, system.config)
82+
const paths = system.getPaths(cwd)
8883
const generators = await getGenerators({
8984
schemaPath: paths.schema.prisma,
9085
})

packages/core/src/context.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
import type { BaseKeystoneTypeInfo, KeystoneConfig, KeystoneContext } from './types'
2-
import { createSystem } from './lib/createSystem'
3-
4-
export function getContext<TypeInfo extends BaseKeystoneTypeInfo>(
5-
config: KeystoneConfig<TypeInfo>,
6-
PrismaModule: unknown
7-
): KeystoneContext<TypeInfo> {
8-
const system = createSystem(config)
9-
const { context } = system.getKeystone(PrismaModule)
10-
return context
11-
}
1+
export { getContext } from './lib/system'

packages/core/src/fields/types/relationship/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { g } from '../../..'
2-
import {
3-
type ListMetaSource,
4-
getAdminMetaForRelationshipField,
5-
} from '../../../lib/create-admin-meta'
2+
import { type ListMetaSource, getAdminMetaForRelationshipField } from '../../../lib/admin-meta'
63
import type { JSONValue } from '../../../types'
74
import {
85
type BaseListTypeInfo,
File renamed without changes.

packages/core/src/lib/coerceAndValidateForGraphQLInput.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { GraphQLSchema, VariableDefinitionNode, GraphQLInputType, GraphQLError } from 'graphql'
1+
import type { GraphQLError, GraphQLInputType, GraphQLSchema, VariableDefinitionNode } from 'graphql'
22
import { Kind } from 'graphql'
33
import { getVariableValues } from 'graphql/execution/values'
4-
import { getTypeNodeForType } from './context/executeGraphQLFieldToSource'
4+
5+
import { getTypeNodeForType } from './context/graphql'
56

67
const argName = 'where'
78

0 commit comments

Comments
 (0)