Skip to content

Commit

Permalink
Add 'add' command for installing foodchain
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitemaeric committed Oct 22, 2024
1 parent 7611293 commit a807917
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
23 changes: 23 additions & 0 deletions commands/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ensureDir } from "@std/fs"

export default async function add(recipe: string) {
switch (recipe) {
case "foodchain":
return foodchain();
default:
throw new Error(`Unknown recipe: ${recipe}`);
}
}

const foodchain = async () => {
console.log("Installing foodchain...")

const foodchainUrl = "https://raw.githubusercontent.com/pvande/foodchain/refs/heads/main/foodchain.rb"

const response = await fetch(foodchainUrl)
const foodchainText = await response.text()

await ensureDir("mygame/vendor/pvande/foodchain")
await Deno.writeTextFile("mygame/vendor/pvande/foodchain/foodchain.rb", foodchainText)
await Deno.writeTextFile("mygame/dependencies.rb", "require \"vendor/pvande/foodchain/foodchain.rb\"\n")
}
6 changes: 6 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Command } from "npm:commander";

import add from "./commands/add.ts";
import global from "./commands/global.ts";
import local from "./commands/local.ts";
import newCommand from "./commands/new.ts";
Expand Down Expand Up @@ -47,6 +48,11 @@ program.command("register")
)
.action(actionRunner(register));

program.command("add")
.argument("<recipe>", "Name of the recipe to add")
.description("Setup a pre-configured library")
.action(actionRunner(add));

program.command("global")
.argument("[version]", "Version of DragonRuby to use")
.description("Get or set the global version of DragonRuby")
Expand Down

0 comments on commit a807917

Please sign in to comment.