diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/.gitignore | 1 | ||||
-rw-r--r-- | compiler/app/Main.hs | 32 | ||||
-rw-r--r-- | compiler/app/ViewerDist.hs | 39 | ||||
-rw-r--r-- | compiler/ldgallery.1.md | 4 | ||||
-rw-r--r-- | compiler/package.yaml | 17 | ||||
-rw-r--r-- | compiler/src/Caching.hs | 6 | ||||
-rw-r--r-- | compiler/src/Compiler.hs | 6 | ||||
-rw-r--r-- | compiler/src/FileProcessors.hs | 4 | ||||
-rw-r--r-- | compiler/src/Input.hs | 6 | ||||
-rw-r--r-- | compiler/src/ItemProcessors.hs | 7 | ||||
-rw-r--r-- | compiler/src/Resource.hs | 3 | ||||
-rw-r--r-- | compiler/stack.yaml | 7 | ||||
-rw-r--r-- | compiler/stack.yaml.lock | 8 |
13 files changed, 93 insertions, 47 deletions
diff --git a/compiler/.gitignore b/compiler/.gitignore index 778e7ef..3415fc8 100644 --- a/compiler/.gitignore +++ b/compiler/.gitignore | |||
@@ -1,3 +1,4 @@ | |||
1 | .stack-work/ | 1 | .stack-work/ |
2 | dist/ | ||
2 | ldgallery-compiler.cabal | 3 | ldgallery-compiler.cabal |
3 | *~ \ No newline at end of file | 4 | *~ \ No newline at end of file |
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index e71e0db..3e6f254 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs | |||
@@ -1,7 +1,7 @@ | |||
1 | -- ldgallery - A static generator which turns a collection of tagged | 1 | -- ldgallery - A static generator which turns a collection of tagged |
2 | -- pictures into a searchable web gallery. | 2 | -- pictures into a searchable web gallery. |
3 | -- | 3 | -- |
4 | -- Copyright (C) 2019-2020 Pacien TRAN-GIRARD | 4 | -- Copyright (C) 2019-2021 Pacien TRAN-GIRARD |
5 | -- | 5 | -- |
6 | -- This program is free software: you can redistribute it and/or modify | 6 | -- This program is free software: you can redistribute it and/or modify |
7 | -- it under the terms of the GNU Affero General Public License as | 7 | -- it under the terms of the GNU Affero General Public License as |
@@ -19,7 +19,7 @@ | |||
19 | module Main where | 19 | module Main where |
20 | 20 | ||
21 | import GHC.Generics (Generic) | 21 | import GHC.Generics (Generic) |
22 | import Paths_ldgallery_compiler (version, getDataFileName) | 22 | import Paths_ldgallery_compiler (version) |
23 | import Control.Monad (when) | 23 | import Control.Monad (when) |
24 | import Data.Functor ((<&>)) | 24 | import Data.Functor ((<&>)) |
25 | import Data.Maybe (isJust) | 25 | import Data.Maybe (isJust) |
@@ -31,7 +31,7 @@ import System.Console.CmdArgs | |||
31 | 31 | ||
32 | import Compiler | 32 | import Compiler |
33 | import Files (readDirectory, copyTo, remove) | 33 | import Files (readDirectory, copyTo, remove) |
34 | 34 | import ViewerDist (viewerDistPath) | |
35 | 35 | ||
36 | newtype ViewerConfig = ViewerConfig | 36 | newtype ViewerConfig = ViewerConfig |
37 | { galleryRoot :: String | 37 | { galleryRoot :: String |
@@ -94,6 +94,7 @@ options = Options | |||
94 | } | 94 | } |
95 | 95 | ||
96 | &= summary ("ldgallery v" ++ showVersion version ++ " - a static web gallery generator with tags") | 96 | &= summary ("ldgallery v" ++ showVersion version ++ " - a static web gallery generator with tags") |
97 | &= details ["This software is distributed under the terms of the GNU Affero General Public License v3.0."] | ||
97 | &= program "ldgallery" | 98 | &= program "ldgallery" |
98 | &= help "Compile a gallery" | 99 | &= help "Compile a gallery" |
99 | &= helpArg [explicit, name "h", name "help"] | 100 | &= helpArg [explicit, name "h", name "help"] |
@@ -105,10 +106,7 @@ main = | |||
105 | do | 106 | do |
106 | opts <- cmdArgs options | 107 | opts <- cmdArgs options |
107 | buildGallery opts | 108 | buildGallery opts |
108 | 109 | deployViewer opts | |
109 | when (isJust $ withViewer opts) $ do | ||
110 | viewerDist <- viewerDistPath $ withViewer opts | ||
111 | deployViewer viewerDist opts | ||
112 | 110 | ||
113 | where | 111 | where |
114 | gallerySubdir :: String | 112 | gallerySubdir :: String |
@@ -117,11 +115,6 @@ main = | |||
117 | viewerConfig :: ViewerConfig | 115 | viewerConfig :: ViewerConfig |
118 | viewerConfig = ViewerConfig (gallerySubdir ++ "/") | 116 | viewerConfig = ViewerConfig (gallerySubdir ++ "/") |
119 | 117 | ||
120 | viewerDistPath :: Maybe FilePath -> IO FilePath | ||
121 | viewerDistPath (Just "") = getDataFileName "viewer" | ||
122 | viewerDistPath (Just dist) = return dist | ||
123 | viewerDistPath Nothing = fail "No viewer distribution" | ||
124 | |||
125 | buildGallery :: Options -> IO () | 118 | buildGallery :: Options -> IO () |
126 | buildGallery opts = | 119 | buildGallery opts = |
127 | checkDistinctPaths (inputDir opts) (outputDir opts) | 120 | checkDistinctPaths (inputDir opts) (outputDir opts) |
@@ -145,10 +138,11 @@ main = | |||
145 | | isJust withViewer = outputDir </> gallerySubdir | 138 | | isJust withViewer = outputDir </> gallerySubdir |
146 | | otherwise = outputDir | 139 | | otherwise = outputDir |
147 | 140 | ||
148 | deployViewer :: FilePath -> Options -> IO () | 141 | deployViewer :: Options -> IO () |
149 | deployViewer distPath Options{outputDir, cleanOutput} = | 142 | deployViewer Options{withViewer = Nothing} = pure () |
143 | deployViewer Options{withViewer = Just viewerPath, outputDir, cleanOutput} = | ||
150 | when cleanOutput (cleanViewerDir outputDir) | 144 | when cleanOutput (cleanViewerDir outputDir) |
151 | >> copyViewer distPath outputDir | 145 | >> viewerDistOr viewerPath >>= deployTo outputDir |
152 | >> writeJSON (outputDir </> "config.json") viewerConfig | 146 | >> writeJSON (outputDir </> "config.json") viewerConfig |
153 | 147 | ||
154 | where | 148 | where |
@@ -158,8 +152,12 @@ main = | |||
158 | <&> filter (/= gallerySubdir) | 152 | <&> filter (/= gallerySubdir) |
159 | >>= mapM_ (remove . (target </>)) | 153 | >>= mapM_ (remove . (target </>)) |
160 | 154 | ||
161 | copyViewer :: FilePath -> FilePath -> IO () | 155 | viewerDistOr :: FilePath -> IO FilePath |
162 | copyViewer dist target = | 156 | viewerDistOr "" = viewerDistPath |
157 | viewerDistOr custom = pure custom | ||
158 | |||
159 | deployTo :: FilePath -> FilePath -> IO () | ||
160 | deployTo target dist = | ||
163 | putStrLn "Copying viewer webapp" | 161 | putStrLn "Copying viewer webapp" |
164 | >> readDirectory dist | 162 | >> readDirectory dist |
165 | >>= copyTo target | 163 | >>= copyTo target |
diff --git a/compiler/app/ViewerDist.hs b/compiler/app/ViewerDist.hs new file mode 100644 index 0000000..2b80ffc --- /dev/null +++ b/compiler/app/ViewerDist.hs | |||
@@ -0,0 +1,39 @@ | |||
1 | -- ldgallery - A static generator which turns a collection of tagged | ||
2 | -- pictures into a searchable web gallery. | ||
3 | -- | ||
4 | -- Copyright (C) 2021 Pacien TRAN-GIRARD | ||
5 | -- | ||
6 | -- This program is free software: you can redistribute it and/or modify | ||
7 | -- it under the terms of the GNU Affero General Public License as | ||
8 | -- published by the Free Software Foundation, either version 3 of the | ||
9 | -- License, or (at your option) any later version. | ||
10 | -- | ||
11 | -- This program is distributed in the hope that it will be useful, | ||
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | -- GNU Affero General Public License for more details. | ||
15 | -- | ||
16 | -- You should have received a copy of the GNU Affero General Public License | ||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
18 | |||
19 | {-# LANGUAGE CPP #-} | ||
20 | |||
21 | module ViewerDist where | ||
22 | |||
23 | #ifndef FLAG_PORTABLE | ||
24 | |||
25 | import Paths_ldgallery_compiler (getDataFileName) | ||
26 | |||
27 | viewerDistPath = getDataFileName "viewer" | ||
28 | |||
29 | #else | ||
30 | |||
31 | import Data.Functor ((<&>)) | ||
32 | import System.FilePath (takeDirectory, (</>)) | ||
33 | import System.Environment (getExecutablePath) | ||
34 | |||
35 | viewerDistPath = fmap takeDirectory getExecutablePath <&> (</> "viewer") | ||
36 | |||
37 | #endif | ||
38 | |||
39 | viewerDistPath :: IO FilePath | ||
diff --git a/compiler/ldgallery.1.md b/compiler/ldgallery.1.md index eda6cc2..2e247cd 100644 --- a/compiler/ldgallery.1.md +++ b/compiler/ldgallery.1.md | |||
@@ -2,7 +2,7 @@ | |||
2 | pagetitle: Compiler user manual - ldgallery | 2 | pagetitle: Compiler user manual - ldgallery |
3 | title: LDGALLERY(1) ldgallery | 3 | title: LDGALLERY(1) ldgallery |
4 | author: Pacien TRAN-GIRARD, Guillaume FOUET | 4 | author: Pacien TRAN-GIRARD, Guillaume FOUET |
5 | date: 2020-09-19 (v2.0) | 5 | date: 2022-09-04 (v2.1) |
6 | --- | 6 | --- |
7 | 7 | ||
8 | 8 | ||
@@ -187,7 +187,7 @@ The ldgallery source code is available on <https://ldgallery.pacien.org>. | |||
187 | 187 | ||
188 | # LICENSE | 188 | # LICENSE |
189 | 189 | ||
190 | Copyright (C) 2019-2020 Pacien TRAN-GIRARD and Guillaume FOUET. | 190 | Copyright (C) 2019-2022 Pacien TRAN-GIRARD and Guillaume FOUET. |
191 | 191 | ||
192 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | 192 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. |
193 | 193 | ||
diff --git a/compiler/package.yaml b/compiler/package.yaml index faa2174..7bd86e9 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml | |||
@@ -1,11 +1,10 @@ | |||
1 | name: ldgallery-compiler | 1 | name: ldgallery-compiler |
2 | version: 2.0 | 2 | version: 2.1 |
3 | homepage: https://ldgallery.pacien.org | 3 | homepage: https://ldgallery.pacien.org |
4 | github: "pacien/ldgallery" | 4 | github: "pacien/ldgallery" |
5 | license: AGPL-3 | 5 | license: AGPL-3 |
6 | author: "Pacien TRAN-GIRARD, Guillaume FOUET" | 6 | author: "Pacien TRAN-GIRARD, Guillaume FOUET" |
7 | maintainer: "" | 7 | copyright: "2019-2021 Pacien TRAN-GIRARD, Guillaume FOUET" |
8 | copyright: "2019-2020 Pacien TRAN-GIRARD, Guillaume FOUET" | ||
9 | 8 | ||
10 | extra-source-files: | 9 | extra-source-files: |
11 | - readme.md | 10 | - readme.md |
@@ -54,6 +53,15 @@ data-files: ["**/*"] | |||
54 | library: | 53 | library: |
55 | source-dirs: src | 54 | source-dirs: src |
56 | 55 | ||
56 | flags: | ||
57 | portable: | ||
58 | description: > | ||
59 | Make the output binary portable. | ||
60 | It will look in its own runtime location for its assets instead of | ||
61 | absolute installation paths. | ||
62 | manual: true | ||
63 | default: false | ||
64 | |||
57 | executables: | 65 | executables: |
58 | ldgallery: | 66 | ldgallery: |
59 | main: Main.hs | 67 | main: Main.hs |
@@ -64,6 +72,9 @@ executables: | |||
64 | - -with-rtsopts=-N | 72 | - -with-rtsopts=-N |
65 | dependencies: | 73 | dependencies: |
66 | - ldgallery-compiler | 74 | - ldgallery-compiler |
75 | when: | ||
76 | - condition: flag(portable) | ||
77 | cpp-options: -DFLAG_PORTABLE | ||
67 | 78 | ||
68 | tests: | 79 | tests: |
69 | ldgallery-compiler-test: |