on master help sign in
Add project skeleton for ob init

Also, make 'base' a mandatory, positional argument of 'project'

commit5e4cd93ebebea29aef58f625e854b983e044a450 authorRyan Trinkle <ryan.trinkle@gmail.com> dateFri 5 Jan 2018, 20:51 (9 years ago) parentd917826
14 files changed+90−2
command/src/Obelisk/Command/Project.hs+11 default.nix+8−2 skeleton/.gitignore+2 skeleton/backend/backend.cabal+13 skeleton/backend/frontend.jsexe+1 skeleton/backend/src/main.hs+5 skeleton/backend/static+1 skeleton/cabal.project+2 skeleton/common/common.cabal+11 skeleton/common/src/Common/Api.hs+4 skeleton/default.nix+8 skeleton/frontend/frontend.cabal+14 skeleton/frontend/src/main.hs+10 skeleton/static/obelisk.jpg
command/src/Obelisk/Command/Project.hs+11
@@ -14,9 +14,11 @@ import Data.Monoid
1414import qualified Data.Text as T
1515import qualified Data.Text.IO as T
1616import System.Directory
17+import System.Exit
1718import System.FilePath
1819import System.IO
1920import System.Posix (FileStatus, getFileStatus , deviceID, fileID, getRealUserID , fileOwner, fileMode)
21+import System.Process
2022
2123import Obelisk.Command.Thunk
2224
@@ -39,6 +41,15 @@ initProject target = do
3941 createDirectory obDir
4042 createThunkWithLatest implDir obeliskSource
4143 _ <- nixBuildThunkAttrWithCache implDir "command"
44+ skeleton <- nixBuildThunkAttrWithCache implDir "skeleton" --TODO: I don't think there's actually any reason to cache this
45+ (_, _, _, p) <- runInteractiveProcess "cp" --TODO: Make this package depend on nix-prefetch-url properly
46+ [ "-r"
47+ , "--no-preserve=mode"
48+ , "-T"
49+ , skeleton </> "."
50+ , target
51+ ] Nothing Nothing
52+ ExitSuccess <- waitForProcess p
4253 return ()
4354
4455--TODO: Handle errors
default.nix+8−2
@@ -45,6 +45,12 @@ with pkgs.lib;
4545rec {
4646 inherit reflex-platform;
4747 command = ghcObelisk.obelisk-command;
48+ #TODO: Why can't I build ./skeleton directly as a derivation? `nix-build -E ./.` doesn't work
49+ skeleton = pkgs.runCommand "skeleton" {
50+ dir = ./skeleton;
51+ } ''
52+ ln -s "$dir" "$out"
53+ '';
4854 nullIfAbsent = p: if pathExists p then p else null;
4955 #TODO: Avoid copying files within the nix store. Right now, obelisk-asset-manifest-generate copies files into a big blob so that the android/ios static assets can be imported from there; instead, we should get everything lined up right before turning it into an APK, so that copies, if necessary, only exist temporarily.
5056 processAssets = { src, packageName ? "static", moduleName ? "Static" }: pkgs.runCommand "asset-manifest" {
@@ -60,8 +66,8 @@ rec {
6066 '';
6167 # An Obelisk project is a reflex-platform project with a predefined layout and role for each component
6268 project =
63− { base ? ./..
64− , android ? null #TODO: Better error when missing
69+ base:
70+ { android ? null #TODO: Better error when missing
6571 , ios ? null #TODO: Better error when missing
6672 }: reflex-platform.project ({ nixpkgs, ... }: with nixpkgs.haskell.lib;
6773 let frontendName = "frontend";
skeleton/.gitignorenew file+2
@@ -0,0 +1,2 @@
1+dist-newstyle
2+result
skeleton/backend/backend.cabalnew file+13
@@ -0,0 +1,13 @@
1+name: backend
2+version: 0.1
3+cabal-version: >= 1.2
4+build-type: Simple
5+
6+executable backend
7+ main-is: main.hs
8+ hs-source-dirs: src
9+ build-depends:
10+ base,
11+ common,
12+ obelisk-backend,
13+ snap
skeleton/backend/frontend.jsexenew file+1
@@ -0,0 +1 @@
1+../frontend-js/bin/frontend.jsexe
skeleton/backend/src/main.hsnew file+5
@@ -0,0 +1,5 @@
1+import Obelisk.Backend
2+import Common.Api
3+
4+main :: IO ()
5+main = backend def
skeleton/backend/staticnew file+1
@@ -0,0 +1 @@
1+../static
skeleton/cabal.projectnew file+2
@@ -0,0 +1,2 @@
1+optional-packages:
2+ *
skeleton/common/common.cabalnew file+11
@@ -0,0 +1,11 @@
1+name: common
2+version: 0.1
3+cabal-version: >= 1.2
4+build-type: Simple
5+
6+library
7+ hs-source-dirs: src
8+ build-depends: base
9+
10+ exposed-modules:
11+ Common.Api
skeleton/common/src/Common/Api.hsnew file+4
@@ -0,0 +1,4 @@
1+module Common.Api where
2+
3+commonStuff :: String
4+commonStuff = undefined
skeleton/default.nixnew file+8
@@ -0,0 +1,8 @@
1+{ system ? builtins.currentSystem }: # TODO: Get rid of this system cruft
2+with import ./.obelisk/impl { inherit system; };
3+project ./. {
4+ android.applicationId = "systems.obsidian.obelisk.examples.minimal";
5+ android.displayName = "Obelisk Minimal Example";
6+ ios.bundleIdentifier = "systems.obsidian.obelisk.examples.minimal";
7+ ios.bundleName = "Obelisk Minimal Example";
8+}
skeleton/frontend/frontend.cabalnew file+14
@@ -0,0 +1,14 @@
1+name: frontend
2+version: 0.1
3+cabal-version: >= 1.2
4+build-type: Simple
5+
6+executable frontend
7+ main-is: main.hs
8+ hs-source-dirs: src
9+ build-depends: base,
10+ reflex-dom,
11+ text,
12+ static
13+ --TODO: Make these ghc-options optional
14+ ghc-options: -threaded
skeleton/frontend/src/main.hsnew file+10
@@ -0,0 +1,10 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE TypeApplications #-}
3+{-# LANGUAGE DataKinds #-}
4+import Reflex.Dom
5+import Static
6+
7+main :: IO ()
8+main = mainWidget $ do
9+ text "Welcome to Obelisk!"
10+ elAttr "img" ("src" =: static @"obelisk.jpg") blank
skeleton/static/obelisk.jpgnew file

Binary file not shown.