Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for gel.toml to get project directory #1140

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions packages/driver/test/connection-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ async function envWrap(
const errorMapping: { [key: string]: string | RegExp } = {
credentials_file_not_found: /^cannot read credentials file/,
project_not_initialised:
/^Found 'edgedb\.toml' but the project is not initialized/,
/^Found project config file but the project is not initialized/,
no_options_or_toml:
/^no 'edgedb\.toml' found and no connection options specified either/,
/^no project config file found and no connection options specified either/,
invalid_credentials_file: /^cannot read credentials file/,
invalid_dsn_or_instance_name: /^invalid DSN or instance name/,
invalid_instance_name: /^invalid instance name/,
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
Loading