Commit a120c914 authored by KristijanZic's avatar KristijanZic
Browse files

jaspr_cli: init at 0.23.0

parent b125f7e6
Loading
Loading
Loading
Loading
+94 −0
Original line number Diff line number Diff line
{
  lib,
  buildDartApplication,
  fetchFromGitHub,
  versionCheckHook,
  callPackage,
  yq-go,
  testers,
}:
# Note: Removed jaspr_cli from arguments because we use finalAttrs.finalPackage for tests
buildDartApplication (finalAttrs: {
  pname = "jaspr_cli";
  version = "0.23.0";

  __structuredAttrs = true;
  strictDeps = true;

  # Fetch the whole monorepo
  src = fetchFromGitHub {
    owner = "schultek";
    repo = "jaspr";
    tag = "jaspr_cli-v${finalAttrs.version}";
    hash = "sha256-V+cmnO4I4hZEdxzjnycPCTQbWpBmjESJSG9cIoMIwjo=";
  };

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

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

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

  nativeBuildInputs = [ yq-go ];

  nativeInstallCheckInputs = [
    versionCheckHook
  ];

  doInstallCheck = true;

  # Remove the resolution: workspace section.
  # Workspace dependencies break the Nix build which expects
  # all dependencies to be resolved via the lockfile.
  preBuild = ''
    yq -i 'del(.resolution)' pubspec.yaml
  '';

  passthru = {
    updateScript = lib.getExe (callPackage ./update.nix { });

    tests = {
      # Basic execution test
      help-text = testers.runCommand {
        name = "jaspr-cli-help-test";
        # Use finalPackage to refer to the finished derivation
        buildInputs = [ finalAttrs.finalPackage ];
        script = ''
          jaspr --help | grep "Usage: jaspr"
          touch $out
        '';
      };

      # Smoke test: Can it initialize a project?
      # Note: Using --no-pub-get because Nix has no network access
      create-project = testers.runCommand {
        name = "jaspr-cli-create-test";
        buildInputs = [ finalAttrs.finalPackage ];
        script = ''
          export HOME=$TMPDIR
          jaspr create -t docs my_test_project --no-pub-get
          test -f my_test_project/pubspec.yaml
          touch $out
        '';
      };
    };
  };

  meta = {
    mainProgram = "jaspr";
    homepage = "https://jaspr.site";
    description = "Command line tools for Jaspr";
    longDescription = ''
      Command line tools for the Jaspr, a modern web framework for building websites in Dart. Supports SPAs, SSR and SSG.
    '';
    changelog = "https://pub.dev/packages/jaspr_cli/changelog#${
      lib.replaceString "." "" finalAttrs.version
    }";
    license = lib.licenses.mit;
    sourceProvenance = with lib.sourceTypes; [ fromSource ];
    identifiers.cpeParts = lib.meta.cpeFullVersionWithVendor "schultek" finalAttrs.version;
    maintainers = with lib.maintainers; [ KristijanZic ];
  };
})
+887 −0

File added.

Preview size limit exceeded, changes collapsed.

+64 −0
Original line number Diff line number Diff line
{
  writeShellApplication,
  common-updater-scripts,
  nix-update,
  yq-go,
  dart,
  nix,
}:
let
  name = "update-jaspr_cli";
  packageName = "jaspr_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 resolution as in the nix build
      yq -i 'del(.resolution)' pubspec.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
  '';
}