2020-05-06 10:39:49 +00:00
#
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
#
2020-05-14 11:58:05 +00:00
{ stdenv , lib , deps , pkgs }:
2019-06-04 16:50:29 +00:00
2020-05-06 10:29:02 +00:00
stdenv . mkDerivation {
2020-05-14 11:58:05 +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 - a n d r o i d " ;
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
] ;
} ;
} ;
2020-05-06 10:39:49 +00:00
buildInputs = with pkgs ; [ 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 }
2020-05-06 10:29:02 +00:00
: maven { : local-repo " ${ deps . clojure } " } '
2019-06-04 16:50:29 +00:00
'' ;
2019-09-07 12:57:22 +00:00
configurePhase = ''
# Symlink Node.js modules to build directory
2020-05-06 10:39:49 +00:00
ln - s $ { deps . nodejs } /node_modules
2019-06-04 16:50:29 +00:00
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.
2020-05-14 11:58:05 +00:00
export CLASS_PATH = " $ ( f i n d ${ deps . clojure } \
- iname ' * . jar' | tr ' \ n' ' : ' ) src "
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
2020-05-14 11:58:05 +00:00
java - cp " $ C L A S S _ P A T H " clojure . main \
- m shadow . cljs . devtools . cli release mobile
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
'' ;
}