git.iko.soy/typeable/octopod
on master help sign in
Reduced size of frontend js (#60)

* Reduced size of frontend js * Pass externs to jscc * Cleaned things up

commit61d53d36002e6892c63b5c58bc795267e2f8ed1b authoriko <ilyakooo0@gmail.com> dateThu 5 Aug 2021, 18:18 (5 years ago) parenta610411
8 files changed+40−26
default.nix+4−1 nix/default.nix+10−7 nix/sources.json+9−9 nix/sources.nix+4−1 octopod-common/octopod-common.cabal+1−1 octopod-common/src/Common/Validation.hs+6−6 octopod-frontend/octopod-frontend.cabal+2 shell.nix+4−1
default.nix+4−1
@@ -38,10 +38,13 @@ let
3838in
3939hsPkgs // {
4040 octopod-frontend-pretty =
41+ let frontend = hsPkgs.projectCross.ghcjs.hsPkgs.octopod-frontend.components.exes.frontend;
42+ in
4143 pkgs.runCommand "octopod-frontend-pretty"
4244 { } ''
4345 mkdir $out
4446 cp ${./octopod-frontend/index.html} $out/index.html
45− cp ${hsPkgs.projectCross.ghcjs.hsPkgs.octopod-frontend.components.exes.frontend}/bin/frontend.jsexe/all.js $out/all.js
47+ cp ${frontend}/bin/frontend.jsexe/all.js $out/all.js
48+ cp ${frontend}/bin/frontend.jsexe/all.js.externs $out/all.js.externs
4649 '';
4750}
nix/default.nix+10−7
@@ -11,15 +11,18 @@ let
1111 octo-cli = hsPkgs.octo-cli.components.exes.octo;
1212 octopod-backend = hsPkgs.octopod-backend.components.exes.octopod-exe;
1313
14− terser = (import sources.nixpkgs { inherit system; }).nodePackages.terser;
14+ closurecompiler = (import sources.nixpkgs { inherit system; }).closurecompiler;
1515
16− octopod-frontend-ugly = pkgs.runCommand "octopod-frontend-ugly"
17− { } ''
18− mkdir $out
19− cp ${hsPkgs.octopod-frontend-pretty}/index.html $out/index.html
16+ octopod-frontend-ugly =
17+ let frontend = hsPkgs.octopod-frontend-pretty;
18+ in
19+ pkgs.runCommand "octopod-frontend-ugly"
20+ { } ''
21+ mkdir $out
22+ cp ${../octopod-frontend/index.html} $out/index.html
2023
21− ${terser}/bin/terser ${hsPkgs.octopod-frontend-pretty}/all.js -o $out/all.js -mangle -c
22− '';
24+ ${closurecompiler}/bin/closure-compiler --compilation_level ADVANCED --jscomp_off=checkVars --warning_level QUIET --js ${frontend}/all.js --externs ${frontend}/all.js.externs --js_output_file $out/all.js
25+ '';
2326
2427 octopod-server-container = pkgs.dockerTools.buildImage {
2528 name = "octopod-server-container-slim";
nix/sources.json+9−9
@@ -5,10 +5,10 @@
55 "homepage": "https://input-output-hk.github.io/haskell.nix",
66 "owner": "input-output-hk",
77 "repo": "haskell.nix",
8− "rev": "920ac43ee13d95f56d7539bece1f5ee41b10c8a9",
9− "sha256": "0px60yvag24ayj9zl82cbnpixm41slj2wqw4p2vgbwnbz125hgsx",
8+ "rev": "9d940715665e28af6a60c760946330c6c63f2e29",
9+ "sha256": "0pcmab8lqxla97cd0726s1nasrwapz95wd78ps9xlv3spz5j2x0n",
1010 "type": "tarball",
11− "url": "https://github.com/input-output-hk/haskell.nix/archive/920ac43ee13d95f56d7539bece1f5ee41b10c8a9.tar.gz",
11+ "url": "https://github.com/input-output-hk/haskell.nix/archive/9d940715665e28af6a60c760946330c6c63f2e29.tar.gz",
1212 "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
1313 },
1414 "niv": {
@@ -17,10 +17,10 @@
1717 "homepage": "https://github.com/nmattia/niv",
1818 "owner": "nmattia",
1919 "repo": "niv",
20− "rev": "ba57d5a29b4e0f2085917010380ef3ddc3cf380f",
21− "sha256": "1kpsvc53x821cmjg1khvp1nz7906gczq8mp83664cr15h94sh8i4",
20+ "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070",
21+ "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx",
2222 "type": "tarball",
23− "url": "https://github.com/nmattia/niv/archive/ba57d5a29b4e0f2085917010380ef3ddc3cf380f.tar.gz",
23+ "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz",
2424 "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
2525 },
2626 "nix-filter": {
@@ -41,10 +41,10 @@
4141 "homepage": "",
4242 "owner": "NixOS",
4343 "repo": "nixpkgs",
44− "rev": "eb93bf6eed08d06bc4eb08b534e544b1f9b4e966",
45− "sha256": "0sm6n0m396szc5wzrkmyqff26qlf3vi9naykyj5vb0lzm485r99n",
44+ "rev": "5c717aad36eda145bd208f65eced1f103f60535f",
45+ "sha256": "14adjx3vzjpkzvlw6a0q04csip2s6cjfyxmrq63a31nm1xikfjqq",
4646 "type": "tarball",
47− "url": "https://github.com/NixOS/nixpkgs/archive/eb93bf6eed08d06bc4eb08b534e544b1f9b4e966.tar.gz",
47+ "url": "https://github.com/NixOS/nixpkgs/archive/5c717aad36eda145bd208f65eced1f103f60535f.tar.gz",
4848 "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
4949 }
5050}
nix/sources.nix+4−1
@@ -98,7 +98,10 @@ let
9898 saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
9999 ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
100100 in
101− if ersatz == "" then drv else ersatz;
101+ if ersatz == "" then drv else
102+ # this turns the string into an actual Nix path (for both absolute and
103+ # relative paths)
104+ if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
102105
103106 # Ports of functions for older nix versions
104107
octopod-common/octopod-common.cabal+1−1
@@ -34,6 +34,7 @@ library
3434 , ScopedTypeVariables
3535 , TypeApplications
3636 , TypeOperators
37+ , ViewPatterns
3738 build-depends: base
3839 , aeson
3940 , bytestring
@@ -41,7 +42,6 @@ library
4142 , generic-lens
4243 , http-api-data
4344 , lens
44− , regex-tdfa
4545 , text
4646 hs-source-dirs: src
4747 default-language: Haskell2010
octopod-common/src/Common/Validation.hs+6−6
@@ -8,13 +8,13 @@ module Common.Validation
88 )
99where
1010
11−import Data.ByteString (ByteString)
12−import Data.Text.Encoding as T (encodeUtf8)
13−import Text.Regex.TDFA
14−
1511import Common.Types
12+import Data.Char
13+import qualified Data.Text as T
1614
1715-- | Validates a deployment name.
1816isNameValid :: DeploymentName -> Bool
19−isNameValid (DeploymentName n) =
20− T.encodeUtf8 n =~ ("^[a-z][a-z0-9\\-]{1,16}$" :: ByteString)
17+isNameValid (DeploymentName (T.uncons -> Just (n, nn))) =
18+ let l = T.length nn
19+ in l > 0 && l < 16 && isAsciiLower n && T.all (\c -> c == '-' || isAsciiLower c || isDigit c) nn
20+isNameValid _ = False
octopod-frontend/octopod-frontend.cabal+2
@@ -21,6 +21,8 @@ flag development
2121 description: mock host
2222
2323executable frontend
24+ if impl(ghcjs >= 0.2.1)
25+ ghcjs-options: -dedupe
2426 if flag(development)
2527 cpp-options: -DDEVELOPMENT
2628 main-is: Main.hs
shell.nix+4−1
@@ -2,7 +2,10 @@
22 tools = {
33 cabal = "3.2.0.0";
44 hlint = "latest";
5− haskell-language-server = "latest";
5+ haskell-language-server = {
6+ version = "latest";
7+ index-state = "2021-07-02T00:00:00Z";
8+ };
69 ghcid = "latest";
710 };
811