about summary refs log tree commit diff
path: root/pkgs/by-name/te/textlint-rule-common-misspellings/package.nix
blob: ad17e2a91092e6da8dfb84e8b707a589b1093f50 (plain) (blame)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{
  lib,
  stdenvNoCC,
  fetchurl,
  fetchFromGitHub,
  fetchYarnDeps,
  fixup-yarn-lock,
  nodejs,
  yarn,
  textlint,
  textlint-rule-common-misspellings,
}:

# there is no lock file in this package, but it is old and stable enough
# so that we handle dependencies manually
let
  misspellings = stdenvNoCC.mkDerivation (finalAttrs: {
    pname = "misspellings";
    version = "1.1.0";

    src = fetchurl {
      url = "https://registry.npmjs.org/misspellings/-/misspellings-${finalAttrs.version}.tgz";
      hash = "sha256-+4QxmGjoF0mBldN4XQMvoK8YDS4PBV9/c+/BPf4FbkM=";
    };

    dontBuild = true;

    installPhase = ''
      runHook preInstall

      mkdir -p $out/lib/node_modules/misspellings
      cp -r . $out/lib/node_modules/misspellings/

      runHook postInstall
    '';
  });

  textlint-rule-helper = stdenvNoCC.mkDerivation (finalAttrs: {
    pname = "textlint-rule-helper";
    version = "2.3.1";

    src = fetchFromGitHub {
      owner = "textlint";
      repo = "textlint-rule-helper";
      rev = "refs/tags/v${finalAttrs.version}";
      hash = "sha256-SVeL/3KC/yazSGsmn5We8fJAuVqfcspzN7i2a4+EOlI=";
    };

    offlineCache = fetchYarnDeps {
      yarnLock = "${finalAttrs.src}/yarn.lock";
      hash = "sha256-UN56VuUHl7aS+QLON8ZROTSCGKKCn/8xuIkR46LyY+U=";
    };

    nativeBuildInputs = [
      fixup-yarn-lock
      nodejs
      yarn
    ];

    configurePhase = ''
      runHook preConfigure

      export HOME=$(mktemp -d)
      yarn config --offline set yarn-offline-mirror "$offlineCache"
      fixup-yarn-lock yarn.lock
      yarn --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive install
      patchShebangs node_modules

      runHook postConfigure
    '';

    buildPhase = ''
      runHook preBuild

      yarn --offline build

      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall

      yarn --offline --production install
      rm -r test
      mkdir -p $out/lib/node_modules/textlint-rule-helper
      cp -r . $out/lib/node_modules/textlint-rule-helper/

      runHook postInstall
    '';
  });
in
stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "textlint-rule-common-misspellings";
  version = "1.0.1";

  src = fetchurl {
    url = "https://registry.npmjs.org/textlint-rule-common-misspellings/-/textlint-rule-common-misspellings-${finalAttrs.version}.tgz";
    hash = "sha256-5QVb5T2yGuunNhRQG5brJQyicRRbO8XewzjO2RzN0bI=";
  };

  dontBuild = true;

  buildInputs = [
    misspellings
    textlint-rule-helper
  ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out/lib/node_modules/textlint-rule-common-misspellings/node_modules/textlint-rule-helper
    cp -r ${misspellings}/lib/node_modules/misspellings $out/lib/node_modules/textlint-rule-common-misspellings/node_modules/misspellings
    cp -r ${textlint-rule-helper}/lib/node_modules/textlint-rule-helper/node_modules/* $out/lib/node_modules/textlint-rule-common-misspellings/node_modules
    cp -r ${textlint-rule-helper}/lib/node_modules/textlint-rule-helper/lib $out/lib/node_modules/textlint-rule-common-misspellings/node_modules/textlint-rule-helper/lib
    cp -r ${textlint-rule-helper}/lib/node_modules/textlint-rule-helper/package.json $out/lib/node_modules/textlint-rule-common-misspellings/node_modules/textlint-rule-helper/package.json

    cp -r . $out/lib/node_modules/textlint-rule-common-misspellings/

    runHook postInstall
  '';

  passthru.tests = textlint.testPackages {
    rule = textlint-rule-common-misspellings;
    testFile = ./test.md;
  };

  meta = {
    description = "Textlint rule to check common misspellings";
    homepage = "https://github.com/io-monad/textlint-rule-common-misspellings";
    license = lib.licenses.gpl3Only;
    maintainers = with lib.maintainers; [ natsukium ];
    mainProgram = "textlint-rule-common-misspellings";
    platforms = textlint.meta.platforms;
  };
})