Create controller
Last updated
mkdir src/controllers/foo
cd src/controllers/fooimport { ToolController } from "../../core";
import { versionCommand } from "./version";
import { updateCommand } from "./update";
import { runCommand } from "./run";
export const Foo: ToolController = {
name: "foo",
title: "Foo Tool",
commands: [
versionCommand,
updateCommand,
runCommand,
],
};import path from "path";
import fs from "fs";
import { Terminal, everdevHome } from "../../core";
function fooHome() {
return path.resolve(everdevHome(), "foo");
}
async function ensureInstalled(terminal: Terminal) {
}
export async function getVersion(): Promise<string> {
return "1.0.0";
}
export async function updateVersion(terminal: Terminal) {
if (fs.existsSync(fooHome())) {
fs.rmdirSync(fooHome(), { recursive: true });
}
ensureInstalled(terminal);
}
export async function runFoo(terminal: Terminal, workDir: string, args: string[]): Promise<void> {
ensureInstalled(terminal);
terminal.log("Foo succeeded");
};import { getVersion } from "./installer";
import { Command, Terminal } from "../../core";
export const versionCommand: Command = {
name: "version",
title: "Show Foo Version",
async run(terminal: Terminal, _args: {}): Promise<void> {
terminal.log(await getVersion());
},
};import { updateVersion } from "./installer";
import { Command, Terminal } from "../../core";
export const versionCommand: Command = {
name: "update",
title: "Update Foo Version",
async run(terminal: Terminal, _args: {}): Promise<void> {
await updateVersion(terminal);
},
};import { runFoo } from "./installer";
import { Command, Terminal } from "../../core";
export const runCommand: Command = {
name: "run",
title: "Run Foo",
async run(terminal: Terminal, args: {}): Promise<void> {
await runFoo(terminal, args);
},
};