Skip to content

Commit

Permalink
feat: add format & lint tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Mar 7, 2024
1 parent 9bf7b42 commit ec2a3c6
Show file tree
Hide file tree
Showing 47 changed files with 248 additions and 257 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deno

on:
- push

jobs:
format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: "1.41.1"

- name: Format
run: deno task format:check

lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: "1.41.1"

- name: Lint
run: deno task lint
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Test Project
name: OpenGB

on:
- push

jobs:
build:
test-core:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -33,3 +33,21 @@ jobs:

- name: Run Tests
run: cd tests/basic/ && opengb test

test-project:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

# Add private key to be able to access OpenGB repository
- uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.GH_DEPLOY_KEY }}

- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: "1.41.1"

- name: Test
run: deno task test:core
23 changes: 0 additions & 23 deletions .github/workflows/test_core.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
**From GitHub (recommended)**
```
deno install --allow-net --allow-read --allow-env --allow-run --allow-write --name opengb --force https://raw.githubusercontent.com/rivet-gg/open-game-services-engine/main/src/cli/main.ts
deno install --allow-net --allow-read --allow-env --allow-run --allow-write --name opengb --force https://raw.githubusercontent.com/rivet-gg/opengb-engine/main/src/cli/main.ts
```
-->

Expand Down
8 changes: 8 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"artifacts:build:all": "deno task artifacts:build:schema && deno task artifacts:build:runtime_archive",
"artifacts:build:schema": "deno run --allow-env --allow-read --allow-write src/artifacts/build_schema.ts",
"artifacts:build:runtime_archive": "deno run --allow-env --allow-read --allow-write src/artifacts/build_runtime_archive.ts",

// Format
"format": "deno fmt src/",
"format:check": "deno fmt --check src/",

// Lint
"lint": "deno task artifacts:build:all && deno lint src/",

// Runs tests
"test:core": "deno task artifacts:build:all && deno test -A src/",
Expand All @@ -26,6 +33,7 @@
}
},
"fmt": {
"lineWidth": 120,
"useTabs": true
}
}
2 changes: 1 addition & 1 deletion docs/KNOWN_ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[typescript-json-schema#547](https://github.com/YousefED/typescript-json-schema/issues/547)

Will be fixed with [#15](https://github.com/rivet-gg/open-game-services-engine/issues/15).
Will be fixed with [#15](https://github.com/rivet-gg/opengb-engine/issues/15).

## Moving modules folder breaks imports

Expand Down
6 changes: 3 additions & 3 deletions docs/evaluations/DRIZZLE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Drizzle

**Querying**
https://github.com/rivet-gg/open-game-services-engine/blob/823becd385ee3a1c6bd05172577a19441716eaa4/modules/users/scripts/get.ts#L18
https://github.com/rivet-gg/opengb-engine/blob/823becd385ee3a1c6bd05172577a19441716eaa4/modules/users/scripts/get.ts#L18

The `inArray` function either needs to be imported or used in this weird
function interface. Intellisense isn't helpful here, you have to read the docs
Expand All @@ -14,7 +14,7 @@ await ctx.db.users.select().where({ id: { inArray: xxx } })
```

**Inserting**
https://github.com/rivet-gg/open-game-services-engine/blob/823becd385ee3a1c6bd05172577a19441716eaa4/modules/users/scripts/register.ts#L27
https://github.com/rivet-gg/opengb-engine/blob/823becd385ee3a1c6bd05172577a19441716eaa4/modules/users/scripts/register.ts#L27

You have to pass the schema in to the `.insert(` command, which is confusing
compared to the `db.query`. I would not be able to figure this out without an
Expand All @@ -32,7 +32,7 @@ The Drizzle way of auto-generating migrations incrementally is pretty slick,
I'll give them that.

But writing the migrations is nails on a chalkboard:
https://github.com/rivet-gg/open-game-services-engine/blob/823becd385ee3a1c6bd05172577a19441716eaa4/modules/users/db/schema.ts#L4
https://github.com/rivet-gg/opengb-engine/blob/823becd385ee3a1c6bd05172577a19441716eaa4/modules/users/db/schema.ts#L4

Need to read docs to know what to insert, default is not immediately obvious,
references functions are wonky. To be clear, all of this is clean if you're a
Expand Down
1 change: 0 additions & 1 deletion src/artifacts/build_runtime_archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ for (const file of files) {
archiveFiles[file] = await Deno.readTextFile(resolve(rootSrc, file));
}


// Create artifacts folder if it doesn't already exist
await Deno.mkdir(resolve(rootSrc, "artifacts"), { recursive: true });

Expand Down
5 changes: 2 additions & 3 deletions src/build/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function generateEntrypoint(project: Project, opts: BuildOpts) {
const runtimeModPath = genRuntimeModPath(project);

// Generate module configs
let [modImports, modConfig] = generateModImports(project, opts);
const [modImports, modConfig] = generateModImports(project, opts);

let imports = "";

Expand Down Expand Up @@ -132,8 +132,7 @@ function generateModImports(project: Project, opts: BuildOpts) {
for (const script of mod.scripts.values()) {
const runIdent = `modules$$${mod.name}$$${script.name}$$run`;

modImports +=
`import { run as ${runIdent} } from '${mod.path}/scripts/${script.name}.ts';\n`;
modImports += `import { run as ${runIdent} } from '${mod.path}/scripts/${script.name}.ts';\n`;

modConfig += `${JSON.stringify(script.name)}: {`;
modConfig += `run: ${runIdent},`;
Expand Down
26 changes: 8 additions & 18 deletions src/build/gen.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { dedent } from "./deps.ts";
import { dirname, resolve } from "../deps.ts";
import {
Module,
moduleGenPath,
Project,
Script,
scriptGenPath,
testGenPath,
typeGenPath,
} from "../project/mod.ts";
import { Module, moduleGenPath, Project, Script, scriptGenPath, testGenPath, typeGenPath } from "../project/mod.ts";
import { genRuntimeModPath } from "../project/project.ts";
import { autoGenHeader } from "./misc.ts";

Expand Down Expand Up @@ -36,8 +28,8 @@ export async function compileModuleHelper(
export { RuntimeError } from "${runtimePath}";
export type ModuleContext = ModuleContextInner<RegistryTypeInner, ${
module.db ? "prisma.PrismaClient" : "undefined"
}>;
module.db ? "prisma.PrismaClient" : "undefined"
}>;
`;

// Write source
Expand All @@ -62,8 +54,8 @@ export async function compileTestHelper(
export * from "./mod.ts";
export type TestContext = TestContextInner<RegistryTypeInner, ${
module.db ? "module.prisma.PrismaClient" : "undefined"
}>;
module.db ? "module.prisma.PrismaClient" : "undefined"
}>;
export type TestFn = (ctx: TestContext) => Promise<void>;
Expand Down Expand Up @@ -96,8 +88,8 @@ export async function compileScriptHelper(
export * from "../mod.ts";
export type ScriptContext = ScriptContextInner<RegistryTypeInner, ${
module.db ? "module.prisma.PrismaClient" : "undefined"
}>;
module.db ? "module.prisma.PrismaClient" : "undefined"
}>;
`;

// Write source
Expand Down Expand Up @@ -198,9 +190,7 @@ export async function compileModuleTypeHelper(
);

const moduleDependencies = Object.keys(module.config.dependencies || {})
.map((dependencyName) =>
`${dependencyName}: FullRegistry["${dependencyName}"]`
)
.map((dependencyName) => `${dependencyName}: FullRegistry["${dependencyName}"]`)
.join(";\n\t");

const source = dedent`
Expand Down
22 changes: 11 additions & 11 deletions src/build/inflate_runtime_archive.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import runtimeArchive from "../../artifacts/runtime_archive.json" with { type: "json" };
import { resolve, emptyDir, dirname } from "../deps.ts";
import { Project, genRuntimePath } from "../project/mod.ts";
import { dirname, emptyDir, resolve } from "../deps.ts";
import { genRuntimePath, Project } from "../project/mod.ts";

/**
* Writes a copy of the OpenGB runtime bundled with the CLI to the project.
*/
export async function inflateRuntimeArchive(project: Project) {
const inflateRuntimePath = genRuntimePath(project);
const inflateRuntimePath = genRuntimePath(project);

await emptyDir(inflateRuntimePath);
for (const [file, value] of Object.entries(runtimeArchive)) {
const absPath = resolve(inflateRuntimePath, file);
await Deno.mkdir(dirname(absPath), { recursive: true });
await Deno.writeTextFile(absPath, value);
}
}
await emptyDir(inflateRuntimePath);

for (const [file, value] of Object.entries(runtimeArchive)) {
const absPath = resolve(inflateRuntimePath, file);
await Deno.mkdir(dirname(absPath), { recursive: true });
await Deno.writeTextFile(absPath, value);
}
}
23 changes: 4 additions & 19 deletions src/build/mod.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import {
assertExists,
denoPlugins,
esbuild,
exists,
resolve,
tjs,
} from "../deps.ts";
import { assertExists, denoPlugins, esbuild, exists, resolve, tjs } from "../deps.ts";
import { crypto, encodeHex } from "./deps.ts";
import { compileSchema } from "./schema.ts";
import { generateEntrypoint } from "./entrypoint.ts";
import { generateOpenApi } from "./openapi.ts";
import {
compileModuleHelper,
compileScriptHelper,
compileTestHelper,
compileTypeHelpers,
} from "./gen.ts";
import { compileModuleHelper, compileScriptHelper, compileTestHelper, compileTypeHelpers } from "./gen.ts";
import { Project } from "../project/project.ts";
import { generateDenoConfig } from "./deno_config.ts";
import { inflateRuntimeArchive } from "./inflate_runtime_archive.ts";
Expand Down Expand Up @@ -288,9 +276,7 @@ async function buildSteps(

buildStep(buildState, {
name: "Type helpers",
files: [...project.modules.values()].map((m) =>
resolve(m.path, "module.yaml")
),
files: [...project.modules.values()].map((m) => resolve(m.path, "module.yaml")),
async build() {
await compileTypeHelpers(project);
},
Expand Down Expand Up @@ -439,8 +425,7 @@ async function buildScript(
},
async alreadyCached() {
// Read schemas from cache
const schemas =
buildState.cache.oldCache.scriptSchemas[module.name][script.name];
const schemas = buildState.cache.oldCache.scriptSchemas[module.name][script.name];
assertExists(schemas);
script.requestSchema = schemas.request;
script.responseSchema = schemas.response;
Expand Down
3 changes: 1 addition & 2 deletions src/build/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ function injectSchema(
// Update $refs to point to the new location
replaceRefs(
definition,
(ref) =>
ref.replace("#/definitions/", `#/components/schemas/${prefix}__`),
(ref) => ref.replace("#/definitions/", `#/components/schemas/${prefix}__`),
);

// Add the definition to the OpenAPI schema
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { GlobalOpts, initProject } from "../common.ts";
import { cleanProject } from "../../project/project.ts";

export const cleanCommand = new Command<GlobalOpts>()
.description("Removes all build artifacts")
.description("Removes all build artifacts")
.action(
async (opts) => {
const project = await initProject(opts);
await cleanProject(project);
const project = await initProject(opts);
await cleanProject(project);
},
);
4 changes: 2 additions & 2 deletions src/cli/commands/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ dbCommand.command("deploy").action(async (opts) => {
await migrateDeploy(project, [...project.modules.values()]);
});

// TODO: https://github.com/rivet-gg/open-game-services-engine/issues/84
// TODO: https://github.com/rivet-gg/open-game-services-engine/issues/85
// TODO: https://github.com/rivet-gg/opengb-engine/issues/84
// TODO: https://github.com/rivet-gg/opengb-engine/issues/85
// dbCommand.command("sh").action(async () => {
// const cmd = await new Deno.Command("docker-compose", {
// args: ["exec", "-it", "postgres", "psql", "--username", "postgres"],
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GlobalOpts } from "../common.ts";
import { templateProject } from "../../template/project.ts";

export const initCommand = new Command<GlobalOpts>()
.description("Create a new project")
.description("Create a new project")
.arguments("[dir]")
.action(
async (_opts, dir?: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const sdkCommand = new Command<GlobalOpts>()

sdkCommand.action(() => sdkCommand.showHelp());

sdkCommand.command("generate").action(async opts => {
sdkCommand.command("generate").action(async (opts) => {
await generate(opts.path);
});
2 changes: 1 addition & 1 deletion src/cli/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GlobalOpts, initProject } from "../common.ts";
import { build, DbDriver, Format, Runtime } from "../../build/mod.ts";
import { ensurePostgresRunning } from "../../utils/postgres_daemon.ts";

// TODO: https://github.com/rivet-gg/open-game-services-engine/issues/86
// TODO: https://github.com/rivet-gg/opengb-engine/issues/86
export const testCommand = new Command<GlobalOpts>()
.description("Run tests")
.arguments("[modules...:string]")
Expand Down
7 changes: 1 addition & 6 deletions src/cli/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Command,
CompletionsCommand,
HelpCommand,
ValidationError,
} from "./deps.ts";
import { Command, CompletionsCommand, HelpCommand, ValidationError } from "./deps.ts";
import { startCommand } from "./commands/start.ts";
import { buildCommand } from "./commands/build.ts";
import { dbCommand } from "./commands/db.ts";
Expand Down
Loading

0 comments on commit ec2a3c6

Please sign in to comment.