Skip to content

Commit

Permalink
feat: init command to create project
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Mar 6, 2024
1 parent 18f0958 commit d1d10d5
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GlobalOpts, initProject } from "../common.ts";
import { build, DbDriver, Format, Runtime } from "../../build/mod.ts";

export const buildCommand = new Command<GlobalOpts>()
.description("Build the project")
.option(
"-r, --runtime <runtime:string>",
"Set target runtime (deno, cloudflare)",
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { GlobalOpts, initProject } from "../common.ts";
import { templateScript } from "../../template/script.ts";
import { templateModule } from "../../template/module.ts";

export const createCommand = new Command<GlobalOpts>();
export const createCommand = new Command<GlobalOpts>()
.description("Create a new module or script");

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

Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { migrateDeploy } from "../../migrate/deploy.ts";
import { migrateReset } from "../../migrate/reset.ts";
import { ensurePostgresRunning } from "../../utils/postgres_daemon.ts";

export const dbCommand = new Command<GlobalOpts>();
export const dbCommand = new Command<GlobalOpts>()
.description("Database commands");

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

Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GlobalOpts, initProject } from "../common.ts";
import { listSourceFiles } from "../../project/mod.ts";

export const formatCommand = new Command<GlobalOpts>()
.description("Format source files")
.option("--check, -c", "Check if files are formatted")
.action(
async (opts) => {
Expand Down
12 changes: 12 additions & 0 deletions src/cli/commands/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Command } from "../deps.ts";
import { GlobalOpts } from "../common.ts";
import { templateProject } from "../../template/project.ts";

export const initCommand = new Command<GlobalOpts>()
.description("Create a new project")
.arguments("[dir]")
.action(
async (_opts, dir?: string) => {
await templateProject(dir || ".");
},
);
1 change: 1 addition & 0 deletions src/cli/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GlobalOpts, initProject } from "../common.ts";
import { listSourceFiles } from "../../project/mod.ts";

export const lintCommand = new Command<GlobalOpts>()
.description("Lint source files")
.action(
async (opts) => {
const project = await initProject(opts);
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { GlobalOpts } from "../common.ts";
import { generate } from "../../sdk/generate.ts";
"";

export const sdkCommand = new Command<GlobalOpts>();
export const sdkCommand = new Command<GlobalOpts>()
.description("SDK commands");

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

Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { build, DbDriver, Format, Runtime } from "../../build/mod.ts";
import { ensurePostgresRunning } from "../../utils/postgres_daemon.ts";

export const startCommand = new Command<GlobalOpts>()
.description("Start the project")
.option("--no-build", "Don't build source files")
.option("--no-check", "Don't check source files before running")
.option("--unstable-watch", "Automatically restart server on changes. This does not support all features yet.")
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ensurePostgresRunning } from "../../utils/postgres_daemon.ts";

// TODO: https://github.com/rivet-gg/open-game-services-engine/issues/86
export const testCommand = new Command<GlobalOpts>()
.description("Run tests")
.arguments("[modules...:string]")
.option("--no-build", "Don't build source files")
.option("--no-check", "Don't check source files before running")
Expand Down
10 changes: 6 additions & 4 deletions src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ import { sdkCommand } from "./commands/sdk.ts";
import { createCommand } from "./commands/create.ts";
import { lintCommand } from "./commands/lint.ts";
import { formatCommand } from "./commands/format.ts";
import { initCommand } from "./commands/init.ts";

const command = new Command();
command.action(() => command.showHelp())
.globalOption("-p, --path <path>", "Path to project root")
.command("init", initCommand)
.command("create", createCommand)
.command("start", startCommand)
.command("test", testCommand)
.command("db", dbCommand)
.command("build", buildCommand)
.command("lint", lintCommand)
.command("format, fmt", formatCommand)
.command("sdk", sdkCommand)
.command("create", createCommand)
.command("format, fmt", formatCommand)
.command("lint", lintCommand)
.command("build", buildCommand)
.command("help", new HelpCommand().global())
.command("completions", new CompletionsCommand())
.error((error, cmd) => {
Expand Down
43 changes: 29 additions & 14 deletions src/template/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@ import { ProjectConfig } from "../config/project.ts";
export async function templateProject(rootPath: string) {
await Deno.mkdir(rootPath, { recursive: true });

// Create backend.yaml
const defaultBackend: ProjectConfig = {
registries: {
local: {
local: {
directory: "modules",
}
}
},
modules: {
users: {},
}
};
await Deno.writeTextFile(resolve(rootPath, "backend.yaml"), stringify(defaultBackend))
// Create backend.yaml
const defaultBackend: ProjectConfig = {
registries: {
default: {
git: {
url: {
https: "https://github.com/rivet-gg/open-game-services.git",
ssh: "git@github.com:rivet-gg/opengb-registry.git"
},
branch: "main",
directory: "./modules",
},
},
local: {
local: {
directory: "modules",
},
},
},
modules: {
users: {},
rate_limit: {},
tokens: {},
},
};
await Deno.writeTextFile(
resolve(rootPath, "backend.yaml"),
stringify(defaultBackend),
);

// Create modules directory
await Deno.mkdir(resolve(rootPath, "modules"), { recursive: true });
Expand Down

0 comments on commit d1d10d5

Please sign in to comment.