Skip to content

Commit

Permalink
Check for gel.toml to get project directory
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh committed Dec 4, 2024
1 parent 807e866 commit f179457
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
2 changes: 0 additions & 2 deletions integration-tests/nightly/edgedb.toml

This file was deleted.

5 changes: 4 additions & 1 deletion packages/driver/src/conUtils.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ async function findProjectDir(required = true): Promise<string | null> {
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;
}
Expand Down
18 changes: 9 additions & 9 deletions packages/driver/src/conUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>;
// true if the connection params were initialized from a project
fromProject: boolean;
Expand Down Expand Up @@ -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",
);
}
Expand Down Expand Up @@ -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'.",
);
}
}
Expand Down
14 changes: 12 additions & 2 deletions packages/generate/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 2 additions & 1 deletion packages/generate/src/edgeql-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/generate/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/generate/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
`,
);
Expand Down

0 comments on commit f179457

Please sign in to comment.