nixify, README, license
This commit is contained in:
parent
b929e21f82
commit
0a00070dbb
33 changed files with 62 additions and 2112 deletions
14
LICENSE
Normal file
14
LICENSE
Normal file
|
@ -0,0 +1,14 @@
|
|||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
10
README.md
Normal file
10
README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Elmskell
|
||||
## Build
|
||||
Run `nix build` from the project root.
|
||||
## Configuration
|
||||
There is nothing configurable at this time. Edit source files if you so wish.
|
||||
## Usage
|
||||
Run `./result/bin/elmskell` from the project root. The server opens at port
|
||||
8080.
|
||||
## License
|
||||
See LICENSE for details; this package is licensed under the WTFPL
|
File diff suppressed because one or more lines are too long
|
@ -1,2 +0,0 @@
|
|||
{
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"message0": "Hello World!",
|
||||
"message1": "This is another message. Hello World!"
|
||||
}
|
2
backend/.gitignore
vendored
2
backend/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
.stack-work/
|
||||
*~
|
|
@ -1,11 +0,0 @@
|
|||
# Changelog for `hs-server`
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to the
|
||||
[Haskell Package Versioning Policy](https://pvp.haskell.org/).
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 0.1.0.0 - YYYY-MM-DD
|
|
@ -1,26 +0,0 @@
|
|||
Copyright 2025 Author name here
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,2 +0,0 @@
|
|||
# hs-server
|
||||
this is a custom-built single-purpose server infrastructure based on Scorry, Warp, and Wai. It holds up MTGmonkey's personal website
|
|
@ -1,2 +0,0 @@
|
|||
import Distribution.Simple
|
||||
main = defaultMain
|
|
@ -1,98 +0,0 @@
|
|||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE DerivingStrategies #-}
|
||||
{-# LANGUAGE DerivingVia #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
|
||||
module ElmskellTypes (generateElmskellTypes) where
|
||||
|
||||
import Data.Aeson (ToJSON (..), FromJSON (..))
|
||||
import Elm
|
||||
import GHC.Generics
|
||||
|
||||
data Command
|
||||
= ClearCommand
|
||||
| ColorsCommand
|
||||
| CookiesCommand
|
||||
| DebugCommand
|
||||
| FontCommand
|
||||
| HelloCommand
|
||||
| HelpCommand
|
||||
| PromptCommand
|
||||
| ThemeCommand
|
||||
| TodoCommand
|
||||
deriving (Generic)
|
||||
deriving (Elm, ToJSON, FromJSON) via ElmStreet Command
|
||||
|
||||
data CookiesKept = CookiesKept
|
||||
{ cookiesKeptKeepFont :: Bool
|
||||
, cookiesKeptKeepPrompt :: Bool
|
||||
, cookiesKeptKeepTheme :: Bool
|
||||
} deriving (Generic)
|
||||
deriving (Elm, ToJSON, FromJSON) via ElmStreet CookiesKept
|
||||
|
||||
data CoreColor
|
||||
= Red
|
||||
| Green
|
||||
| Yellow
|
||||
| Blue
|
||||
| Magenta
|
||||
| Cyan
|
||||
| BrightRed
|
||||
| BrightGreen
|
||||
| BrightYellow
|
||||
| BrightBlue
|
||||
| BrightMagenta
|
||||
| BrightCyan
|
||||
deriving (Generic)
|
||||
deriving (Elm, ToJSON, FromJSON) via ElmStreet CoreColor
|
||||
|
||||
data Font = Font
|
||||
{ fontFontSize :: Float
|
||||
} deriving (Generic)
|
||||
deriving (Elm, ToJSON, FromJSON) via ElmStreet Font
|
||||
|
||||
data Input = Input
|
||||
{ inputCommand :: Command
|
||||
, inputArgs :: [String]
|
||||
}
|
||||
deriving (Generic)
|
||||
deriving (Elm, ToJSON, FromJSON) via ElmStreet Input
|
||||
|
||||
data Prompt = Prompt
|
||||
{ promptPrompt :: String
|
||||
} deriving (Generic)
|
||||
deriving (Elm, ToJSON, FromJSON) via ElmStreet Prompt
|
||||
|
||||
data Theme
|
||||
= Pit
|
||||
| Dim
|
||||
| Sky
|
||||
| Sun
|
||||
deriving (Generic)
|
||||
deriving (Elm, ToJSON, FromJSON) via ElmStreet Theme
|
||||
|
||||
data ThemeColor
|
||||
= Background
|
||||
| Foreground
|
||||
| Cursor
|
||||
| Black
|
||||
| White
|
||||
| BrightBlack
|
||||
| BrightWhite
|
||||
deriving (Generic)
|
||||
deriving (Elm, ToJSON, FromJSON) via ElmStreet ThemeColor
|
||||
|
||||
type Types =
|
||||
'[Command
|
||||
, CookiesKept
|
||||
, CoreColor
|
||||
, Font
|
||||
, Input
|
||||
, Prompt
|
||||
, Theme
|
||||
, ThemeColor
|
||||
]
|
||||
|
||||
generateElmskellTypes :: IO ()
|
||||
generateElmskellTypes = generateElm @Types $ defaultSettings "frontend/src" ["ElmskellTypes", "Generated"]
|
|
@ -1,108 +0,0 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Main (main) where
|
||||
|
||||
import ElmskellTypes
|
||||
import Data.Text.Lazy (Text)
|
||||
import Network.Wai.Handler.Warp (Port)
|
||||
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
|
||||
import Text.Blaze ((!))
|
||||
import Text.Blaze.Html.Renderer.Text (renderHtml)
|
||||
|
||||
import Network.HTTP.Types
|
||||
import Network.Wai.Middleware.Gzip
|
||||
import Web.Scotty as S
|
||||
|
||||
import qualified Control.Exception as E
|
||||
import qualified Text.Blaze.Html5 as H
|
||||
import qualified Text.Blaze.Html5.Attributes as A
|
||||
|
||||
-- HTML
|
||||
index :: H.Html -> Text
|
||||
index compiledElmApp = renderHtml $ do
|
||||
H.docTypeHtml $ do
|
||||
H.head $ do
|
||||
H.title "TESTING Scotty+Elm"
|
||||
H.meta ! A.charset "utf-8"
|
||||
H.style "body{margin:0px;}"
|
||||
(H.body ! A.id "body") $ do
|
||||
embedJs compiledElmApp
|
||||
|
||||
-- CONF
|
||||
port :: Port
|
||||
port = 8080
|
||||
|
||||
adminContact :: String
|
||||
adminContact = "[Matrix] @mtgmonkey:calitabby.net"
|
||||
|
||||
compiledElmAppFile :: AssetPath
|
||||
compiledElmAppFile = "/js/main.js"
|
||||
|
||||
boilerplateJsFile :: AssetPath
|
||||
boilerplateJsFile = "/js/init.js"
|
||||
|
||||
assetsFolder :: FilePath
|
||||
assetsFolder = "/home/mtgmonkey/elmskell/assets"
|
||||
|
||||
-- MAIN
|
||||
main :: IO ()
|
||||
main = do
|
||||
|
||||
generateElmskellTypes
|
||||
|
||||
compiledElmAppOrExc <- E.try $ readFile $ assetsFolder ++ compiledElmAppFile :: IO (Either E.IOException String)
|
||||
let compiledElmApp = case compiledElmAppOrExc of
|
||||
Left e -> serverErrorReadFile e
|
||||
Right contents -> H.toHtml $ contents
|
||||
|
||||
boilerplateJsOrExc <- E.try $ readFile $ assetsFolder ++ boilerplateJsFile :: IO (Either E.IOException String)
|
||||
let boilerplateJs = case boilerplateJsOrExc of
|
||||
Left e -> serverErrorReadFile e
|
||||
Right contents -> H.toHtml $ contents
|
||||
|
||||
let anyRoute = regex "^.*$"
|
||||
scotty port $ do
|
||||
|
||||
middleware $ gzip $ def { gzipFiles = GzipCompress }
|
||||
middleware logStdoutDev
|
||||
|
||||
-- GET requests
|
||||
get "/" $ do
|
||||
shortCache
|
||||
status ok200
|
||||
S.html $ index $ do
|
||||
compiledElmApp
|
||||
boilerplateJs
|
||||
|
||||
get "/favicon.ico/" $ do
|
||||
shortCache
|
||||
status notFound404
|
||||
S.html $ "you want a favi-<i>what</i>now!?"
|
||||
|
||||
-- ERR
|
||||
notFound $ do
|
||||
noCache
|
||||
status methodNotAllowed405
|
||||
S.text "Verb disallowed; OR, route doesn't exist :("
|
||||
|
||||
|
||||
-- FUNC
|
||||
serverErrorReadFile :: E.IOException -> Js
|
||||
serverErrorReadFile e = H.toHtml $ "document.getElementById('body').innerHTML='Server-side error occurred: "
|
||||
++ (show e)
|
||||
++ "; report this to a site administrator: "
|
||||
++ adminContact
|
||||
++ "';"
|
||||
|
||||
shortCache :: ActionM ()
|
||||
shortCache = addHeader "Cache-Control" "max-age=21600"
|
||||
|
||||
noCache :: ActionM ()
|
||||
noCache = addHeader "Cache-Control" "no-cache"
|
||||
|
||||
embedJs :: Js -> H.Html
|
||||
embedJs js = H.script $ js
|
||||
|
||||
-- TYPES
|
||||
type AssetPath = FilePath
|
||||
type Js = H.Html
|
|
@ -1,91 +0,0 @@
|
|||
cabal-version: 2.2
|
||||
|
||||
-- This file has been generated from package.yaml by hpack version 0.37.0.
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
|
||||
name: hs-server
|
||||
version: 0.1.0.0
|
||||
description: Please see README.md
|
||||
author: mtgmonkey
|
||||
maintainer: mtgmonkey
|
||||
copyright: 2025 mtgmonkey
|
||||
license: BSD-3-Clause
|
||||
license-file: LICENSE
|
||||
build-type: Simple
|
||||
extra-source-files:
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
|
||||
library
|
||||
exposed-modules:
|
||||
ElmskellTypes
|
||||
other-modules:
|
||||
Paths_hs_server
|
||||
autogen-modules:
|
||||
Paths_hs_server
|
||||
hs-source-dirs:
|
||||
src
|
||||
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
|
||||
build-depends:
|
||||
aeson >=2.2.3 && <2.3
|
||||
, base >=4.19.2 && <4.20
|
||||
, blaze-html >=0.9.2 && <0.10
|
||||
, blaze-markup >=0.8.3 && <0.9
|
||||
, directory >=1.3.8 && <1.4
|
||||
, elm-street >=0.2.2 && <0.3
|
||||
, http-types >=0.12.4 && <0.13
|
||||
, scotty ==0.22.*
|
||||
, text >=2.1.1 && <2.2
|
||||
, wai-extra >=3.1.16 && <3.2
|
||||
, warp >=3.4.7 && <3.5
|
||||
default-language: Haskell2010
|
||||
|
||||
executable hs-server-exe
|
||||
main-is: Main.hs
|
||||
other-modules:
|
||||
Paths_hs_server
|
||||
autogen-modules:
|
||||
Paths_hs_server
|
||||
hs-source-dirs:
|
||||
app
|
||||
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
|
||||
build-depends:
|
||||
aeson >=2.2.3 && <2.3
|
||||
, base >=4.19.2 && <4.20
|
||||
, blaze-html >=0.9.2 && <0.10
|
||||
, blaze-markup >=0.8.3 && <0.9
|
||||
, directory >=1.3.8 && <1.4
|
||||
, elm-street >=0.2.2 && <0.3
|
||||
, hs-server
|
||||
, http-types >=0.12.4 && <0.13
|
||||
, scotty ==0.22.*
|
||||
, text >=2.1.1 && <2.2
|
||||
, wai-extra >=3.1.16 && <3.2
|
||||
, warp >=3.4.7 && <3.5
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite hs-server-test
|
||||
type: exitcode-stdio-1.0
|
||||
main-is: Spec.hs
|
||||
other-modules:
|
||||
Paths_hs_server
|
||||
autogen-modules:
|
||||
Paths_hs_server
|
||||
hs-source-dirs:
|
||||
test
|
||||
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
|
||||
build-depends:
|
||||
aeson >=2.2.3 && <2.3
|
||||
, base >=4.19.2 && <4.20
|
||||
, blaze-html >=0.9.2 && <0.10
|
||||
, blaze-markup >=0.8.3 && <0.9
|
||||
, directory >=1.3.8 && <1.4
|
||||
, elm-street >=0.2.2 && <0.3
|
||||
, hs-server
|
||||
, http-types >=0.12.4 && <0.13
|
||||
, scotty ==0.22.*
|
||||
, text >=2.1.1 && <2.2
|
||||
, wai-extra >=3.1.16 && <3.2
|
||||
, warp >=3.4.7 && <3.5
|
||||
default-language: Haskell2010
|
|
@ -1,68 +0,0 @@
|
|||
name: hs-server
|
||||
version: 0.1.0.0
|
||||
license: BSD-3-Clause
|
||||
author: "mtgmonkey"
|
||||
maintainer: "mtgmonkey"
|
||||
copyright: "2025 mtgmonkey"
|
||||
|
||||
extra-source-files:
|
||||
- README.md
|
||||
- CHANGELOG.md
|
||||
|
||||
# Metadata used when publishing your package
|
||||
# synopsis: Short description of your package
|
||||
# category: Web
|
||||
|
||||
# To avoid duplicated efforts in documentation and dealing with the
|
||||
# complications of embedding Haddock markup inside cabal files, it is
|
||||
# common to point users to the README.md file.
|
||||
description: Please see README.md
|
||||
|
||||
dependencies:
|
||||
- aeson >= 2.2.3 && < 2.3
|
||||
- base >= 4.19.2 && < 4.20
|
||||
- blaze-html >= 0.9.2 && < 0.10
|
||||
- blaze-markup >= 0.8.3 && < 0.9
|
||||
- directory >= 1.3.8 && < 1.4
|
||||
- elm-street >= 0.2.2 && < 0.3
|
||||
- http-types >= 0.12.4 && < 0.13
|
||||
- scotty >= 0.22 && < 0.23
|
||||
- text >= 2.1.1 && < 2.2
|
||||
- wai-extra >= 3.1.16 && < 3.2
|
||||
- warp >= 3.4.7 && < 3.5
|
||||
|
||||
ghc-options:
|
||||
- -Wall
|
||||
- -Wcompat
|
||||
- -Widentities
|
||||
- -Wincomplete-record-updates
|
||||
- -Wincomplete-uni-patterns
|
||||
- -Wmissing-export-lists
|
||||
- -Wmissing-home-modules
|
||||
- -Wpartial-fields
|
||||
- -Wredundant-constraints
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
|
||||
executables:
|
||||
hs-server-exe:
|
||||
main: Main.hs
|
||||
source-dirs: app
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- hs-server
|
||||
|
||||
tests:
|
||||
hs-server-test:
|
||||
main: Spec.hs
|
||||
source-dirs: test
|
||||
ghc-options:
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- hs-server
|
|
@ -1,74 +0,0 @@
|
|||
# This file was automatically generated by 'stack init'
|
||||
#
|
||||
# Some commonly used options have been documented as comments in this file.
|
||||
# For advanced use and comprehensive documentation of the format, please see:
|
||||
# https://docs.haskellstack.org/en/stable/yaml_configuration/
|
||||
|
||||
# A 'specific' Stackage snapshot or a compiler version.
|
||||
# A snapshot resolver dictates the compiler version and the set of packages
|
||||
# to be used for project dependencies. For example:
|
||||
#
|
||||
# snapshot: lts-22.28
|
||||
# snapshot: nightly-2024-07-05
|
||||
# snapshot: ghc-9.6.6
|
||||
#
|
||||
# The location of a snapshot can be provided as a file or url. Stack assumes
|
||||
# a snapshot provided as a file might change, whereas a url resource does not.
|
||||
#
|
||||
# snapshot: ./custom-snapshot.yaml
|
||||
# snapshot: https://example.com/snapshots/2024-01-01.yaml
|
||||
snapshot:
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/19.yaml
|
||||
|
||||
# User packages to be built.
|
||||
# Various formats can be used as shown in the example below.
|
||||
#
|
||||
# packages:
|
||||
# - some-directory
|
||||
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
|
||||
# subdirs:
|
||||
# - auto-update
|
||||
# - wai
|
||||
#
|
||||
# packages is represented in package.yaml
|
||||
packages:
|
||||
- .
|
||||
|
||||
nix:
|
||||
enable: true
|
||||
packages: [zlib]
|
||||
|
||||
# Dependency packages to be pulled from upstream that are not in the snapshot.
|
||||
# These entries can reference officially published versions as well as
|
||||
# forks / in-progress versions pinned to a git hash. For example:
|
||||
#
|
||||
# extra-deps:
|
||||
# - acme-missiles-0.3
|
||||
# - git: https://github.com/commercialhaskell/stack.git
|
||||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||
#
|
||||
# extra-deps: []
|
||||
|
||||
# Override default flag values for project packages and extra-deps
|
||||
# flags: {}
|
||||
|
||||
# Extra package databases containing global packages
|
||||
# extra-package-dbs: []
|
||||
|
||||
# Control whether we use the GHC we find on the path
|
||||
# system-ghc: true
|
||||
#
|
||||
# Require a specific version of Stack, using version ranges
|
||||
# require-stack-version: -any # Default
|
||||
# require-stack-version: ">=3.1"
|
||||
#
|
||||
# Override the architecture used by Stack, especially useful on Windows
|
||||
# arch: i386
|
||||
# arch: x86_64
|
||||
#
|
||||
# Extra directories used by Stack for building
|
||||
# extra-include-dirs: [/path/to/dir]
|
||||
# extra-lib-dirs: [/path/to/dir]
|
||||
#
|
||||
# Allow a newer minor version of GHC than the snapshot specifies
|
||||
# compiler-check: newer-minor
|
|
@ -1,13 +0,0 @@
|
|||
# This file was autogenerated by Stack.
|
||||
# You should not edit this file by hand.
|
||||
# For more information, please see the documentation at:
|
||||
# https://docs.haskellstack.org/en/stable/lock_files
|
||||
|
||||
packages: []
|
||||
snapshots:
|
||||
- completed:
|
||||
sha256: 296a7960c37efa382432ab497161a092684191815eb92a608c5d6ea5f894ace3
|
||||
size: 683835
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/19.yaml
|
||||
original:
|
||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/19.yaml
|
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
esbuild,
|
||||
stdenv,
|
||||
elmPackages,
|
||||
...
|
||||
}: let
|
||||
elmConfig = elmPackages.fetchElmDeps {
|
||||
elmPackages = import ./frontend/elm-srcs.nix;
|
||||
elmVersion = "0.19.1";
|
||||
registryDat = ./frontend/registry.dat;
|
||||
};
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "elmskell-backend";
|
||||
version = "0.1.0";
|
||||
src = ./frontend;
|
||||
nativeBuildInputs = [
|
||||
esbuild
|
||||
elmPackages.elm
|
||||
];
|
||||
buildInputs = [
|
||||
];
|
||||
configurePhase = ''
|
||||
${elmConfig}
|
||||
'';
|
||||
buildPhase = ''
|
||||
elm make src/Main.elm --optimize --output=tmp.js
|
||||
esbuild tmp.js --minify --target=es5 --outfile=main.js
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
cp main.js $out/main.js
|
||||
'';
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"NoRedInk/elm-json-decode-pipeline": "1.0.1",
|
||||
"bartavelle/json-helpers": "2.0.2",
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"lobanov/elm-localstorage": "1.0.1",
|
||||
"rtfeldman/elm-css": "18.0.0",
|
||||
"rtfeldman/elm-iso8601-date-strings": "1.1.4"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/bytes": "1.0.8",
|
||||
"elm/file": "1.0.5",
|
||||
"elm/http": "2.0.0",
|
||||
"elm/parser": "1.1.0",
|
||||
"elm/random": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.3",
|
||||
"lobanov/elm-taskport": "2.0.1",
|
||||
"robinheghan/murmur3": "1.0.0",
|
||||
"rtfeldman/elm-hex": "1.0.0"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
{pkgs ? import <nixpkgs> {}}:
|
||||
pkgs.mkShell {
|
||||
nativeBuildInputs = [
|
||||
pkgs.elmPackages.elm
|
||||
pkgs.elmPackages.elm-format
|
||||
pkgs.uglify-js
|
||||
pkgs.ungoogled-chromium
|
||||
];
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
module ElmskellTypes.Generated.Decoder exposing (..)
|
||||
|
||||
import Iso8601 as Iso
|
||||
import Json.Decode as D exposing (..)
|
||||
import Json.Decode.Pipeline as D exposing (required)
|
||||
|
||||
import ElmskellTypes.Generated.ElmStreet exposing (..)
|
||||
import ElmskellTypes.Generated.Types as T
|
||||
|
||||
|
||||
decodeCommand : Decoder T.Command
|
||||
decodeCommand = elmStreetDecodeEnum T.readCommand
|
||||
|
||||
decodeCookiesKept : Decoder T.CookiesKept
|
||||
decodeCookiesKept = D.succeed T.CookiesKept
|
||||
|> required "keepFont" D.bool
|
||||
|> required "keepPrompt" D.bool
|
||||
|> required "keepTheme" D.bool
|
||||
|
||||
decodeCoreColor : Decoder T.CoreColor
|
||||
decodeCoreColor = elmStreetDecodeEnum T.readCoreColor
|
||||
|
||||
decodeFont : Decoder T.Font
|
||||
decodeFont = D.succeed T.Font
|
||||
|> required "fontSize" D.float
|
||||
|
||||
decodeInput : Decoder T.Input
|
||||
decodeInput = D.succeed T.Input
|
||||
|> required "command" decodeCommand
|
||||
|> required "args" (D.list D.string)
|
||||
|
||||
decodePrompt : Decoder T.Prompt
|
||||
decodePrompt = D.succeed T.Prompt
|
||||
|> required "prompt" D.string
|
||||
|
||||
decodeTheme : Decoder T.Theme
|
||||
decodeTheme = elmStreetDecodeEnum T.readTheme
|
||||
|
||||
decodeThemeColor : Decoder T.ThemeColor
|
||||
decodeThemeColor = elmStreetDecodeEnum T.readThemeColor
|
|
@ -1,52 +0,0 @@
|
|||
module ElmskellTypes.Generated.ElmStreet exposing (..)
|
||||
|
||||
import Json.Encode as E exposing (Value)
|
||||
import Json.Decode as D exposing (Decoder)
|
||||
import Json.Decode.Pipeline as D exposing (..)
|
||||
|
||||
|
||||
elmStreetEncodeMaybe : (a -> Value) -> Maybe a -> Value
|
||||
elmStreetEncodeMaybe enc = Maybe.withDefault E.null << Maybe.map enc
|
||||
|
||||
elmStreetEncodeEither : (a -> Value) -> (b -> Value) -> Result a b -> Value
|
||||
elmStreetEncodeEither encA encB res = E.object <| case res of
|
||||
Err a -> [("Left", encA a)]
|
||||
Ok b -> [("Right", encB b)]
|
||||
|
||||
elmStreetEncodePair : (a -> Value) -> (b -> Value) -> (a, b) -> Value
|
||||
elmStreetEncodePair encA encB (a, b) = E.list identity [encA a, encB b]
|
||||
|
||||
elmStreetEncodeTriple : (a -> Value) -> (b -> Value) -> (c -> Value) -> (a, b, c) -> Value
|
||||
elmStreetEncodeTriple encA encB encC (a, b, c) = E.list identity [encA a, encB b, encC c]
|
||||
|
||||
elmStreetEncodeNonEmpty : (a -> Value) -> (a, List a) -> Value
|
||||
elmStreetEncodeNonEmpty encA (a, xs) = E.list encA <| a :: xs
|
||||
|
||||
decodeStr : (String -> Maybe a) -> String -> Decoder a
|
||||
decodeStr readX x = case readX x of
|
||||
Just a -> D.succeed a
|
||||
Nothing -> D.fail "Constructor not matched"
|
||||
|
||||
elmStreetDecodeEnum : (String -> Maybe a) -> Decoder a
|
||||
elmStreetDecodeEnum r = D.andThen (decodeStr r) D.string
|
||||
|
||||
elmStreetDecodeChar : Decoder Char
|
||||
elmStreetDecodeChar = D.andThen (decodeStr (Maybe.map Tuple.first << String.uncons)) D.string
|
||||
|
||||
elmStreetDecodeEither : Decoder a -> Decoder b -> Decoder (Result a b)
|
||||
elmStreetDecodeEither decA decB = D.oneOf
|
||||
[ D.field "Left" (D.map Err decA)
|
||||
, D.field "Right" (D.map Ok decB)
|
||||
]
|
||||
|
||||
elmStreetDecodePair : Decoder a -> Decoder b -> Decoder (a, b)
|
||||
elmStreetDecodePair decA decB = D.map2 Tuple.pair (D.index 0 decA) (D.index 1 decB)
|
||||
|
||||
elmStreetDecodeTriple : Decoder a -> Decoder b -> Decoder c -> Decoder (a, b, c)
|
||||
elmStreetDecodeTriple decA decB decC = D.map3 (\a b c -> (a,b,c)) (D.index 0 decA) (D.index 1 decB) (D.index 2 decC)
|
||||
|
||||
elmStreetDecodeNonEmpty : Decoder a -> Decoder (a, List a)
|
||||
elmStreetDecodeNonEmpty decA = D.list decA |> D.andThen (\xs -> case xs of
|
||||
h::t -> D.succeed (h, t)
|
||||
_ -> D.fail "Expecting non-empty array")
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
module ElmskellTypes.Generated.Encoder exposing (..)
|
||||
|
||||
import Iso8601 as Iso
|
||||
import Json.Encode as E exposing (..)
|
||||
|
||||
import ElmskellTypes.Generated.ElmStreet exposing (..)
|
||||
import ElmskellTypes.Generated.Types as T
|
||||
|
||||
|
||||
encodeCommand : T.Command -> Value
|
||||
encodeCommand = E.string << T.showCommand
|
||||
|
||||
encodeCookiesKept : T.CookiesKept -> Value
|
||||
encodeCookiesKept x = E.object
|
||||
[ ("tag", E.string "CookiesKept")
|
||||
, ("keepFont", E.bool x.keepFont)
|
||||
, ("keepPrompt", E.bool x.keepPrompt)
|
||||
, ("keepTheme", E.bool x.keepTheme)
|
||||
]
|
||||
|
||||
encodeCoreColor : T.CoreColor -> Value
|
||||
encodeCoreColor = E.string << T.showCoreColor
|
||||
|
||||
encodeFont : T.Font -> Value
|
||||
encodeFont x = E.object
|
||||
[ ("tag", E.string "Font")
|
||||
, ("fontSize", E.float x.fontSize)
|
||||
]
|
||||
|
||||
encodeInput : T.Input -> Value
|
||||
encodeInput x = E.object
|
||||
[ ("tag", E.string "Input")
|
||||
, ("command", encodeCommand x.command)
|
||||
, ("args", (E.list E.string) x.args)
|
||||
]
|
||||
|
||||
encodePrompt : T.Prompt -> Value
|
||||
encodePrompt x = E.object
|
||||
[ ("tag", E.string "Prompt")
|
||||
, ("prompt", E.string x.prompt)
|
||||
]
|
||||
|
||||
encodeTheme : T.Theme -> Value
|
||||
encodeTheme = E.string << T.showTheme
|
||||
|
||||
encodeThemeColor : T.ThemeColor -> Value
|
||||
encodeThemeColor = E.string << T.showThemeColor
|
|
@ -1,197 +0,0 @@
|
|||
module ElmskellTypes.Generated.Types exposing (..)
|
||||
|
||||
import Time exposing (Posix)
|
||||
import Json.Decode exposing (Value)
|
||||
|
||||
|
||||
type Command
|
||||
= ClearCommand
|
||||
| ColorsCommand
|
||||
| CookiesCommand
|
||||
| DebugCommand
|
||||
| FontCommand
|
||||
| HelloCommand
|
||||
| HelpCommand
|
||||
| PromptCommand
|
||||
| ThemeCommand
|
||||
| TodoCommand
|
||||
|
||||
showCommand : Command -> String
|
||||
showCommand x = case x of
|
||||
ClearCommand -> "ClearCommand"
|
||||
ColorsCommand -> "ColorsCommand"
|
||||
CookiesCommand -> "CookiesCommand"
|
||||
DebugCommand -> "DebugCommand"
|
||||
FontCommand -> "FontCommand"
|
||||
HelloCommand -> "HelloCommand"
|
||||
HelpCommand -> "HelpCommand"
|
||||
PromptCommand -> "PromptCommand"
|
||||
ThemeCommand -> "ThemeCommand"
|
||||
TodoCommand -> "TodoCommand"
|
||||
|
||||
readCommand : String -> Maybe Command
|
||||
readCommand x = case x of
|
||||
"ClearCommand" -> Just ClearCommand
|
||||
"ColorsCommand" -> Just ColorsCommand
|
||||
"CookiesCommand" -> Just CookiesCommand
|
||||
"DebugCommand" -> Just DebugCommand
|
||||
"FontCommand" -> Just FontCommand
|
||||
"HelloCommand" -> Just HelloCommand
|
||||
"HelpCommand" -> Just HelpCommand
|
||||
"PromptCommand" -> Just PromptCommand
|
||||
"ThemeCommand" -> Just ThemeCommand
|
||||
"TodoCommand" -> Just TodoCommand
|
||||
_ -> Nothing
|
||||
|
||||
universeCommand : List Command
|
||||
universeCommand = [ ClearCommand
|
||||
, ColorsCommand
|
||||
, CookiesCommand
|
||||
, DebugCommand
|
||||
, FontCommand
|
||||
, HelloCommand
|
||||
, HelpCommand
|
||||
, PromptCommand
|
||||
, ThemeCommand
|
||||
, TodoCommand ]
|
||||
|
||||
type alias CookiesKept =
|
||||
{ keepFont : Bool
|
||||
, keepPrompt : Bool
|
||||
, keepTheme : Bool
|
||||
}
|
||||
|
||||
type CoreColor
|
||||
= Red
|
||||
| Green
|
||||
| Yellow
|
||||
| Blue
|
||||
| Magenta
|
||||
| Cyan
|
||||
| BrightRed
|
||||
| BrightGreen
|
||||
| BrightYellow
|
||||
| BrightBlue
|
||||
| BrightMagenta
|
||||
| BrightCyan
|
||||
|
||||
showCoreColor : CoreColor -> String
|
||||
showCoreColor x = case x of
|
||||
Red -> "Red"
|
||||
Green -> "Green"
|
||||
Yellow -> "Yellow"
|
||||
Blue -> "Blue"
|
||||
Magenta -> "Magenta"
|
||||
Cyan -> "Cyan"
|
||||
BrightRed -> "BrightRed"
|
||||
BrightGreen -> "BrightGreen"
|
||||
BrightYellow -> "BrightYellow"
|
||||
BrightBlue -> "BrightBlue"
|
||||
BrightMagenta -> "BrightMagenta"
|
||||
BrightCyan -> "BrightCyan"
|
||||
|
||||
readCoreColor : String -> Maybe CoreColor
|
||||
readCoreColor x = case x of
|
||||
"Red" -> Just Red
|
||||
"Green" -> Just Green
|
||||
"Yellow" -> Just Yellow
|
||||
"Blue" -> Just Blue
|
||||
"Magenta" -> Just Magenta
|
||||
"Cyan" -> Just Cyan
|
||||
"BrightRed" -> Just BrightRed
|
||||
"BrightGreen" -> Just BrightGreen
|
||||
"BrightYellow" -> Just BrightYellow
|
||||
"BrightBlue" -> Just BrightBlue
|
||||
"BrightMagenta" -> Just BrightMagenta
|
||||
"BrightCyan" -> Just BrightCyan
|
||||
_ -> Nothing
|
||||
|
||||
universeCoreColor : List CoreColor
|
||||
universeCoreColor = [ Red
|
||||
, Green
|
||||
, Yellow
|
||||
, Blue
|
||||
, Magenta
|
||||
, Cyan
|
||||
, BrightRed
|
||||
, BrightGreen
|
||||
, BrightYellow
|
||||
, BrightBlue
|
||||
, BrightMagenta
|
||||
, BrightCyan ]
|
||||
|
||||
type alias Font =
|
||||
{ fontSize : Float
|
||||
}
|
||||
|
||||
type alias Input =
|
||||
{ command : Command
|
||||
, args : List String
|
||||
}
|
||||
|
||||
type alias Prompt =
|
||||
{ prompt : String
|
||||
}
|
||||
|
||||
type Theme
|
||||
= Pit
|
||||
| Dim
|
||||
| Sky
|
||||
| Sun
|
||||
|
||||
showTheme : Theme -> String
|
||||
showTheme x = case x of
|
||||
Pit -> "Pit"
|
||||
Dim -> "Dim"
|
||||
Sky -> "Sky"
|
||||
Sun -> "Sun"
|
||||
|
||||
readTheme : String -> Maybe Theme
|
||||
readTheme x = case x of
|
||||
"Pit" -> Just Pit
|
||||
"Dim" -> Just Dim
|
||||
"Sky" -> Just Sky
|
||||
"Sun" -> Just Sun
|
||||
_ -> Nothing
|
||||
|
||||
universeTheme : List Theme
|
||||
universeTheme = [Pit, Dim, Sky, Sun]
|
||||
|
||||
type ThemeColor
|
||||
= Background
|
||||
| Foreground
|
||||
| Cursor
|
||||
| Black
|
||||
| White
|
||||
| BrightBlack
|
||||
| BrightWhite
|
||||
|
||||
showThemeColor : ThemeColor -> String
|
||||
showThemeColor x = case x of
|
||||
Background -> "Background"
|
||||
Foreground -> "Foreground"
|
||||
Cursor -> "Cursor"
|
||||
Black -> "Black"
|
||||
White -> "White"
|
||||
BrightBlack -> "BrightBlack"
|
||||
BrightWhite -> "BrightWhite"
|
||||
|
||||
readThemeColor : String -> Maybe ThemeColor
|
||||
readThemeColor x = case x of
|
||||
"Background" -> Just Background
|
||||
"Foreground" -> Just Foreground
|
||||
"Cursor" -> Just Cursor
|
||||
"Black" -> Just Black
|
||||
"White" -> Just White
|
||||
"BrightBlack" -> Just BrightBlack
|
||||
"BrightWhite" -> Just BrightWhite
|
||||
_ -> Nothing
|
||||
|
||||
universeThemeColor : List ThemeColor
|
||||
universeThemeColor = [ Background
|
||||
, Foreground
|
||||
, Cursor
|
||||
, Black
|
||||
, White
|
||||
, BrightBlack
|
||||
, BrightWhite ]
|
File diff suppressed because it is too large
Load diff
26
package.nix
26
package.nix
|
@ -2,10 +2,11 @@
|
|||
esbuild,
|
||||
elmPackages,
|
||||
haskellPackages,
|
||||
lib,
|
||||
stdenv,
|
||||
...
|
||||
}: let
|
||||
ghcExeOptions = "-Wall -Wcompact -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N";
|
||||
ghcExeOptions = "-Wall -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N";
|
||||
ghcPackages = p: [
|
||||
p.aeson
|
||||
p.blaze-html
|
||||
|
@ -19,9 +20,9 @@
|
|||
p.warp
|
||||
];
|
||||
elmConfig = elmPackages.fetchElmDeps {
|
||||
elmPackages = import ./frontend/elm-srcs.nix;
|
||||
elmPackages = import ./src/elm2nix/elm-srcs.nix;
|
||||
elmVersion = "0.19.1";
|
||||
registryDat = ./frontend/registry.dat;
|
||||
registryDat = ./src/elm2nix/registry.dat;
|
||||
};
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
|
@ -39,15 +40,26 @@ in
|
|||
${elmConfig}
|
||||
'';
|
||||
buildPhase = ''
|
||||
ghc -v ${ghcExeOptions} ./Main.hs -o ./main
|
||||
ghc ${ghcExeOptions} ./ElmskellTypes.hs -o ./generateElmskellTypes
|
||||
./generateElmskellTypes
|
||||
elm make ./Main.elm --optimize --output=tmp.js
|
||||
esbuild ./tmp.js --minify --target=es5 --outfile=main.js
|
||||
ghc ${ghcExeOptions} ./Main.hs -o ./main
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
mkdir -p $out/src
|
||||
cp ./main $out/bin/elmskell
|
||||
cp ./main.js $out/src/main.js
|
||||
cp ./init.js $out/src/init.js
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "Fully functional website template";
|
||||
longDescription = ''
|
||||
Elmskell is the hobby website of MTGmonkey. A running example is hosted at
|
||||
mtgmonkey.net.
|
||||
'';
|
||||
homepage = "https://mtgmonkey.net";
|
||||
license = lib.licenses.wtfpl;
|
||||
mainProgram = "elmskell";
|
||||
platforms = ["x86_64-linux"];
|
||||
};
|
||||
}
|
||||
|
|
1
result
1
result
|
@ -1 +0,0 @@
|
|||
/nix/store/afnd25aqbkrr55z46pld1yg1fdnv893w-elmskell-0.1.0
|
|
@ -4,7 +4,7 @@
|
|||
{-# LANGUAGE DerivingVia #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
|
||||
module ElmskellTypes (generateElmskellTypes) where
|
||||
module Main (main) where
|
||||
|
||||
import Data.Aeson (ToJSON (..), FromJSON (..))
|
||||
import Elm
|
||||
|
@ -94,5 +94,5 @@ type Types =
|
|||
, ThemeColor
|
||||
]
|
||||
|
||||
generateElmskellTypes :: IO ()
|
||||
generateElmskellTypes = generateElm @Types $ defaultSettings "frontend/src" ["ElmskellTypes", "Generated"]
|
||||
main :: IO ()
|
||||
main = generateElm @Types $ defaultSettings "." ["ElmskellTypes", "Generated"]
|
||||
|
|
|
@ -558,7 +558,7 @@ runHello : CommandRunner
|
|||
runHello model args =
|
||||
case List.head args of
|
||||
Nothing ->
|
||||
( { model | content = model.content ++ [ text "\nHello World!" ] }, Cmd.none )
|
||||
( { model | content = model.content ++ [ text "\nHello World! My test worked!!!" ] }, Cmd.none )
|
||||
|
||||
_ ->
|
||||
( { model | content = model.content ++ wrongArgs HelloCommand 0 args }, Cmd.none )
|
||||
|
|
22
src/Main.hs
22
src/Main.hs
|
@ -1,8 +1,10 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
module Main (main) where
|
||||
|
||||
import ElmskellTypes
|
||||
import Data.FileEmbed (embedStringFile)
|
||||
import Data.Text.Lazy (Text)
|
||||
import Network.Wai.Handler.Warp (Port)
|
||||
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
|
||||
|
@ -36,27 +38,31 @@ adminContact :: String
|
|||
adminContact = "[Matrix] @mtgmonkey:calitabby.net"
|
||||
|
||||
compiledElmAppFile :: AssetPath
|
||||
compiledElmAppFile = "/js/main.js"
|
||||
compiledElmAppFile = "/main.js"
|
||||
|
||||
boilerplateJsFile :: AssetPath
|
||||
boilerplateJsFile = "/js/init.js"
|
||||
boilerplateJsFile = "/init.js"
|
||||
|
||||
assetsFolder :: FilePath
|
||||
assetsFolder = "/home/mtgmonkey/elmskell/assets"
|
||||
assetsFolder = "."
|
||||
|
||||
compiledElmApp :: H.Html
|
||||
compiledElmApp = H.toHtml ($(embedStringFile "./main.js") :: String)
|
||||
|
||||
boilerplateJs :: H.Html
|
||||
boilerplateJs = H.toHtml ($(embedStringFile "./init.js") :: String)
|
||||
|
||||
-- MAIN
|
||||
main :: IO ()
|
||||
main = do
|
||||
|
||||
generateElmskellTypes
|
||||
|
||||
compiledElmAppOrExc <- E.try $ readFile $ assetsFolder ++ compiledElmAppFile :: IO (Either E.IOException String)
|
||||
let compiledElmApp = case compiledElmAppOrExc of
|
||||
let compiledElmApp' = case compiledElmAppOrExc of
|
||||
Left e -> serverErrorReadFile e
|
||||
Right contents -> H.toHtml $ contents
|
||||
|
||||
boilerplateJsOrExc <- E.try $ readFile $ assetsFolder ++ boilerplateJsFile :: IO (Either E.IOException String)
|
||||
let boilerplateJs = case boilerplateJsOrExc of
|
||||
let boilerplateJs' = case boilerplateJsOrExc of
|
||||
Left e -> serverErrorReadFile e
|
||||
Right contents -> H.toHtml $ contents
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src"
|
||||
"."
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
Loading…
Add table
Add a link
Reference in a new issue