Design system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

54 lines
1.2 KiB

  1. #!/usr/bin/env node
  2. import { hideBin } from 'yargs/helpers';
  3. import yargs from 'yargs';
  4. const main = async (args: string[]) => {
  5. const COMMANDS = {
  6. init: await import('./commands/init'),
  7. serve: await import('./commands/serve'),
  8. analyze: await import('./commands/analyze'),
  9. refresh: await import('./commands/refresh'),
  10. };
  11. const yargsBuilder = Object.entries(COMMANDS).reduce(
  12. (theYargs, [name, command]) => theYargs.command(
  13. name,
  14. command.description ?? '',
  15. command.builder ?? ((commandYargs) => commandYargs),
  16. ),
  17. yargs
  18. .scriptName('amanuensis'),
  19. );
  20. const { _: commandNamesRaw, ...etcArgs } = await yargsBuilder.parse(args);
  21. const [commandName, ...subcommands] = commandNamesRaw as [keyof typeof COMMANDS, ...string[]];
  22. if (typeof commandName === 'undefined') {
  23. yargsBuilder.showHelp();
  24. return -1;
  25. }
  26. const { [commandName]: commandDef } = COMMANDS;
  27. if (typeof commandDef === 'undefined') {
  28. process.stderr.write(`Unknown command: ${commandName}\n`);
  29. yargsBuilder.showHelp();
  30. return -1;
  31. }
  32. const { default: handler } = commandDef;
  33. return handler({
  34. ...etcArgs,
  35. subcommands,
  36. });
  37. };
  38. main(hideBin(process.argv))
  39. .then((code = 0) => {
  40. // noop
  41. process.exit(code);
  42. })
  43. .catch(() => {
  44. process.exit(-1);
  45. });