Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit bbd1ce3

Browse files
authored
Merge pull request #3472 from input-output-hk/devops-999-explorer-gitrev-develop
[DEVOPS-999] explorer frontend: Replace @gitrev@ with actual rev
2 parents 03af824 + 55614dd commit bbd1ce3

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

explorer/frontend/default.nix

+31-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ let
4646
nodejs = pkgs.nodejs-6_x;
4747
};
4848

49+
regen-script = pkgs.writeScriptBin "regen" ''
50+
export PATH=${makeBinPath [oldHaskellPackages.purescript-derive-lenses cardano-sl-explorer]}:$PATH
51+
cardano-explorer-hs2purs --bridge-path src/Generated/
52+
scripts/generate-explorer-lenses.sh
53+
'';
54+
4955
frontend = { stdenv, python, purescript, mkYarnPackage }:
5056
mkYarnPackage {
5157
name = "cardano-explorer-frontend";
@@ -56,14 +62,14 @@ let
5662
oldHaskellPackages.purescript-derive-lenses
5763
cardano-sl-explorer
5864
purescript
65+
regen-script
5966
];
6067
passthru = { inherit bowerComponents; };
6168
postConfigure = ''
6269
rm -rf .psci_modules .pulp-cache bower_components output result
6370
6471
# Purescript code generation
65-
cardano-explorer-hs2purs --bridge-path src/Generated/
66-
scripts/generate-explorer-lenses.sh
72+
regen
6773
6874
# Frontend dependencies
6975
ln -s ${bowerComponents}/bower_components .
@@ -85,8 +91,29 @@ let
8591
'';
8692
};
8793

94+
# Stamps the frontend with the git revision in a way that avoids
95+
# a webpack rebuild when the git revision changes.
96+
# This will just replace @GITREV@ in all javascript files.
97+
# See also: cardano-sl/scripts/set-git-rev/default.nix
98+
withGitRev = drvOut: let
99+
drvOutOutputs = drvOut.outputs or ["out"];
100+
in
101+
pkgs.runCommand drvOut.name {
102+
outputs = drvOutOutputs;
103+
passthru = drvOut.drvAttrs
104+
// (drvOut.passthru or {})
105+
// { inherit gitrev; };
106+
}
107+
(concatMapStrings (output: ''
108+
cp -a "${drvOut.${output}}" "${"$"}${output}"
109+
chmod -R +w "${"$"}${output}"
110+
find "${"$"}${output}" -type f -name '*.js' \
111+
-exec echo Setting gitrev in {} ';' \
112+
-exec sed -i 's/@GITREV@/${gitrev}/g' {} ';'
113+
'') drvOutOutputs);
114+
88115
in
89116

90-
pkgs.callPackage frontend {
117+
withGitRev (pkgs.callPackage frontend {
91118
inherit (yarn2nix) mkYarnPackage;
92-
}
119+
})

explorer/frontend/shell.nix

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{ ... }@args:
2+
3+
let
4+
cardanoPkgs = import ../.. args;
5+
frontend = cardanoPkgs.cardano-sl-explorer-frontend;
6+
7+
in
8+
# fixme: cardano-sl-explorer source is not filtered enough, so
9+
# generating files in frontend will cause a rebuild of explorer
10+
# backend. You will just have to wait a little wait to get a shell.
11+
12+
frontend.overrideAttrs (oldAttrs: {
13+
14+
shellHook = ''
15+
help() {
16+
echo "*** To regenerate purescript code, run \`regen'."
17+
echo
18+
echo "*** To build, run \`yarn build:prod'."
19+
echo "*** For dev, run \`yarn server:dev'."
20+
echo
21+
echo "*** To see this message again, run \`help'."
22+
}
23+
24+
echo; echo; help
25+
26+
export PATH=$(pwd)/node_modules/.bin:$PATH
27+
'';
28+
29+
})

0 commit comments

Comments
 (0)