Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Oct 21, 2022
1 parent bb2872e commit b789b28
Show file tree
Hide file tree
Showing 23 changed files with 1,078 additions and 960 deletions.
1 change: 1 addition & 0 deletions _generate/FILES.ts

Large diffs are not rendered by default.

12 changes: 1 addition & 11 deletions _generate/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,20 +727,10 @@ export class DirBuilder {
}

const mod = this.getPath(`modules/${this._modules.get(moduleName)}`);
const edgedb = "edgedb";

mod.addImport({$: true}, edgedb);
mod.addImportStar("$", "../reflection", {allowFileExt: true});
mod.addImportStar("_", "../imports", {allowFileExt: true});

// @ts-ignore
const isDeno = typeof Deno !== "undefined";
if (moduleName === "std" && isDeno) {
mod.addImport(
{Buffer: true},
"https://deno.land/[email protected]/node/buffer.ts"
);
}

return mod;
}

Expand Down
69 changes: 54 additions & 15 deletions _generate/cli.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#!/usr/bin/env node

// tslint:disable no-console
// tslint:disable:no-console
import {adapter} from "../mod.ts";

import {
ConnectConfig,
parseConnectArguments,
validTlsSecurityValues
} from "../_src/conUtils.ts";
import {ConnectConfig, validTlsSecurityValues} from "../_src/conUtils.ts";
import {parseConnectArguments} from "../_src/conUtils.server.ts";
import {
CommandOptions,
promptForPassword,
readPasswordFromStdin
} from "./commandutil.ts";
import {generateQueryBuilder} from "./edgeql-js.ts";
import {exitWithError} from "./generate.ts";
import {runInterfacesGenerator} from "./interfaces.ts";
import {exitWithError} from "./genutil.ts";
import {generateQueryFiles} from "./queries.ts";

const {path, readFileUtf8, exists} = adapter;

enum Generator {
QueryBuilder = "edgeql-js",
Queries = "queries"
Queries = "queries",
Interfaces = "interfaces"
}

const run = async () => {
Expand All @@ -37,7 +36,7 @@ const run = async () => {
}
if (!generator || generator[0] === "-") {
console.error(
`Error: No generator specified.\n \`npx @edgedb/generate [generator]\`\nAvailable generators:\n - edgeql-js (query builder)\n - queries (query files)`
`Error: No generator specified.\n \`npx @edgedb/generate <generator>\`\nAvailable generators:\n - edgeql-js (query builder)\n - queries (query files)`
);
adapter.exit();
}
Expand All @@ -48,6 +47,16 @@ const run = async () => {
adapter.exit();
}

switch (generator) {
case Generator.QueryBuilder:
break;
case Generator.Queries:
break;
case Generator.Interfaces:
options.target = "ts";
break;
}

while (args.length) {
let flag = args.shift()!;
let val: string | null = null;
Expand Down Expand Up @@ -135,6 +144,11 @@ const run = async () => {
connectionConfig.tlsSecurity = tlsSec;
break;
case "--target":
if (generator === Generator.Interfaces) {
exitWithError(
`--target is not supported for generator "${generator}"`
);
}
const target = getVal();
if (!target || !["ts", "esm", "cjs", "mts", "deno"].includes(target)) {
exitWithError(
Expand All @@ -147,16 +161,29 @@ const run = async () => {
break;
case "--out":
case "--output-dir":
if (
generator === Generator.Interfaces ||
generator === Generator.Queries
) {
exitWithError(
`--output-dir is not supported for generator "${generator}"`
);
}
options.out = getVal();
break;
case "--file":
if (generator !== Generator.Queries) {
exitWithError(`Unknown option: ${flag}`);
}
if (args.length > 0 && args[0][0] !== "-") {
if (generator === Generator.Interfaces) {
options.file = getVal();
} else if (generator === Generator.Queries) {
if (args.length > 0 && args[0][0] !== "-") {
options.file = getVal();
} else {
options.file = "dbschema/queries";
}
} else {
options.file = "dbschema/queries";
exitWithError(
`Flag --file not supported for generator "${generator}"`
);
}

break;
Expand Down Expand Up @@ -220,6 +247,9 @@ const run = async () => {
case Generator.Queries:
console.log(`Generating functions from .edgeql files...`);
break;
case Generator.Interfaces:
console.log(`Generating TS interfaces from schema...`);
break;
}

let currentDir = adapter.process.cwd();
Expand Down Expand Up @@ -324,6 +354,13 @@ Run this command inside an EdgeDB project directory or specify the desired targe
root: projectRoot
});
break;
case Generator.Interfaces:
await runInterfacesGenerator({
options,
connectionConfig,
root: projectRoot
});
break;
}
};

Expand All @@ -336,8 +373,10 @@ USAGE
npx @edgedb/generate [COMMAND] [OPTIONS]
COMMANDS:
edgeql-js Generate query builder
queries Generate typed functions from .edgeql files
edgeql-js Generate query builder
interfaces Generate TS interfaces for schema types
CONNECTION OPTIONS:
-I, --instance <instance>
Expand Down
148 changes: 0 additions & 148 deletions _generate/codecToType.ts

This file was deleted.

4 changes: 2 additions & 2 deletions _generate/commandutil.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node

// tslint:disable no-console
// tslint:disable:no-console
import {adapter} from "../mod.ts";
import {exitWithError, Target} from "./generate.ts";
import {exitWithError, Target} from "./genutil.ts";

export interface CommandOptions {
showHelp?: boolean;
Expand Down
Loading

0 comments on commit b789b28

Please sign in to comment.