Skip to content

Commit 5dccaae

Browse files
committed
cryptogram init
1 parent d71dd09 commit 5dccaae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+11601
-2
lines changed

ghcjs/cryptogram/.envrc

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

ghcjs/cryptogram/.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

ghcjs/cryptogram/.gitignore

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/cryptogram/.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/cryptogram/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+

ghcjs/cryptogram/README.md

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.

ghcjs/cryptogram/android.nix

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 ./lib/Clipboard.java ./node_modules/@capacitor/clipboard/android/src/main/java/com/capacitorjs/plugins/clipboard/Clipboard.java
49+
cp ${repo}/static/android-chrome-512x512.png ${repo}/static/logo.png
50+
${pkgs.nodejs}/bin/npx @capacitor/assets generate \
51+
--android --assetPath static
52+
${pkgs.nodejs}/bin/npx trapeze run trapeze.yaml -y \
53+
--android-project android
54+
)
55+
'';
56+
};
57+
app-release-apk = pkgs.writeShellApplication rec {
58+
name = "app-release-apk";
59+
text = ''
60+
(
61+
cd ${repo}
62+
${app-prepare-android}/bin/app-prepare-android
63+
cd ./android
64+
./gradlew assembleRelease
65+
${app-keygen-android}/bin/app-keygen-android
66+
rm ${repo}/android/app.apk || true
67+
rm ${repo}/android/${label}-v${vsn}.apk || true
68+
${app-sign-apk}/bin/app-sign-apk
69+
cp ${repo}/android/app.apk ${repo}/android/${label}-v${vsn}.apk
70+
ls -la ${repo}/android/app.apk
71+
ls -la ${repo}/android/${label}-v${vsn}.apk
72+
)
73+
'';
74+
};
75+
app-release-aab = pkgs.writeShellApplication rec {
76+
name = "app-release-aab";
77+
text = ''
78+
(
79+
cd ${repo}
80+
${app-prepare-android}/bin/app-prepare-android
81+
cd ./android
82+
./gradlew bundleRelease
83+
${app-keygen-android}/bin/app-keygen-android
84+
rm ${repo}/android/app.aab || true
85+
${app-sign-aab}/bin/app-sign-aab
86+
ls -la ${repo}/android/app.aab
87+
)
88+
'';
89+
};
90+
in
91+
pkgs.mkShell rec {
92+
buildInputs = with pkgs; [
93+
alejandra
94+
android-sdk
95+
glibc
96+
jdk
97+
zulu
98+
kotlin
99+
nodejs
100+
app-release-apk
101+
app-release-aab
102+
];
103+
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${android-sdk}/libexec/android-sdk/build-tools/34.0.0/aapt2";
104+
ANDROID_SDK_ROOT = "${android-sdk}/libexec/android-sdk";
105+
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
106+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"appId": "com.functora.app",
3+
"appName": "app",
4+
"webDir": "dist/latest",
5+
"server": {
6+
"androidScheme": "https"
7+
},
8+
"plugins": {
9+
"Keyboard": {
10+
"resize": "body",
11+
"resizeOnFullScreen": true
12+
}
13+
}
14+
}

ghcjs/cryptogram/cryptogram.cabal

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
cabal-version: 2.2
2+
name: cryptogram
3+
version: 0.1.0.23
4+
synopsis: Cryptogram
5+
category: Web
6+
build-type: Simple
7+
8+
flag ghcid
9+
manual: True
10+
default: False
11+
12+
common pkg
13+
other-modules: Paths_delivery_calculator
14+
autogen-modules: Paths_delivery_calculator
15+
default-language: Haskell2010
16+
hs-source-dirs: src
17+
js-sources: static/app.js
18+
other-modules:
19+
App.I18n
20+
App.Jsm
21+
App.Types
22+
App.Widgets.Asset
23+
App.Widgets.Donate
24+
App.Widgets.GooglePlay
25+
App.Widgets.Main
26+
App.Widgets.MarketLinks
27+
App.Widgets.Menu
28+
App.Widgets.PlaceOrder
29+
App.Widgets.RemoveOrder
30+
App.Widgets.ShareApp
31+
App.Widgets.Templates
32+
App.Xlsx
33+
34+
ghc-options:
35+
-Werror -Weverything -Wno-all-missed-specialisations
36+
-Wno-missed-specialisations -Wno-missing-exported-signatures
37+
-Wno-missing-import-lists -Wno-missing-local-signatures -Wno-safe
38+
-Wno-unsafe -fprint-potential-instances -fwarn-tabs
39+
40+
if impl(ghc >=8.10.7)
41+
ghc-options:
42+
-Wno-prepositive-qualified-module -Wno-missing-safe-haskell-mode
43+
44+
if impl(ghc >8.10.7)
45+
ghc-options: -Wno-missing-kind-signatures
46+
47+
if impl(ghc >=9.8)
48+
ghc-options:
49+
-Wno-missing-role-annotations -Wno-missing-poly-kind-signatures
50+
51+
cpp-options: -Wno-trigraphs
52+
default-extensions:
53+
AllowAmbiguousTypes
54+
ConstraintKinds
55+
DataKinds
56+
DefaultSignatures
57+
DeriveDataTypeable
58+
DeriveFunctor
59+
DeriveGeneric
60+
DeriveLift
61+
DerivingStrategies
62+
DerivingVia
63+
EmptyCase
64+
ExistentialQuantification
65+
FlexibleContexts
66+
FlexibleInstances
67+
FunctionalDependencies
68+
GADTs
69+
GeneralizedNewtypeDeriving
70+
InstanceSigs
71+
KindSignatures
72+
LambdaCase
73+
MultiParamTypeClasses
74+
MultiWayIf
75+
NoImplicitPrelude
76+
NumericUnderscores
77+
OverloadedLabels
78+
OverloadedLists
79+
OverloadedStrings
80+
PackageImports
81+
PolyKinds
82+
QuantifiedConstraints
83+
QuasiQuotes
84+
RankNTypes
85+
ScopedTypeVariables
86+
StandaloneDeriving
87+
StrictData
88+
TupleSections
89+
TypeApplications
90+
TypeFamilies
91+
TypeOperators
92+
93+
build-depends:
94+
, barbies
95+
, base
96+
, base64-bytestring
97+
, bytestring
98+
, containers
99+
, functora-ghcjs
100+
, microlens
101+
, miso
102+
, miso-functora
103+
, modern-uri
104+
, network-uri
105+
, regex-compat
106+
, syb
107+
, time
108+
, xlsx
109+
110+
if flag(ghcid)
111+
build-depends: jsaddle
112+
113+
if os(wasi)
114+
build-depends: jsaddle-wasm
115+
ghc-options:
116+
-no-hs-main -optl-mexec-model=reactor "-optl-Wl,--export=hs_start"
117+
118+
executable cryptogram
119+
import: pkg
120+
main-is: Main.hs
121+
ghcjs-options: -dedupe
122+
build-depends: containers
123+
124+
if ((impl(ghcjs) || arch(javascript)) || os(wasi))
125+
build-depends: jsaddle
126+
127+
else
128+
build-depends:
129+
, jsaddle-warp
130+
, wai
131+
, wai-app-static
132+
, warp
133+
, websockets
134+
135+
if impl(ghcjs)
136+
ghc-options: -Wno-missing-home-modules
137+
cpp-options: -DGHCJS_BROWSER
138+
139+
if !flag(ghcid)
140+
ghc-options: -O2 -optc-O3 -funfolding-use-threshold=16
141+
142+
if (!flag(ghcid) && !os(wasi))
143+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
144+
145+
if flag(ghcid)
146+
cpp-options: -DGHCID
147+
148+
if (flag(ghcid) && impl(ghc >=8.10.7))
149+
ghc-options: -Wno-unused-packages
150+
151+
test-suite cryptogram-test
152+
import: pkg
153+
type: exitcode-stdio-1.0
154+
main-is: Spec.hs
155+
hs-source-dirs: test
156+
other-modules: App.TypesSpec
157+
ghc-options: -Wno-missing-export-lists
158+
build-depends:
159+
, aeson
160+
, hspec
161+
, optics-core
162+
, quickcheck-instances

0 commit comments

Comments
 (0)