start frontend code

This commit is contained in:
Cadey Ratio 2020-10-03 11:08:50 -04:00
parent a2a82eba8e
commit 62adcab9ff
23 changed files with 130 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
/target
/backend/target
mi.db

View File

53
frontend/default.nix Normal file
View File

@ -0,0 +1,53 @@
{ nixpkgs ? <nixpkgs>
, config ? {}
}:
with (import nixpkgs config);
let
mkDerivation =
{ srcs ? ./elm-srcs.nix
, src
, name
, srcdir ? "./src"
, targets ? []
, registryDat ? ./registry.dat
, outputJavaScript ? false
}:
stdenv.mkDerivation {
inherit name src;
buildInputs = [ elmPackages.elm ]
++ lib.optional outputJavaScript nodePackages_10_x.uglify-js;
buildPhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import srcs;
elmVersion = "0.19.1";
inherit registryDat;
};
installPhase = let
elmfile = module: "${srcdir}/${builtins.replaceStrings ["."] ["/"] module}.elm";
extension = if outputJavaScript then "js" else "html";
in ''
mkdir -p $out/share/doc
${lib.concatStrings (map (module: ''
echo "compiling ${elmfile module}"
elm make ${elmfile module} --output $out/${module}.${extension} --docs $out/share/doc/${module}.json
${lib.optionalString outputJavaScript ''
echo "minifying ${elmfile module}"
uglifyjs $out/${module}.${extension} --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' \
| uglifyjs --mangle --output=$out/${module}.min.${extension}
''}
'') targets)}
'';
};
in mkDerivation {
name = "mi-frontend-0.1.0";
srcs = ./elm-srcs.nix;
src = ./.;
targets = ["Main"];
srcdir = "./src";
outputJavaScript = true;
}

37
frontend/elm-srcs.nix Normal file
View File

@ -0,0 +1,37 @@
{
"elm/html" = {
sha256 = "1n3gpzmpqqdsldys4ipgyl1zacn0kbpc3g4v3hdpiyfjlgh8bf3k";
version = "1.0.0";
};
"elm/browser" = {
sha256 = "0nagb9ajacxbbg985r4k9h0jadqpp0gp84nm94kcgbr5sf8i9x13";
version = "1.0.2";
};
"elm/core" = {
sha256 = "19w0iisdd66ywjayyga4kv2p1v9rxzqjaxhckp8ni6n8i0fb2dvf";
version = "1.0.5";
};
"elm/json" = {
sha256 = "0kjwrz195z84kwywaxhhlnpl3p251qlbm5iz6byd6jky2crmyqyh";
version = "1.1.3";
};
"elm/url" = {
sha256 = "0av8x5syid40sgpl5vd7pry2rq0q4pga28b4yykn9gd9v12rs3l4";
version = "1.0.0";
};
"elm/time" = {
sha256 = "0vch7i86vn0x8b850w1p69vplll1bnbkp8s383z7pinyg94cm2z1";
version = "1.0.0";
};
"elm/virtual-dom" = {
sha256 = "0q1v5gi4g336bzz1lgwpn5b1639lrn63d8y6k6pimcyismp2i1yg";
version = "1.0.2";
};
}

24
frontend/elm.json Normal file
View File

@ -0,0 +1,24 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}

BIN
frontend/registry.dat Normal file

Binary file not shown.

1
frontend/result Symbolic link
View File

@ -0,0 +1 @@
/nix/store/r27d8p3jcpydwx8g4v2svl7p9f7f3f3k-mi-frontend-0.1.0

7
frontend/src/Main.elm Normal file
View File

@ -0,0 +1,7 @@
module Main exposing (main)
import Html exposing (Html, text)
main : Html msg
main =
text "Hello, World!"

View File

@ -8,6 +8,7 @@ let
in pkgs.mkShell {
buildInputs = with pkgs; [
# rust
ruststable
pkgconfig
openssl
@ -17,6 +18,12 @@ in pkgs.mkShell {
diesel-cli
sqlite
# elm
elmPackages.elm
elmPackages.elm-format
elmPackages.elm-language-server
elm2nix
# keep this line if you use bash
bashInteractive
];