From f179457f4e2c17a35034f74cd9df92bdd4bedcc0 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Wed, 4 Dec 2024 10:18:52 -0500 Subject: [PATCH] Check for `gel.toml` to get project directory --- integration-tests/nightly/edgedb.toml | 2 -- packages/driver/src/conUtils.server.ts | 5 ++++- packages/driver/src/conUtils.ts | 18 +++++++++--------- packages/generate/src/cli.ts | 14 ++++++++++++-- packages/generate/src/edgeql-js.ts | 3 ++- packages/generate/src/interfaces.ts | 3 ++- packages/generate/src/queries.ts | 2 +- 7 files changed, 30 insertions(+), 17 deletions(-) delete mode 100644 integration-tests/nightly/edgedb.toml diff --git a/integration-tests/nightly/edgedb.toml b/integration-tests/nightly/edgedb.toml deleted file mode 100644 index e9ced6501..000000000 --- a/integration-tests/nightly/edgedb.toml +++ /dev/null @@ -1,2 +0,0 @@ -[edgedb] -server-version = "nightly" diff --git a/packages/driver/src/conUtils.server.ts b/packages/driver/src/conUtils.server.ts index 8c88f3165..b7e74404a 100644 --- a/packages/driver/src/conUtils.server.ts +++ b/packages/driver/src/conUtils.server.ts @@ -24,7 +24,10 @@ async function findProjectDir(required = true): Promise { let dir = workingDir; const cwdDev = (await fs.stat(dir)).dev; while (true) { - if (await exists(path.join(dir, "edgedb.toml"))) { + if ( + (await exists(path.join(dir, "edgedb.toml"))) || + (await exists(path.join(dir, "gel.toml"))) + ) { projectDirCache.set(workingDir, dir); return dir; } diff --git a/packages/driver/src/conUtils.ts b/packages/driver/src/conUtils.ts index 79fae0d4f..8657871e2 100644 --- a/packages/driver/src/conUtils.ts +++ b/packages/driver/src/conUtils.ts @@ -55,7 +55,7 @@ export function isValidTlsSecurityValue( interface PartiallyNormalizedConfig { connectionParams: ResolvedConnectConfig; - // true if the program is run in a directory with `edgedb.toml` + // true if the program is run in a directory with a toml config file inProject: () => Promise; // true if the connection params were initialized from a project fromProject: boolean; @@ -658,17 +658,17 @@ async function parseConnectDsnAndArgs( // resolve config from project if (!serverUtils) { throw new errors.ClientConnectionError( - "no connection options specified either by arguments to `createClient` API " + - "or environment variables; also cannot resolve from edgedb.toml in browser " + - "(or edge runtime) environment", + "no connection options specified either by arguments to `createClient` " + + "API or environment variables; also cannot resolve from project config " + + "file in browser (or edge runtime) environment", ); } const projectDir = await serverUtils?.findProjectDir(); if (!projectDir) { throw new errors.ClientConnectionError( - "no 'edgedb.toml' found and no connection options specified" + - " either via arguments to `createClient()` API or via environment" + - " variables EDGEDB_HOST, EDGEDB_INSTANCE, EDGEDB_DSN, " + + "no project config file found and no connection options " + + "specified either via arguments to `createClient()` API or via " + + "environment variables EDGEDB_HOST, EDGEDB_INSTANCE, EDGEDB_DSN, " + "EDGEDB_CREDENTIALS or EDGEDB_CREDENTIALS_FILE", ); } @@ -721,8 +721,8 @@ async function parseConnectDsnAndArgs( fromProject = true; } else { throw new errors.ClientConnectionError( - "Found 'edgedb.toml' but the project is not initialized. " + - "Run `edgedb project init`.", + "Found project config file but the project is not initialized. " + + "Run 'edgedb project init'.", ); } } diff --git a/packages/generate/src/cli.ts b/packages/generate/src/cli.ts index f59c24ded..c58a9f19c 100644 --- a/packages/generate/src/cli.ts +++ b/packages/generate/src/cli.ts @@ -72,11 +72,21 @@ const run = async () => { let schemaDir = "dbschema"; const systemRoot = path.parse(currentDir).root; while (currentDir !== systemRoot) { - if (await exists(path.join(currentDir, "edgedb.toml"))) { + const gelToml = path.join(currentDir, "gel.toml"); + const edgedbToml = path.join(currentDir, "edgedb.toml"); + let configFile: string | null = null; + + if (await exists(gelToml)) { + configFile = gelToml; + } else if (await exists(edgedbToml)) { + configFile = edgedbToml; + } + + if (configFile) { projectRoot = currentDir; const config: { project?: { "schema-dir"?: string }; - } = TOML.parse(await readFileUtf8(currentDir, "edgedb.toml")); + } = TOML.parse(await readFileUtf8(configFile)); const maybeProjectTable = config.project; const maybeSchemaDir = diff --git a/packages/generate/src/edgeql-js.ts b/packages/generate/src/edgeql-js.ts index e72a4919e..3617b49e4 100644 --- a/packages/generate/src/edgeql-js.ts +++ b/packages/generate/src/edgeql-js.ts @@ -58,7 +58,8 @@ export async function generateQueryBuilder(params: { outputDir = path.join(root, schemaDir, "edgeql-js"); } else { throw new Error( - `No edgedb.toml found. Initialize an EdgeDB project with\n\`edgedb project init\` or specify an output directory with \`--output-dir\``, + "No project config file found. Initialize an EdgeDB project with\n" + + "'edgedb project init' or specify an output directory with '--output-dir'", ); } diff --git a/packages/generate/src/interfaces.ts b/packages/generate/src/interfaces.ts index 3d0fc9d9a..9b1c81270 100644 --- a/packages/generate/src/interfaces.ts +++ b/packages/generate/src/interfaces.ts @@ -24,7 +24,8 @@ export async function runInterfacesGenerator(params: { outFile = path.join(root, schemaDir, "interfaces.ts"); } else { throw new Error( - `No edgedb.toml found. Initialize an EdgeDB project with\n\`edgedb project init\` or specify an output file with \`--file\``, + "No project config file found. Initialize an EdgeDB project with\n" + + "'edgedb project init' or specify an output file with '--file'", ); } diff --git a/packages/generate/src/queries.ts b/packages/generate/src/queries.ts index 220adefc9..58cb8c93c 100644 --- a/packages/generate/src/queries.ts +++ b/packages/generate/src/queries.ts @@ -21,7 +21,7 @@ currently supported.`); const root = params.root ?? adapter.process.cwd(); if (noRoot) { console.warn( - `No \`edgedb.toml\` found, using process.cwd() as root directory: + `No project config file found, using process.cwd() as root directory: ${params.root} `, );