|
| 1 | +#!/usr/bin/env -S deno run --allow-all |
| 2 | + |
1 | 3 | // Copyright 2018-2026 the Deno authors. MIT license. |
2 | 4 |
|
| 5 | +/** |
| 6 | + * x - Developer CLI for contributing to Deno |
| 7 | + * |
| 8 | + * Inspired by Servo's mach tool, this script provides a unified |
| 9 | + * interface for common development tasks like building, testing, and more. |
| 10 | + * |
| 11 | + * Usage: |
| 12 | + * ./x <command> [options] |
| 13 | + * |
| 14 | + * Run `./x --help` for more information. |
| 15 | + */ |
| 16 | + |
3 | 17 | // deno-lint-ignore-file no-console |
4 | 18 |
|
5 | 19 | import $ from "jsr:@david/dax@^0.42.0"; |
@@ -370,33 +384,31 @@ function printCommandHelp(name: string, cmd: Command) { |
370 | 384 | // Entry point |
371 | 385 | // --------------------------------------------------------------------------- |
372 | 386 |
|
373 | | -export async function main(dirname: string) { |
374 | | - const root = $.path(dirname); |
375 | | - const COMMANDS = buildCommands(root); |
376 | | - const args = Deno.args; |
377 | | - |
378 | | - if ( |
379 | | - args.length === 0 || args[0] === "--help" || args[0] === "-h" || |
380 | | - args[0] === "help" |
381 | | - ) { |
382 | | - printHelp(COMMANDS); |
383 | | - Deno.exit(0); |
384 | | - } |
| 387 | +const root = $.path(import.meta.dirname).parent(); |
| 388 | +const COMMANDS = buildCommands(root); |
| 389 | +const args = Deno.args; |
385 | 390 |
|
386 | | - const subcommand = args[0]; |
387 | | - const cmd = COMMANDS[subcommand]; |
| 391 | +if ( |
| 392 | + args.length === 0 || args[0] === "--help" || args[0] === "-h" || |
| 393 | + args[0] === "help" |
| 394 | +) { |
| 395 | + printHelp(COMMANDS); |
| 396 | + Deno.exit(0); |
| 397 | +} |
388 | 398 |
|
389 | | - if (!cmd) { |
390 | | - $.logError(`Unknown command '${subcommand}'.`); |
391 | | - console.log(); |
392 | | - printHelp(COMMANDS); |
393 | | - Deno.exit(1); |
394 | | - } |
| 399 | +const subcommand = args[0]; |
| 400 | +const cmd = COMMANDS[subcommand]; |
395 | 401 |
|
396 | | - if (args.includes("--help") || args.includes("-h")) { |
397 | | - printCommandHelp(subcommand, cmd); |
398 | | - Deno.exit(0); |
399 | | - } |
| 402 | +if (!cmd) { |
| 403 | + $.logError(`Unknown command '${subcommand}'.`); |
| 404 | + console.log(); |
| 405 | + printHelp(COMMANDS); |
| 406 | + Deno.exit(1); |
| 407 | +} |
400 | 408 |
|
401 | | - await cmd.fn(args.slice(1)); |
| 409 | +if (args.includes("--help") || args.includes("-h")) { |
| 410 | + printCommandHelp(subcommand, cmd); |
| 411 | + Deno.exit(0); |
402 | 412 | } |
| 413 | + |
| 414 | +await cmd.fn(args.slice(1)); |
0 commit comments