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
#
2019-11-29 10:20:08 +00:00
{ target-os ? " a n d r o i d " ,
stdenv , mkFilter , clojure , leiningen , nodejs ,
leinProjectDeps , 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-11-29 10:20:08 +00:00
leinProjectDepsLocalRepo = localMavenRepoBuilder " l e i n - p r o j e c t - d e p s " leinProjectDeps ;
2019-06-04 16:50:29 +00:00
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 =
2019-11-29 10:20:08 +00:00
let path = ./../../../.. ;
2019-06-04 16:50:29 +00:00
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 {
2020-03-30 07:45:25 +00:00
include = [
" s r c / . * " " p r o d / . * " " e n v / p r o d / . * "
" 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 "
" 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 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 / . * "
" 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 "
" r e s o u r c e s / j s / . * "
" r e s o u r c e s / c o n f i g / . * "
] ;
exclude = [
" r e s o u r c e s / i m a g e s / . * "
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 /
'' ;
}