Skip to content

Commit

Permalink
Use passed in directory to read config file instead of process.cwd() (#…
Browse files Browse the repository at this point in the history
…5393)

* Use passed in directory to read config file instead of process.cwd()

* Add dist
  • Loading branch information
emmatown committed Apr 7, 2021
1 parent f059f63 commit a73aea7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-cows-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Fixed reading config file to be local to the passed directory instead of `process.cwd()`
12 changes: 12 additions & 0 deletions packages-next/keystone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
"license": "MIT",
"main": "dist/keystone.cjs.js",
"module": "dist/keystone.esm.js",
"files": [
"session",
"bin",
"artifacts",
"___internal-do-not-use-will-break-in-patch",
"migrations",
"next",
"schema",
"scripts",
"session",
"dist"
],
"bin": {
"keystone-next": "bin/cli.js"
},
Expand Down
12 changes: 7 additions & 5 deletions packages-next/keystone/src/scripts/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createSystem } from '../../lib/createSystem';
import { initConfig } from '../../lib/initConfig';
import { requireSource } from '../../lib/requireSource';
import { generateNodeModulesArtifacts, validateCommittedArtifacts } from '../../artifacts';
import { CONFIG_PATH, getAdminPath } from '../utils';
import { getAdminPath, getConfigPath } from '../utils';

// FIXME: Duplicated from admin-ui package. Need to decide on a common home.
async function writeAdminFile(file: AdminFileToWrite, projectAdminPath: string) {
Expand Down Expand Up @@ -41,7 +41,9 @@ export function serializePathForImport(path: string) {
export const formatSource = (src: string, parser: 'babel' | 'babel-ts' = 'babel') =>
prettier.format(src, { parser, trailingComma: 'es5', singleQuote: true });

const reexportKeystoneConfig = async (projectAdminPath: string, isDisabled?: boolean) => {
const reexportKeystoneConfig = async (cwd: string, isDisabled?: boolean) => {
const projectAdminPath = getAdminPath(cwd);
const configPath = getConfigPath(cwd);
if (isDisabled) {
// Nuke any existing files in our target directory
await fs.remove(projectAdminPath);
Expand All @@ -57,7 +59,7 @@ const reexportKeystoneConfig = async (projectAdminPath: string, isDisabled?: boo
{
mode: 'write',
src: `export { default as config } from ${serializePathForImport(
Path.relative(Path.join(projectAdminPath, 'pages', 'api'), CONFIG_PATH)
Path.relative(Path.join(projectAdminPath, 'pages', 'api'), configPath)
)}
export default function (req, res) { return res.status(500) }`,
outputPath: Path.join('pages', 'api', '__keystone_api_build.js'),
Expand Down Expand Up @@ -85,7 +87,7 @@ const reexportKeystoneConfig = async (projectAdminPath: string, isDisabled?: boo
export async function build(cwd: string) {
console.log('✨ Building Keystone');

const config = initConfig(requireSource(CONFIG_PATH).default);
const config = initConfig(requireSource(getConfigPath(cwd)).default);

const { keystone, graphQLSchema } = createSystem(config);

Expand All @@ -104,7 +106,7 @@ export async function build(cwd: string) {
}

console.log('✨ Generating Keystone config code');
await reexportKeystoneConfig(getAdminPath(cwd), config.ui?.isDisabled);
await reexportKeystoneConfig(cwd, config.ui?.isDisabled);

console.log('✨ Building Admin UI');
await buildAdminUI(getAdminPath(cwd));
Expand Down
4 changes: 2 additions & 2 deletions packages-next/keystone/src/scripts/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
} from '../artifacts';
import { requireSource } from '../lib/requireSource';
import { initConfig } from '../lib/initConfig';
import { CONFIG_PATH } from './utils';
import { getConfigPath } from './utils';

export async function postinstall(cwd: string, shouldFix: boolean) {
const config = initConfig(requireSource(CONFIG_PATH).default);
const config = initConfig(requireSource(getConfigPath(cwd)).default);

const { keystone, graphQLSchema } = createSystem(config);

Expand Down
4 changes: 2 additions & 2 deletions packages-next/keystone/src/scripts/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { createSystem } from '../lib/createSystem';
import { generateNodeModulesArtifacts, validateCommittedArtifacts } from '../artifacts';
import { requireSource } from '../lib/requireSource';
import { initConfig } from '../lib/initConfig';
import { CONFIG_PATH } from './utils';
import { getConfigPath } from './utils';

export async function prisma(cwd: string, args: string[]) {
const config = initConfig(requireSource(CONFIG_PATH).default);
const config = initConfig(requireSource(getConfigPath(cwd)).default);

const { keystone, graphQLSchema } = createSystem(config);

Expand Down
4 changes: 2 additions & 2 deletions packages-next/keystone/src/scripts/run/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getSchemaPaths,
requirePrismaClient,
} from '../../artifacts';
import { CONFIG_PATH, getAdminPath } from '../utils';
import { getAdminPath, getConfigPath } from '../utils';

// TODO: Don't generate or start an Admin UI if it isn't configured!!
const devLoadingHTMLFilepath = path.join(
Expand All @@ -28,7 +28,7 @@ export const dev = async (cwd: string, shouldDropDatabase: boolean) => {
const server = express();
let expressServer: null | ReturnType<typeof express> = null;

const config = initConfig(requireSource(CONFIG_PATH).default);
const config = initConfig(requireSource(getConfigPath(cwd)).default);
const initKeystone = async () => {
{
const { keystone, graphQLSchema } = createSystem(config);
Expand Down
6 changes: 4 additions & 2 deletions packages-next/keystone/src/scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import path from 'path';
// TODO: Read config path from process args
export const CONFIG_PATH = path.join(process.cwd(), 'keystone');

export function getConfigPath(cwd: string) {
return path.join(cwd, 'keystone');
}

export function getAdminPath(cwd: string) {
return path.join(cwd, '.keystone/admin');
Expand Down

1 comment on commit a73aea7

@vercel
Copy link

@vercel vercel bot commented on a73aea7 Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.