Skip to content

Commit dfc8c4c

Browse files
committed
init delivery-calculator
1 parent 555ea7b commit dfc8c4c

40 files changed

+8537
-0
lines changed

ghcjs/delivery-calculator/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use nix

ghcjs/delivery-calculator/.ghcid

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--restart=.ghcid
2+
--restart=lightning-verifier.cabal
3+
--restart=cabal.config
4+
--restart=cabal.project
5+
--restart=static
6+
--restart=README.md
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.direnv
2+
result
3+
dist-newstyle
4+
node_modules
5+
dist
6+
android
7+
capacitor-geckoview/capacitor/build

ghcjs/delivery-calculator/.ignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.stack-work
2+
dist-newstyle
3+
capacitor-geckoview
4+
package-lock.json
5+
*\.min\.*

ghcjs/delivery-calculator/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
Copyright (c) 2024 Functora
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21+
OR OTHER DEALINGS IN THE SOFTWARE.
22+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Sample Miso-JSaddle application
2+
3+
4+
It's possible to build miso applications with `ghcid`, `miso` and `jsaddle`. This can enable a faster workflow due to hot reloading of the code.
5+
6+
This application (sample-app-jsaddle) serves as an example of development w/ GHC, and releases with GHCJS.
7+
8+
To take advantage of the hot reload code features, we recommend running the following command (see below) in a shell. (This will invoke `ghcid` for you).
9+
10+
## Dev
11+
```bash
12+
nix-shell --run reload
13+
```
14+
15+
You should now be able to open your browser to `http://localhost:8080` and see your working application. Subsequent edits of the code should cause a live update of the website at that address.
16+
17+
To build the application w/ GHCJS, execute the below command.
18+
19+
## Build w/ GHCJS
20+
```bash
21+
nix-build -A release
22+
```
23+
24+
## Dev with `stack`
25+
26+
In order to build `miso` w/ `jsaddle` support, it is necessary to remove the existing `miso` package first.
27+
28+
```bash
29+
stack exec -- ghc-pkg unregister --force miso
30+
```
31+
32+
Enable the `jsaddle` flag by adding the following to your project's `package.yaml` file, then call `stack build`.
33+
34+
```yaml
35+
flags:
36+
miso:
37+
jsaddle: true
38+
```
39+
40+
## Add external javascript file
41+
42+
First download the external javascript file (`your-file.js`) to your project directory.
43+
Then add `bytestring` to `build-depends` in `app.cabal`.
44+
In your `Main.hs` you need to change the implementation of `runApp` from this:
45+
```
46+
runApp f =
47+
Warp.runSettings (Warp.setPort 8080 (Warp.setTimeout 3600 Warp.defaultSettings)) =<<
48+
JSaddle.jsaddleOr defaultConnectionOptions (f >> syncPoint) JSaddle.jsaddleApp
49+
```
50+
to this:
51+
```
52+
runApp f = do
53+
bString <- B.readFile "your-file.js"
54+
jSaddle <- JSaddle.jsaddleOr defaultConnectionOptions (f >> syncPoint) (JSaddle.jsaddleAppWithJs (B.append (JSaddle.jsaddleJs False) bString))
55+
Warp.runSettings (Warp.setPort 8081 (Warp.setTimeout 3600 Warp.defaultSettings)) jSaddle
56+
```
57+
Now you should be able to use `your-file.js` in jsaddle.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
with (import ./default.nix); let
2+
pkgs = android-pkgs;
3+
repo = toString ./.;
4+
android-sdk =
5+
(pkgs.androidenv.composeAndroidPackages android-sdk-args).androidsdk;
6+
app-keygen-android = pkgs.writeShellApplication {
7+
name = "app-keygen-android";
8+
text = ''
9+
if [ ! -f ~/keys/app-key.jks ]; then
10+
mkdir -p ~/keys
11+
${pkgs.zulu}/bin/keytool -genkey -v \
12+
-keystore ~/keys/app-key.jks \
13+
-keyalg RSA \
14+
-keysize 2048 \
15+
-validity 10000 \
16+
-alias app-key
17+
fi
18+
'';
19+
};
20+
app-sign-apk = pkgs.writeShellApplication {
21+
name = "app-sign-apk";
22+
text = ''
23+
${pkgs.apksigner}/bin/apksigner sign \
24+
--ks ~/keys/app-key.jks \
25+
--out ${repo}/android/app.apk \
26+
${repo}/android/app/build/outputs/apk/release/app-release-unsigned.apk
27+
'';
28+
};
29+
app-sign-aab = pkgs.writeShellApplication {
30+
name = "app-sign-aab";
31+
text = ''
32+
${pkgs.zulu}/bin/jarsigner \
33+
-verbose \
34+
-keystore ~/keys/app-key.jks \
35+
-signedjar ${repo}/android/app.aab \
36+
${repo}/android/app/build/outputs/bundle/release/app-release.aab \
37+
app-key
38+
'';
39+
};
40+
app-prepare-android = pkgs.writeShellApplication rec {
41+
name = "app-prepare-android";
42+
text = ''
43+
(
44+
cd ${repo}
45+
${pkgs.nodejs}/bin/npm i --prefer-offline
46+
${pkgs.nodejs}/bin/npx cap add android || true
47+
${pkgs.nodejs}/bin/npx cap sync
48+
cp ${repo}/static/android-chrome-512x512.png ${repo}/static/logo.png
49+
${pkgs.nodejs}/bin/npx @capacitor/assets generate \
50+
--android --assetPath static
51+
${pkgs.nodejs}/bin/npx trapeze run trapeze.yaml -y \
52+
--android-project android
53+
)
54+
'';
55+
};
56+
app-release-apk = pkgs.writeShellApplication rec {
57+
name = "app-release-apk";
58+
text = ''
59+
(
60+
cd ${repo}
61+
${app-prepare-android}/bin/app-prepare-android
62+
cd ./android
63+
./gradlew assembleRelease
64+
${app-keygen-android}/bin/app-keygen-android
65+
rm ${repo}/android/app.apk || true
66+
rm ${repo}/android/${label}-v${vsn}.apk || true
67+
${app-sign-apk}/bin/app-sign-apk
68+
cp ${repo}/android/app.apk ${repo}/android/${label}-v${vsn}.apk
69+
ls -la ${repo}/android/app.apk
70+
ls -la ${repo}/android/${label}-v${vsn}.apk
71+
)
72+
'';
73+
};
74+
app-release-aab = pkgs.writeShellApplication rec {
75+
name = "app-release-aab";
76+
text = ''
77+
(
78+
cd ${repo}
79+
${app-prepare-android}/bin/app-prepare-android
80+
cd ./android
81+
./gradlew bundleRelease
82+
${app-keygen-android}/bin/app-keygen-android
83+
rm ${repo}/android/app.aab || true
84+
${app-sign-aab}/bin/app-sign-aab
85+
ls -la ${repo}/android/app.aab
86+
)
87+
'';
88+
};
89+
in
90+
pkgs.mkShell rec {
91+
buildInputs = with pkgs; [
92+
alejandra
93+
android-sdk
94+
glibc
95+
jdk
96+
zulu
97+
kotlin
98+
nodejs
99+
app-release-apk
100+
app-release-aab
101+
];
102+
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${android-sdk}/libexec/android-sdk/build-tools/34.0.0/aapt2";
103+
ANDROID_SDK_ROOT = "${android-sdk}/libexec/android-sdk";
104+
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
105+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"appId": "com.functora.app",
3+
"appName": "app",
4+
"webDir": "dist/latest",
5+
"server": {
6+
"androidScheme": "https"
7+
}
8+
}

0 commit comments

Comments
 (0)