2019-06-04 16:50:29 +00:00
#
# This Nix expression builds an index.*.js file for the current repository given a node modules Nix expression
#
{ stdenv , stdenvNoCC , lib , target-os , callPackage , pkgs ,
2019-07-23 20:54:17 +00:00
mkFilter , clojure , leiningen , maven , nodejs , localMavenRepoBuilder , projectNodePackage } :
2019-06-04 16:50:29 +00:00
let
2019-07-23 20:54:17 +00:00
lein-command = if target-os == " a l l " then " l e i n j s b u n d l e " else " l e i n j s b u n d l e - ${ target-os } " ;
2019-06-04 16:50:29 +00:00
lein-project-deps = import ../lein/lein-project-deps.nix { } ;
leinProjectDepsLocalRepo = localMavenRepoBuilder " l e i n - p r o j e c t - d e p s " lein-project-deps ;
in stdenv . mkDerivation {
2019-07-15 16:34:33 +00:00
name = " s t a t u s - r e a c t - b u i l d - j s b u n d l e - ${ target-os } " ;
2019-06-04 16:50:29 +00:00
src =
let path = ./../.. ;
in builtins . path { # We use builtins.path so that we can name the resulting derivation, otherwise the name would be taken from the checkout directory, which is outside of our control
inherit path ;
2019-07-15 16:34:33 +00:00
name = " s t a t u s - r e a c t - s o u r c e - j s b u n d l e " ;
2019-06-04 16:50:29 +00:00
filter =
# Keep this filter as restrictive as possible in order to avoid unnecessary rebuilds and limit closure size
mkFilter {
dirRootsToInclude = [
" c o m p o n e n t s / s r c " " r e a c t - n a t i v e / s r c / c l j s j s " " r e a c t - n a t i v e / s r c / m o b i l e " " s r c " " e n v / p r o d " " p r o d " # Taken from project.clj :profiles :prod :cljsbuild :builds :android :source-paths
2019-08-23 17:16:08 +00:00
" r e s o u r c e s " " s t a t u s - m o d u l e s / c l j s " " s t a t u s - m o d u l e s / r e s o u r c e s " " s c r i p t s / v e r s i o n "
2019-06-04 16:50:29 +00:00
] ;
dirsToExclude = [ " . g i t " " . s v n " " C V S " " . h g " " . g r a d l e " " b u i l d " " i n t e r m e d i a t e s " " l i b s " " o b j " ] ;
2019-08-23 17:16:08 +00:00
filesToInclude = [ " b u i l d . c l j " " e x t e r n s . j s " " p r o j e c t . c l j " " p r e p a r e - m o d u l e s . j s " " V E R S I O N " " B U I L D _ N U M B E R " ] ;
2019-06-04 16:50:29 +00:00
root = path ;
} ;
} ;
buildInputs = [ clojure leiningen nodejs ] ;
LEIN_OFFLINE = " y " ;
phases = [ " u n p a c k P h a s e " " p a t c h P h a s e " " b u i l d P h a s e " " i n s t a l l P h a s e " ] ;
patchPhase =
let anchor = '' : u r l " h t t p s : / / g i t h u b . c o m / s t a t u s - i m / s t a t u s - r e a c t / " '' ;
in ''
substituteInPlace project . clj \
- - replace ' $ { anchor } ' \
' $ { anchor }
: local-repo " ${ leinProjectDepsLocalRepo } " ' \
- - replace ' [ rasom/lein-githooks " ' ' ; ; [ r a s o m / l e i n - g i t h o o k s " ' \
- - replace ' : githooks' ' ; ; : githooks' \
- - replace ' : pre-commit' ' ; ; : pre-commit'
'' ;
buildPhase = ''
ln - s $ { projectNodePackage } /node_modules
# On macOS, lein tries to create $HOME/.lein, which fails with java.lang.Exception: Couldn't create directories: /homeless-shelter/.lein, so we just make it use a temp dir
tmp = $ ( mktemp - d )
HOME = $ tmp $ { lein-command }
rm - rf $ tmp
unset tmp
node prepare-modules . js
'' ;
installPhase = ''
mkdir - p $ out
cp index . * . js $ out /
'' ;
}