diff --git a/commands/add.ts b/commands/add.ts new file mode 100644 index 0000000..a7f9673 --- /dev/null +++ b/commands/add.ts @@ -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") +} diff --git a/main.ts b/main.ts index 0ca4998..39d1863 100644 --- a/main.ts +++ b/main.ts @@ -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"; @@ -47,6 +48,11 @@ program.command("register") ) .action(actionRunner(register)); +program.command("add") + .argument("", "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")