bunSpec top-level property

FigSpec bunSpec
final

Completion spec for bun CLI

Implementation

final FigSpec bunSpec = FigSpec(
    name: 'bun',
    icon: 'asset://bun.png',
    description:
        'A fast bundler, transpiler, JavaScript Runtime and package manager for web software',
    args: [
      FigArg(name: 'file', generators: [
        const FigGenerator(template: 'filepaths'),
        npmScriptsGenerator
      ]),
      FigArg(name: 'args')
    ],
    options: [
      ...sharedPublicParams.where((p) {
        final name = p.name;
        if (name is String) {
          return name.contains('--inspect') ||
              name.contains('--hot') ||
              name.contains('--watch');
        }
        if (name is List) {
          return name.any((n) =>
              n.contains('--inspect') ||
              n.contains('--hot') ||
              n.contains('--watch'));
        }
        return false;
      }),
    ],
    subcommands: [
      FigSubcommand(
          name: ['c', 'create'],
          icon: 'asset://bun.png',
          description: 'Start a new project from a template',
          args: [
            FigArg(
                name: 'template',
                description:
                    'Package from @bun-examples, GitHub repo, or local file',
                suggestions: [
                  const FigSuggestion(name: 'react'),
                  const FigSuggestion(name: 'next'),
                  const FigSuggestion(name: 'hono'),
                  const FigSuggestion(name: 'discord-interactions'),
                  const FigSuggestion(name: 'blank'),
                  const FigSuggestion(name: 'bun-bakery'),
                  // Note: npxSuggestions are not easily portable without npx.dart logic.
                  // Placeholder for now.
                  const FigSuggestion(name: 'create-react-app', priority: 76),
                  const FigSuggestion(name: 'create-next-app', priority: 76),
                ],
                generators: [
                  const FigGenerator(template: 'folders'),
                  const FigGenerator(
                      script: ['command', 'ls', '-1', '.bun-create'],
                      splitOn: '\n'),
                  // createCLIsGenerator logic would go here
                ]),
            FigArg(name: 'name', template: 'folders')
          ],
          options: [
            FigOption(name: '--force', description: 'Overwrite existing files'),
            FigOption(
                name: '--no-install',
                description: 'Don\'t install node_modules'),
            FigOption(
                name: '--no-git',
                description: 'Don\'t create a git repository'),
            FigOption(name: '--verbose', description: 'Too many logs'),
            FigOption(
                name: '--no-package-json',
                description: 'Disable package.json transforms'),
            FigOption(
                name: '--open',
                description: 'On finish, start bun and open in browser')
          ]),
      FigSubcommand(
          name: 'run',
          icon: 'asset://bun.png',
          description: 'Run a package.json script or executable',
          args: [
            FigArg(name: 'script', filterStrategy: 'fuzzy', generators: [
              const FigGenerator(template: 'filepaths'),
              npmScriptsGenerator
            ])
          ]),
      FigSubcommand(
          name: ['i', 'install'],
          icon: '📦',
          description: 'Install dependencies for a package.json',
          options: dependencyOptions),
      FigSubcommand(
          name: ['a', 'add'],
          icon: '📦',
          description: 'Add a dependency to package.json',
          options: dependencyOptions,
          args: [
            FigArg(
                name: 'package',
                isVariadic: true,
                generators: [npmSearchGenerator],
                filterStrategy: 'fuzzy')
          ]),
      FigSubcommand(
          name: ['rm', 'remove'],
          icon: '📦',
          description: 'Remove a dependency from package.json',
          options: dependencyOptions,
          args: [
            FigArg(
                name: 'package',
                filterStrategy: 'fuzzy',
                generators: [dependenciesGenerator],
                isVariadic: true)
          ]),
      FigSubcommand(
          name: ['build', 'bun'],
          icon: 'asset://bun.png',
          description: 'Bundle files using Bun\'s native bundler',
          args: [
            FigArg(
                name: 'entrypoints',
                isVariadic: true,
                generators: [const FigGenerator(template: 'filepaths')],
                description:
                    'Entrypoint to bundle. If multiple entrypoints provided, must specify --outdir')
          ],
          options: [...buildOnlyParams, ...sharedPublicParams]),
      FigSubcommand(
          name: 'update',
          icon: 'asset://bun.png',
          description: 'Update outdated dependencies',
          options: dependencyOptions,
          args: [
            FigArg(
                name: 'package',
                filterStrategy: 'fuzzy',
                isOptional: true,
                generators: [dependenciesGenerator],
                isVariadic: true)
          ]),
      FigSubcommand(
          name: 'link',
          icon: '📦',
          description: 'Link a package',
          args: [
            FigArg(name: 'package', generators: [
              dependenciesGenerator, // Approximate for local link
            ])
          ]),
      FigSubcommand(
          name: 'unlink',
          icon: '📦',
          description: 'Unlink a package',
          args: [
            FigArg(name: 'package', generators: [dependenciesGenerator])
          ]),
      FigSubcommand(
          name: 'pm',
          icon: 'asset://bun.png',
          description: 'Package manager utilities',
          subcommands: [
            FigSubcommand(
                name: 'bin',
                description: 'Print the path to the bin directory',
                options: [
                  FigOption(
                      name: '-g', description: 'Print the global bin directory')
                ]),
            FigSubcommand(
                name: 'ls',
                description: 'List installed dependencies',
                options: [
                  FigOption(name: '--all', description: 'List all dependencies')
                ]),
            FigSubcommand(
                name: 'cache',
                description: 'Manage the cache',
                subcommands: [
                  FigSubcommand(
                    name: 'rm',
                    description: 'Clear the cache',
                  )
                ])
          ]),
      FigSubcommand(name: 'test', description: 'Run tests', options: [
        ...testOnlyParams,
        ...notBunDevFlags
      ], args: [
        FigArg(
            name: 'files',
            isVariadic: true,
            generators: [const FigGenerator(template: 'filepaths')])
      ]),
      FigSubcommand(
          name: 'x',
          icon: 'asset://bun.png',
          description: 'Execute a package binary (dlx)',
          args: [
            FigArg(name: 'package', generators: [npmSearchGenerator]),
            FigArg(name: 'args', isVariadic: true)
          ]),
      FigSubcommand(
          name: 'repl',
          icon: 'asset://bun.png',
          description: 'Start the Bun REPL'),
      FigSubcommand(
          name: 'init',
          icon: 'asset://bun.png',
          description: 'Start a new empty Bun project'),
      FigSubcommand(
          name: 'upgrade',
          icon: 'asset://bun.png',
          description: 'Upgrade Bun',
          options: [
            FigOption(
                name: '--canary', description: 'Upgrade to the canary build')
          ])
    ]);