Unverified Commit 28c79466 authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

dart_frog_cli: init at 1.2.14 (#491078)

parents 8f96ca1c 8d12ed00
Loading
Loading
Loading
Loading
+61 −0
Original line number Diff line number Diff line
{
  lib,
  buildDartApplication,
  fetchFromGitHub,
  versionCheckHook,
  callPackage,
}:
buildDartApplication (finalAttrs: {
  pname = "dart_frog_cli";
  version = "1.2.14";

  __structuredAttrs = true;
  strictDeps = true;

  src = fetchFromGitHub {
    owner = "dart-frog-dev";
    repo = "dart_frog";
    tag = "dart_frog_cli-v${finalAttrs.version}";
    hash = "sha256-B5ET/SwQzYw251Ox/RyuLM27+M//xTehke9JJSD7Gf8=";
  };

  sourceRoot = "${finalAttrs.src.name}/packages/dart_frog_cli";

  dartEntryPoints = {
    "bin/dart_frog" = "bin/dart_frog.dart";
  };

  pubspecLock = lib.importJSON ./pubspec.lock.json;

  nativeInstallCheckInputs = [
    versionCheckHook
  ];

  doInstallCheck = true;

  preBuild = ''
    rm pubspec_overrides.yaml
  '';

  passthru = {
    updateScript = lib.getExe (callPackage ./update.nix { });
    # If your tests.nix needs the package itself, pass finalAttrs.finalPackage
    tests = callPackage ./tests.nix { };
  };

  meta = {
    mainProgram = "dart_frog";
    homepage = "https://dart-frog.dev";
    description = "Command line tools for Dart Frog";
    longDescription = ''
      The official command line interface for Dart Frog — a fast, minimalistic backend framework for Dart.
    '';
    changelog = "https://pub.dev/packages/dart_frog_cli/changelog#${
      lib.replaceString "." "" finalAttrs.version
    }";
    license = lib.licenses.mit;
    sourceProvenance = with lib.sourceTypes; [ fromSource ];
    identifiers.cpeParts = lib.meta.cpeFullVersionWithVendor "dart-frog-dev" finalAttrs.version;
    maintainers = with lib.maintainers; [ KristijanZic ];
  };
})
+797 −0

File added.

Preview size limit exceeded, changes collapsed.

+61 −0
Original line number Diff line number Diff line
{
  testers,
  dart_frog_cli,
  dart,
}:

let
  testPkgName = "my_frog_project";
in
{
  # Simple help check (Sanity test)
  usage = testers.runCommand {
    name = "dart-frog-usage-test";
    buildInputs = [ dart_frog_cli ];
    script = ''
      export HOME=$TMPDIR
      dart_frog --help > output.txt
      if grep -q "Usage: dart_frog" output.txt; then
        echo "Usage check passed ✅"
        touch $out
      else
        echo "Usage check failed ❌"
        exit 1
      fi
    '';
  };

  # Project creation test (Behavioral test)
  create-project = testers.runCommand {
    name = "dart-frog-create-test";
    buildInputs = [
      dart_frog_cli
      dart
    ];

    script = ''
      export HOME=$TMPDIR

      echo "🔨 Creating new Dart Frog project..."
      dart_frog create ${testPkgName}

      echo "---------------------------------------"
      if [ -d "${testPkgName}" ] && [ -f "${testPkgName}/pubspec.yaml" ]; then
        printf "%-20s %-15s %s\n" "Project Created:" "${testPkgName}" "✅"
        printf "%-20s %-15s %s\n" "Pubspec Found:"   "yes"            "✅"

        # Check if it generated the default route
        if [ -f "${testPkgName}/routes/index.dart" ]; then
           printf "%-20s %-15s %s\n" "Default Route:" "found"         "✅"
        fi

        echo "---------------------------------------"
        echo "Integration test passed successfully! 🚀"
        touch $out
      else
        echo "Project generation failed! ❌"
        exit 1
      fi
    '';
  };
}
+64 −0
Original line number Diff line number Diff line
{
  writeShellApplication,
  common-updater-scripts,
  nix-update,
  yq-go,
  dart,
  nix,
}:
let
  name = "update-dart_frog_cli";
  packageName = "dart_frog_cli";
  packageDir = toString ./.;
in
writeShellApplication {
  inherit name;
  runtimeInputs = [
    common-updater-scripts
    nix-update
    yq-go
    dart
    nix
  ];
  text = ''
    pname="''${UPDATE_NIX_PNAME:-${packageName}}"

    main() {
      old_version="''${UPDATE_NIX_OLD_VERSION:-$(get_version)}"
      nix-update "$pname" --version stable --version-regex "$pname-v([0-9.]+(:?\\+[0-9]+)?)"
      new_version=$(get_version)
      if [[ "$new_version" == "$old_version" ]]; then
        exit 0
      fi
      generate_lockfile
    }

    get_version() {
      nix-instantiate --raw --eval --strict -A "$pname.version"
    }

    generate_lockfile() {
      tmp_dir=$(mktemp -d)
      trap 'rm -rf "$tmp_dir"' EXIT

      src=$(nix-build --no-link . -A "$pname.src")

      cp -r "$src/packages/$pname/." "$tmp_dir/"
      chmod -R +w "$tmp_dir"
      cd "$tmp_dir"

      # Remove pubspec overrides as in the nix preBuild
      rm pubspec_overrides.yaml

      # Generate lockfile because it's not included in the source
      if ! test -f pubspec.lock; then
        dart pub get
      fi

      # Convert to JSON
      yq -o=json . pubspec.lock > "${packageDir}/pubspec.lock.json"
    }

    main
  '';
}