export { abort, DrakeError, env, glob, log, quote, readFile, sh, shCapture, ShCaptureOpts, ShOpts, ShOutput, updateFile, writeFile} from "./lib/utils.ts";export { desc, execute, run, task, vers };
import { existsSync } from "https://deno.land/std@v0.36.0/fs/mod.ts";import * as path from "https://deno.land/std@v0.36.0/path/mod.ts";import { help } from "./lib/help.ts";import { Action, TaskRegistry } from "./lib/tasks.ts";import { abort, env, parseEnv } from "./lib/utils.ts";
const vers: string = "0.11.0";
const taskRegistry = new TaskRegistry();
env["--abort-exits"] = true;
parseEnv(Deno.args.slice(), env);
if (env["--help"]) { help();} else if (env["--version"]) { console.log(vers);} else { let drakefile = env["--drakefile"] ?? "Drakefile.ts"; if (!path.isAbsolute(drakefile)) { drakefile = path.join(Deno.cwd(), drakefile); } env["--drakefile"] = drakefile;
if (env["--directory"]) { const dir = env["--directory"]; if (!existsSync(dir) || !Deno.statSync(dir).isDirectory()) { abort(`--directory missing or not a directory: ${dir}`); } Deno.chdir(dir); }}
function desc(description: string): void { taskRegistry.desc(description);}
function task( name: string, prereqs: string[] = [], action?: Action): void { taskRegistry.register(name, prereqs, action);}
async function run(...names: string[]) { if (env["--help"] || env["--version"]) { return; } if (env["--list-tasks"] || env["--list-all"]) { taskRegistry.list().forEach(t => console.log(t)); } else { if (names.length === 0) { names = env["--tasks"]; if (names.length === 0 && env["--default-task"]) { names.push(env["--default-task"]); } } if (names.length === 0) { abort("no task specified"); } await taskRegistry.run(...names); }}
async function execute(names: string | string[]) { await taskRegistry.execute(names);}