Implementation
final FigSpec npxSpec = FigSpec(
name: 'npx',
description: 'Execute binaries from npm packages',
args: [
FigArg(
name: 'command',
isCommand: true,
generators: [
FigGenerator(
script: [
'bash',
'-c',
'until [[ -d node_modules/ ]] || [[ \$PWD = \'/\' ]]; do cd ..; done; ls -1 node_modules/.bin/'
],
postProcess: (String out, [List<String>? tokens]) {
final cli = npxSuggestions.map((s) => s.name).toList();
return out
.split('\n')
.where((name) => !cli.contains(name))
.map((name) => FigSuggestion(
name: name,
icon: 'fig://icon?type=command',
loadSpec: name,
))
.toList();
},
),
],
suggestions: npxSuggestions,
isOptional: true,
),
],
options: [
FigOption(
name: ['--package', '-p'],
description: 'Package to be installed',
args: [
FigArg(
name: 'package',
),
],
),
FigOption(
name: ['--cache'],
args: [
FigArg(
name: 'path',
template: 'filepaths',
),
],
description: 'Location of the npm cache',
),
FigOption(
name: ['--always-spawn'],
description: 'Always spawn a child process to execute the command',
),
FigOption(
name: ['-y'],
description: 'Execute npx command without prompting for confirmation',
),
FigOption(
name: ['--no-install'],
description: 'Skip installation if a package is missing',
),
FigOption(
name: ['--userconfig'],
args: [
FigArg(
name: 'path',
template: 'filepaths',
),
],
description: 'Path to user npmrc',
),
FigOption(
name: ['--call', '-c'],
args: [
FigArg(
name: 'script',
),
],
description: 'Execute string as if inside `npm run-script`',
),
FigOption(
name: ['--shell', '-s'],
description: 'Shell to execute the command with, if any',
args: [
FigArg(
name: 'shell',
suggestions: [
FigSuggestion(name: 'bash'),
FigSuggestion(name: 'fish'),
FigSuggestion(name: 'zsh'),
],
),
],
),
FigOption(
name: ['--shell-auto-fallback'],
args: [
FigArg(
name: 'shell-fallback',
suggestions: [
FigSuggestion(name: 'bash'),
FigSuggestion(name: 'fish'),
FigSuggestion(name: 'zsh'),
],
),
],
description:
'Generate shell code to use npx as the "command not found" fallback',
),
FigOption(
name: ['--ignore-existing'],
description:
'Ignores existing binaries in \$PATH, or in the localproject. This forces npx to do a temporary install and use the latest version',
),
FigOption(
name: ['--quiet', '-q'],
description:
'Suppress output from npx itself. Subcommands will not be affected',
),
FigOption(
name: ['--npm'],
args: [
FigArg(
name: 'path to binary',
template: 'filepaths',
),
],
description: 'Npm binary to use for internal operations',
),
FigOption(
name: ['--node-arg', '-n'],
args: [],
description: 'Extra node argument when calling a node binary',
),
FigOption(
name: ['--version', '-v'],
description: 'Show version number',
),
FigOption(
name: ['--help', '-h'],
description: 'Show help',
),
],
);