nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1#!@bash@
2packagePath() {
3 jq --raw-output --arg name "$1" '.packages.[] | select(.name == $name) .rootUri | sub("file://"; "")' .dart_tool/package_config.json
4}
5
6# Runs a Dart executable from a package with a custom path.
7#
8# Usage:
9# packageRunCustom <package> [executable] [bin_dir]
10#
11# By default, [bin_dir] is "bin", and [executable] is <package>.
12# i.e. `packageRunCustom build_runner` is equivalent to `packageRunCustom build_runner build_runner bin`, which runs `bin/build_runner.dart` from the build_runner package.
13packageRunCustom() {
14 local args=()
15 local passthrough=()
16
17 while [ $# -gt 0 ]; do
18 if [ "$1" != "--" ]; then
19 args+=("$1")
20 shift
21 else
22 shift
23 passthrough=("$@")
24 break
25 fi
26 done
27
28 local name="${args[0]}"
29 local path="${args[1]:-$name}"
30 local prefix="${args[2]:-bin}"
31
32 dart --packages=.dart_tool/package_config.json "$(packagePath "$name")/$prefix/$path.dart" "${passthrough[@]}"
33}
34
35# Runs a Dart executable from a package.
36#
37# Usage:
38# packageRun <package> [-e executable] [...]
39#
40# To run an executable from an unconventional location, use packageRunCustom.
41packageRun() {
42 local name="build_runner"
43 shift
44
45 local executableName="$name"
46 if [ "build_runner" = "-e" ]; then
47 shift
48 executableName="build_runner"
49 shift
50 fi
51
52 fileName="$(yq --raw-output --arg name "$executableName" '.executables.[$name] // $name' "$(packagePath "$name")/pubspec.yaml")"
53 packageRunCustom "$name" "$fileName" -- "$@"
54}
55
56packageRun build_runner "$@"