Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'add' command along with the 'foodchain' recipe #9

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
2 changes: 1 addition & 1 deletion constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const version = "0.3.4";
export const version = "0.4.0";
export const homePath = `${Deno.env.get("HOME")}/.drenv`;
export const versionsPath = `${homePath}/versions`;
export const binPath = `${homePath}/bin`;
Expand Down
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