2019-09-07 12:57:22 +00:00
# This Nix expression builds the js files for the current repository given a node modules Nix expression
2019-06-04 16:50:29 +00:00
#
2019-09-07 12:57:22 +00:00
{ target ? " a n d r o i d " ,
stdenv , lib , clojure , nodejs , bash , git , openjdk ,
clojureDeps , localMavenRepoBuilder , projectNodePackage } :
2019-06-04 16:50:29 +00:00
let
2019-09-07 12:57:22 +00:00
clojureDepsLocal = localMavenRepoBuilder " c l o j u r e - p r o j e c t - d e p s " clojureDeps ;
2019-06-04 16:50:29 +00:00
in stdenv . mkDerivation {
2019-09-07 12:57:22 +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 } " ;
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
2020-04-26 12:40:06 +00:00
lib . mkFilter {
2020-04-08 13:06:40 +00:00
root = path ;
ignoreVCS = false ;
2020-03-30 07:45:25 +00:00
include = [
2020-04-08 13:06:40 +00:00
" V E R S I O N " " B U I L D _ N U M B E R " " s c r i p t s / v e r s i o n / . * "
# I want to avoid including the whole .git directory
" . g i t / H E A D " " . g i t / o b j e c t s " " . g i t / r e f s / h e a d s / . * "
2019-09-07 12:57:22 +00:00
" s r c / . * " " s h a d o w - c l j s . e d n " " i n d e x . j s "
# shadow-cljs expects these for deps resolution
" m o b i l e / j s _ f i l e s / p a c k a g e . j s o n " " m o b i l e / j s _ f i l e s / y a r n . l o c k "
# build stat's images to check if they exist
" r e s o u r c e s / . * " " t r a n s l a t i o n s / . * "
2020-03-30 07:45:25 +00:00
] ;
exclude = [
2020-04-06 15:30:41 +00:00
" r e s o u r c e s / f o n t s / . * "
2019-06-04 16:50:29 +00:00
] ;
} ;
} ;
2019-09-07 12:57:22 +00:00
buildInputs = [ clojure nodejs bash git openjdk ] ;
2019-06-04 16:50:29 +00:00
2019-09-07 12:57:22 +00:00
phases = [ " u n p a c k P h a s e " " p a t c h P h a s e " " c o n f i g u r e 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 " ] ;
# Patching shadow-cljs.edn so it uses the local maven repo of dependencies provided by Nix
2019-06-04 16:50:29 +00:00
patchPhase =
2019-09-07 12:57:22 +00:00
let anchor = '' { : s o u r c e - p a t h s [ " s r c " " t e s t / c l j s " ] '' ;
2019-06-04 16:50:29 +00:00
in ''
2019-09-07 12:57:22 +00:00
substituteInPlace shadow-cljs . edn \
2019-06-04 16:50:29 +00:00
- - replace ' $ { anchor } ' \
' $ { anchor }
2019-09-07 12:57:22 +00:00
: maven { : local-repo " ${ clojureDepsLocal } " } '
2019-06-04 16:50:29 +00:00
'' ;
2019-09-07 12:57:22 +00:00
configurePhase = ''
# Symlink Node.js modules to build directory
2019-06-04 16:50:29 +00:00
ln - s $ { projectNodePackage } /node_modules
2019-09-07 12:57:22 +00:00
# Symlink Node.JS dependency definitions
ln - sf mobile/js_files/package.json . /
ln - sf mobile/js_files/yarn.lock . /
'' ;
buildPhase = ''
# Assemble CLASSPATH from available clojure dependencies.
# We append 'src' so it can find the local sources.
export CLASS_PATH = " $ ( f i n d ${ clojureDepsLocal } - i n a m e ' * . j a r ' | t r ' \n ' ' : ' ) s r c "
2019-06-04 16:50:29 +00:00
2019-09-07 12:57:22 +00:00
# target must be one of the builds defined in shadow-cljs.edn
java - cp " $ C L A S S _ P A T H " clojure . main - m shadow . cljs . devtools . cli release $ { target }
2019-06-04 16:50:29 +00:00
'' ;
installPhase = ''
mkdir - p $ out
2019-09-07 12:57:22 +00:00
cp - r index . js app $ out /
2019-06-04 16:50:29 +00:00
'' ;
}