From cc9b975f87e26e39313063552fed8e277f93c8f0 Mon Sep 17 00:00:00 2001 From: h3rald Date: Mon, 8 Oct 2018 18:12:58 +0200 Subject: [PATCH] Changed package structure. --- hastyscribe.nimble | 88 ++++++++++++++++-- lib/config.nim | 37 -------- lib/consts.nim | 34 ------- nakefile.nim | 58 ------------ hastyscribe.nim => src/hastyscribe.nim | 33 +++++-- .../hastyscribe.nim.cfg | 0 src/hastyscribepkg/config.nim | 5 + src/hastyscribepkg/consts.nim | 34 +++++++ {lib => src/hastyscribepkg}/markdown.nim | 16 ---- {lib => src/hastyscribepkg}/utils.nim | 0 .../vendor}/libmarkdown_linux_arm.a | Bin .../vendor}/libmarkdown_linux_x64.a | Bin .../vendor}/libmarkdown_linux_x86.a | Bin .../vendor}/libmarkdown_macosx_x64.a | Bin .../vendor}/libmarkdown_windows_x64.a | Bin src/nifty.json | 54 +++++++++++ 16 files changed, 200 insertions(+), 159 deletions(-) delete mode 100644 lib/config.nim delete mode 100644 lib/consts.nim delete mode 100644 nakefile.nim rename hastyscribe.nim => src/hastyscribe.nim (95%) rename hastyscribe.nim.cfg => src/hastyscribe.nim.cfg (100%) create mode 100644 src/hastyscribepkg/config.nim create mode 100644 src/hastyscribepkg/consts.nim rename {lib => src/hastyscribepkg}/markdown.nim (92%) rename {lib => src/hastyscribepkg}/utils.nim (100%) rename {vendor => src/hastyscribepkg/vendor}/libmarkdown_linux_arm.a (100%) rename {vendor => src/hastyscribepkg/vendor}/libmarkdown_linux_x64.a (100%) rename {vendor => src/hastyscribepkg/vendor}/libmarkdown_linux_x86.a (100%) rename {vendor => src/hastyscribepkg/vendor}/libmarkdown_macosx_x64.a (100%) rename {vendor => src/hastyscribepkg/vendor}/libmarkdown_windows_x64.a (100%) create mode 100644 src/nifty.json diff --git a/hastyscribe.nimble b/hastyscribe.nimble index e50aef0..2e8432b 100644 --- a/hastyscribe.nimble +++ b/hastyscribe.nimble @@ -1,11 +1,83 @@ -[Package] -name = "hastyscribe" -version = "1.11.0" -author = "Fabio Cevasco" -description = "Self-contained markdown compiler generating self-contained HTML documents" +import + ospaths + +template thisModuleFile: string = instantiationInfo(fullPaths = true).filename + +when fileExists(thisModuleFile.parentDir / "src/hastyscribepkg/config.nim"): + # In the git repository the Nimble sources are in a ``src`` directory. + import src/hastyscribepkg/config +else: + # When the package is installed, the ``src`` directory disappears. + import hastyscribepkg/config + +# Package + +version = pkgVersion +author = pkgAuthor +description = pkgDescription license = "MIT" +bin = @["hastyscribe"] +srcDir = "src" +installFiles = @["nifty.json"] + +requires "nim >= 0.19.0" + +before install: + exec "nifty install" + +# Tasks + +const + compile = "nim c -d:release" + linux_x86 = "--cpu:i386 --os:linux" + linux_x64 = "--cpu:amd64 --os:linux" + linux_arm = "--cpu:arm --os:linux" + windows_x64 = "--cpu:amd64 --os:windows" + macosx_x64 = "" + hs = "src/hastyscribe" + hs_file = "src/hastyscribe.nim" + zip = "zip -X" + +proc shell(command, args: string, dest = "") = + exec command & " " & args & " " & dest + +proc filename_for(os: string, arch: string): string = + return "hastyscribe" & "_v" & version & "_" & os & "_" & arch & ".zip" + +task windows_x64_build, "Build HastyScribe for Windows (x64)": + shell compile, windows_x64, hs_file -bin = "hastyscribe" +task linux_x86_build, "Build HastyScribe for Linux (x86)": + shell compile, linux_x86, hs_file + +task linux_x64_build, "Build HastyScribe for Linux (x64)": + shell compile, linux_x64, hs_file + +task linux_arm_build, "Build HastyScribe for Linux (ARM)": + shell compile, linux_arm, hs_file + +task macosx_x64_build, "Build HastyScribe for Mac OS X (x64)": + shell compile, macosx_x64, hs_file -[Deps] -Requires: "nim >= 0.19.0" +task release, "Release HastyScribe": + echo "\n\n\n WINDOWS - x64:\n\n" + windows_x64_buildTask() + shell zip, filename_for("windows", "x64"), hs & ".exe" + shell "rm", hs & ".exe" + echo "\n\n\n LINUX - x64:\n\n" + linux_x64_buildTask() + shell zip, filename_for("linux", "x64"), hs + shell "rm", hs + echo "\n\n\n LINUX - x86:\n\n" + linux_x86_buildTask() + shell zip, filename_for("linux", "x86"), hs + shell "rm", hs + echo "\n\n\n LINUX - ARM:\n\n" + linux_arm_buildTask() + shell zip, filename_for("linux", "arm"), hs + shell "rm", hs + echo "\n\n\n MAC OS X - x64:\n\n" + macosx_x64_buildTask() + shell zip, filename_for("macosx", "x64"), hs + shell "rm", hs + echo "\n\n\n ALL DONE!" diff --git a/lib/config.nim b/lib/config.nim deleted file mode 100644 index d0d2fad..0000000 --- a/lib/config.nim +++ /dev/null @@ -1,37 +0,0 @@ -import - parsecfg, - streams, - strutils - -const - cfgfile = "../hastyscribe.nimble".slurp - -var - version*: string - f = newStringStream(cfgfile) - -if f != nil: - var p: CfgParser - open(p, f, "hastyscribe.nimble") - while true: - var e = next(p) - case e.kind - of cfgEof: - break - of cfgKeyValuePair: - case e.key: - of "version": - version = e.value - else: - discard - of cfgError: - stderr.writeLine("Configuration error.") - quit(1) - else: - discard - close(p) -else: - stderr.writeLine("Cannot process configuration file.") - quit(2) - - diff --git a/lib/consts.nim b/lib/consts.nim deleted file mode 100644 index 1f84169..0000000 --- a/lib/consts.nim +++ /dev/null @@ -1,34 +0,0 @@ - -const - stylesheet* = "../packages/hastystyles/styles/hastyscribe.css".slurp - hastyscribe_font* = "../packages/hastystyles/fonts/hastyscribe.woff".slurp - fa_solid_font* = "../packages/hastystyles/fonts/fa-solid-900.woff".slurp - fa_brands_font* = "../packages/hastystyles/fonts/fa-brands-400.woff".slurp - sourcecodepro_font* = "../packages/hastystyles/fonts/SourceCodePro-Regular.woff".slurp - sourcecodepro_it_font* = "../packages/hastystyles/fonts/SourceCodePro-It.woff".slurp - sourcecodepro_bold_font* = "../packages/hastystyles/fonts/SourceCodePro-Bold.woff".slurp - sourcecodepro_boldit_font* = "../packages/hastystyles/fonts/SourceCodePro-BoldIt.woff".slurp - sourcesanspro_font* = "../packages/hastystyles/fonts/SourceSansPro-Light.woff".slurp - sourcesanspro_bold_font* = "../packages/hastystyles/fonts/SourceSansPro-Semibold.woff".slurp - sourcesanspro_it_font* = "../packages/hastystyles/fonts/SourceSansPro-LightIt.woff".slurp - sourcesanspro_boldit_font* = "../packages/hastystyles/fonts/SourceSansPro-SemiboldIt.woff".slurp - watermark_style* = """ -#container { - position: relative; - z-index: 0; -} -#container:after { - content: ""; - opacity: 0.1; - z-index: -1; - position: absolute; - top: 0; - left: 0; - bottom: 0; - right: 0; - background-image: url($1); - background-repeat: no-repeat; - background-position: center 70px; - background-attachment: fixed; -} -""" diff --git a/nakefile.nim b/nakefile.nim deleted file mode 100644 index bb67cb9..0000000 --- a/nakefile.nim +++ /dev/null @@ -1,58 +0,0 @@ -import - nake - -import - lib/config - -const - compile = "nim c -d:release" - linux_x86 = "--cpu:i386 --os:linux" - linux_x64 = "--cpu:amd64 --os:linux" - linux_arm = "--cpu:arm --os:linux" - windows_x64 = "--cpu:amd64 --os:windows" - macosx_x64 = "" - #parallel = "--parallelBuild:1 --verbosity:3" - hs = "hastyscribe" - hs_file = "hastyscribe.nim" - zip = "zip -X" - -proc filename_for(os: string, arch: string): string = - return "hastyscribe" & "_v" & version & "_" & os & "_" & arch & ".zip" - -task "windows-x64-build", "Build HastyScribe for Windows (x64)": - direshell compile, windows_x64, hs_file - -task "linux-x86-build", "Build HastyScribe for Linux (x86)": - direshell compile, linux_x86, hs_file - -task "linux-x64-build", "Build HastyScribe for Linux (x64)": - direshell compile, linux_x64, hs_file - -task "linux-arm-build", "Build HastyScribe for Linux (ARM)": - direshell compile, linux_arm, hs_file - -task "macosx-x64-build", "Build HastyScribe for Mac OS X (x64)": - direshell compile, macosx_x64, hs_file - -task "release", "Release HastyScribe": - echo "\n\n\n WINDOWS - x64:\n\n" - runTask "windows-x64-build" - direshell zip, filename_for("windows", "x64"), hs & ".exe" - direshell "rm", hs & ".exe" - echo "\n\n\n LINUX - x64:\n\n" - runTask "linux-x64-build" - direshell zip, filename_for("linux", "x64"), hs - direshell "rm", hs - echo "\n\n\n LINUX - x86:\n\n" - runTask "linux-x86-build" - direshell zip, filename_for("linux", "x86"), hs - direshell "rm", hs - echo "\n\n\n LINUX - ARM:\n\n" - runTask "linux-arm-build" - direshell zip, filename_for("linux", "arm"), hs - direshell "rm", hs - echo "\n\n\n MAC OS X - x64:\n\n" - runTask "macosx-x64-build" - direshell zip, filename_for("macosx", "x64"), hs - direshell "rm", hs - echo "\n\n\n ALL DONE!" diff --git a/hastyscribe.nim b/src/hastyscribe.nim similarity index 95% rename from hastyscribe.nim rename to src/hastyscribe.nim index 848d97b..16eca9c 100644 --- a/hastyscribe.nim +++ b/src/hastyscribe.nim @@ -11,16 +11,37 @@ import logging import - packages/niftylogger, - lib/markdown, - lib/config, - lib/consts, - lib/utils + ../packages/niftylogger, + hastyscribepkg/markdown, + hastyscribepkg/config, + hastyscribepkg/consts, + hastyscribepkg/utils export consts +when defined(discount): + {.passL: "-L../packages/discount".} + {.passL: "-lmarkdown".} +else: + import os + when dirExists("src/hastyscribepkg/vendor"): + {.passL: "-Lsrc/hastyscribepkg/vendor".} + else: + {.passL: "-Lhastyscribepkg/vendor".} + when defined(macosx): + {.passL: "-lmarkdown_macosx_x64".} + when defined(windows): + {.passL: "-lmarkdown_windows_x64".} + when defined(linux): + when defined(arm): + {.passL: "-lmarkdown_linux_arm".} + when defined(i386): + {.passL: "-lmarkdown_linux_x86".} + when defined(amd64): + {.passL: "-lmarkdown_linux_x64".} + type HastyOptions* = object toc*: bool @@ -469,7 +490,7 @@ proc compile*(hs: var HastyScribe, input_file: string) = ### MAIN when isMainModule: - let usage = " HastyScribe v" & version & " - Self-contained Markdown Compiler" & """ + let usage = " HastyScribe v" & pkgVersion & " - Self-contained Markdown Compiler" & """ (c) 2013-2018 Fabio Cevasco diff --git a/hastyscribe.nim.cfg b/src/hastyscribe.nim.cfg similarity index 100% rename from hastyscribe.nim.cfg rename to src/hastyscribe.nim.cfg diff --git a/src/hastyscribepkg/config.nim b/src/hastyscribepkg/config.nim new file mode 100644 index 0000000..2ecf6ee --- /dev/null +++ b/src/hastyscribepkg/config.nim @@ -0,0 +1,5 @@ +const + pkgVersion* = "1.11.0" + pkgAuthor* = "Fabio Cevasco" + pkgDescription* = "Self-contained markdown compiler generating self-contained HTML documents" + diff --git a/src/hastyscribepkg/consts.nim b/src/hastyscribepkg/consts.nim new file mode 100644 index 0000000..8e10ddb --- /dev/null +++ b/src/hastyscribepkg/consts.nim @@ -0,0 +1,34 @@ + +const + stylesheet* = "../../packages/hastystyles/styles/hastyscribe.css".slurp + hastyscribe_font* = "../../packages/hastystyles/fonts/hastyscribe.woff".slurp + fa_solid_font* = "../../packages/hastystyles/fonts/fa-solid-900.woff".slurp + fa_brands_font* = "../../packages/hastystyles/fonts/fa-brands-400.woff".slurp + sourcecodepro_font* = "../../packages/hastystyles/fonts/SourceCodePro-Regular.woff".slurp + sourcecodepro_it_font* = "../../packages/hastystyles/fonts/SourceCodePro-It.woff".slurp + sourcecodepro_bold_font* = "../../packages/hastystyles/fonts/SourceCodePro-Bold.woff".slurp + sourcecodepro_boldit_font* = "../../packages/hastystyles/fonts/SourceCodePro-BoldIt.woff".slurp + sourcesanspro_font* = "../../packages/hastystyles/fonts/SourceSansPro-Light.woff".slurp + sourcesanspro_bold_font* = "../../packages/hastystyles/fonts/SourceSansPro-Semibold.woff".slurp + sourcesanspro_it_font* = "../../packages/hastystyles/fonts/SourceSansPro-LightIt.woff".slurp + sourcesanspro_boldit_font* = "../../packages/hastystyles/fonts/SourceSansPro-SemiboldIt.woff".slurp + watermark_style* = """ +#container { + position: relative; + z-index: 0; +} +#container:after { + content: ""; + opacity: 0.1; + z-index: -1; + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + background-image: url($1); + background-repeat: no-repeat; + background-position: center 70px; + background-attachment: fixed; +} +""" diff --git a/lib/markdown.nim b/src/hastyscribepkg/markdown.nim similarity index 92% rename from lib/markdown.nim rename to src/hastyscribepkg/markdown.nim index 06ad96a..86bece6 100644 --- a/lib/markdown.nim +++ b/src/hastyscribepkg/markdown.nim @@ -1,19 +1,3 @@ -when defined(discount): - {.passL: "-Lpackages/discount".} - {.passL: "-lmarkdown".} -else: - {.passL: "-Lvendor".} - when defined(macosx): - {.passL: "-lmarkdown_macosx_x64".} - when defined(windows): - {.passL: "-lmarkdown_windows_x64".} - when defined(linux): - when defined(arm): - {.passL: "-lmarkdown_linux_arm".} - when defined(i386): - {.passL: "-lmarkdown_linux_x86".} - when defined(amd64): - {.passL: "-lmarkdown_linux_x64".} const MKDIO_D* = true type diff --git a/lib/utils.nim b/src/hastyscribepkg/utils.nim similarity index 100% rename from lib/utils.nim rename to src/hastyscribepkg/utils.nim diff --git a/vendor/libmarkdown_linux_arm.a b/src/hastyscribepkg/vendor/libmarkdown_linux_arm.a similarity index 100% rename from vendor/libmarkdown_linux_arm.a rename to src/hastyscribepkg/vendor/libmarkdown_linux_arm.a diff --git a/vendor/libmarkdown_linux_x64.a b/src/hastyscribepkg/vendor/libmarkdown_linux_x64.a similarity index 100% rename from vendor/libmarkdown_linux_x64.a rename to src/hastyscribepkg/vendor/libmarkdown_linux_x64.a diff --git a/vendor/libmarkdown_linux_x86.a b/src/hastyscribepkg/vendor/libmarkdown_linux_x86.a similarity index 100% rename from vendor/libmarkdown_linux_x86.a rename to src/hastyscribepkg/vendor/libmarkdown_linux_x86.a diff --git a/vendor/libmarkdown_macosx_x64.a b/src/hastyscribepkg/vendor/libmarkdown_macosx_x64.a similarity index 100% rename from vendor/libmarkdown_macosx_x64.a rename to src/hastyscribepkg/vendor/libmarkdown_macosx_x64.a diff --git a/vendor/libmarkdown_windows_x64.a b/src/hastyscribepkg/vendor/libmarkdown_windows_x64.a similarity index 100% rename from vendor/libmarkdown_windows_x64.a rename to src/hastyscribepkg/vendor/libmarkdown_windows_x64.a diff --git a/src/nifty.json b/src/nifty.json new file mode 100644 index 0000000..298ff84 --- /dev/null +++ b/src/nifty.json @@ -0,0 +1,54 @@ +{ + "storage": "packages", + "commands": { + "build": { + "name+configure.sh": { + "pwd": "{{name}}", + "cmd": "./configure.sh && make" + } + }, + "install": { + "git+src": { + "cmd": "git clone {{src}} --depth 1" + }, + "git+src+tag": { + "cmd": "git clone --branch {{tag}} {{src}} --depth 1" + }, + "curl+src+name": { + "cmd": "curl {{src}} -o {{name}}" + }, + "_syntax": "install []", + "_description": "Installs the specified package (or all mapped packages) to the storage directory." + }, + "upgrade": { + "_syntax": "upgrade []", + "_description": "Upgrades the specified previously-installed package (or all packages).", + "git+name": { + "cmd": "git pull", + "pwd": "{{name}}" + }, + "curl+src+name": { + "cmd": "curl {{src}} -o {{name}}" + } + } + }, + "packages": { + "hastystyles": { + "name": "hastystyles", + "src": "https://github.com/h3rald/hastystyles.git", + "git": true + }, + "discount": { + "configure.sh": true, + "name": "discount", + "src": "https://github.com/Orc/discount.git", + "tag": "v2.2.2", + "git": true + }, + "niftylogger.nim": { + "name": "niftylogger.nim", + "src": "https://raw.githubusercontent.com/h3rald/nifty/master/lib/niftylogger.nim", + "curl": true + } + } +}