summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/we/webdev/package.nix
blob: cec9d4ca6edb9657d9892a9bc4842effd47af893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
  lib,
  buildDartApplication,
  fetchFromGitHub,
  versionCheckHook,
  callPackage,
  testers,
  yq-go,
}:
buildDartApplication (finalAttrs: {
  pname = "webdev";
  version = "3.8.1";

  __structuredAttrs = true;
  strictDeps = true;

  src = fetchFromGitHub {
    owner = "dart-lang";
    repo = "webdev";
    tag = "webdev-v${finalAttrs.version}";
    hash = "sha256-IwH0+J0iCSPxP/FbKPtmhpWjE16SGyYK88xa8ioBC2w=";
  };

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

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

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

  nativeBuildInputs = [ yq-go ];

  nativeInstallCheckInputs = [
    versionCheckHook
  ];

  doInstallCheck = true;

  # Remove the dev_dependencies section.
  # Relative path overrides in the monorepo break the Nix build which expects
  # all dependencies to be resolved via the lockfile.
  preBuild = ''
    yq -i 'del(.dev_dependencies)' pubspec.yaml
  '';

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

    tests = {
      # Basic usage check
      usage = testers.runCommand {
        name = "webdev-usage-test";
        # Reference the package itself via finalPackage
        buildInputs = [ finalAttrs.finalPackage ];
        script = ''
          export HOME=$TMPDIR
          webdev --help > output.txt
          if grep -q "Usage: webdev" output.txt; then
            echo "Usage check passed ✅"
            touch $out
          else
            echo "Usage check failed ❌"
            exit 1
          fi
        '';
      };
    };
  };

  meta = {
    mainProgram = "webdev";
    homepage = "https://dart.dev/tools/webdev";
    description = "Command-line tool for developing and deploying web applications with Dart";
    longDescription = ''
      A CLI for Dart web development. Provides an easy and consistent set of features for users and tools to build and deploy web applications with Dart.
    '';
    changelog = "https://pub.dev/packages/webdev/changelog#${
      lib.replaceString "." "" finalAttrs.version
    }";
    license = lib.licenses.bsd3;
    sourceProvenance = with lib.sourceTypes; [ fromSource ];
    identifiers.cpeParts =
      let
        versionSplit = lib.split "\\+" finalAttrs.version;
        versionPart = lib.elemAt versionSplit 0;
        updatePart =
          if lib.count (x: lib.isList x) versionSplit > 0 then lib.elemAt versionSplit 2 else "*";
      in
      {
        vendor = "dart-lang";
        product = "webdev";
        version = versionPart;
        update = updatePart;
      };
    maintainers = with lib.maintainers; [ KristijanZic ];
  };
})