-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
172 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Documentation Deploy | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
docs: | ||
concurrency: ci-${{ github.ref }} | ||
runs-on: ubuntu-latest | ||
container: nimlang/nim | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: git config --global --add safe.directory "$(pwd)" | ||
- run: nimble -y doc --index:on --out:docs --project src/playdate/api.nim | ||
- run: cp docs/api.html docs/index.html | ||
- name: Deploy documents | ||
uses: peaceiris/actions-gh-pages@v3 | ||
if: ${{ !env.ACT }} | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ htmldocs/ | |
src/tests/ | ||
pdex.bin | ||
*.pdx | ||
docs | ||
tests/source/pdxinfo | ||
|
||
# macOS general | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import std/[strutils, strformat, osproc, json, jsonutils], utils | ||
|
||
type | ||
NimbleDump* = ref object | ||
## The data pulled from running `nimble dump --json` | ||
name*, version*, nimblePath*, author*, desc*, license*: string | ||
|
||
proc getNimbleDump*(): NimbleDump = | ||
## Executes nimble with the given set of arguments | ||
let (output, exitCode) = execCmdEx("nimble dump --json") | ||
if exitCode != 0: | ||
echo output | ||
raise BuildFail.newException(fmt"Unable to extract nimble dump for package") | ||
return parseJson(output).jsonTo(NimbleDump, Joptions(allowExtraKeys: true)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import std/[os, parsecfg, streams, strutils, strformat, times, osproc], nimbledump | ||
|
||
type PdxInfo* = object | ||
## Details used to populate the pdxinfo file | ||
name*, author*, description*, bundleId*, imagePath*, version*, buildNumber*: string | ||
|
||
proc `$`*(pdx: PdxInfo): string = | ||
for key, value in pdx.fieldPairs: | ||
if value != "": | ||
result &= key & "=" & value & "\n" | ||
|
||
proc write*(pdx: PdxInfo) = | ||
## Writes the pdxinfo file | ||
createDir("source") | ||
writeFile("source" / "pdxinfo", $pdx) | ||
|
||
proc join*(a, b: PdxInfo): PdxInfo = | ||
## Combins two PdxInfo instances | ||
result = a | ||
for current, override in fields(result, b): | ||
if override != "": | ||
current = override | ||
|
||
proc parsePdx*(data: Stream, filename: string): PdxInfo = | ||
## Parses a pdx config from a string | ||
let dict = loadConfig(data, filename) | ||
for key, value in result.fieldPairs: | ||
value = dict.getSectionValue("", key) | ||
|
||
proc readPdx*(path: string): PdxInfo = | ||
## Creates a pdx by reading a local pxinfo file | ||
if fileExists(path): | ||
return parsePdx(newFileStream(path), path) | ||
|
||
proc gitHashOrElse(fallback: string): string = | ||
let (output, exitCode) = execCmdEx("git rev-parse HEAD") | ||
return if exitCode == 0: output[0..<8] else: fallback | ||
|
||
proc toPdxInfo*( | ||
dump: NimbleDump, | ||
version: string = gitHashOrElse(dump.version), | ||
buildNumber: string = now().format("yyyyMMddhhmmss") | ||
): PdxInfo = | ||
## Creates a base PdxInfo file | ||
result.name = dump.name | ||
result.author = dump.author | ||
result.description = dump.desc | ||
|
||
let bundleIdPkg = dump.author.toLower().replace(" ", "").replace("-", "").replace("_", "") | ||
let bundleIdName = dump.name.replace(" ", "").toLowerAscii() | ||
result.bundleId = fmt"com.{bundleIdPkg}.{bundleIdName}" | ||
result.imagePath = "launcher" | ||
result.version = version | ||
result.buildNumber = buildNumber | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import std/[unittest, strutils, streams], playdate/build/[pdxinfo, nimbledump] | ||
|
||
suite "Pdxinfo generation": | ||
|
||
test "Produce a default pdxinfo from a nimble dump": | ||
let dump = NimbleDump( | ||
name: "Lorem Ipsum", | ||
version: "0.0.0", | ||
nimblePath: "/path/to/nimble", | ||
author: "Twas Brillig", | ||
desc: "A thing", | ||
license: "MIT", | ||
) | ||
|
||
check($dump.toPdxInfo("1.2.3", "20250216") == """ | ||
name=Lorem Ipsum | ||
author=Twas Brillig | ||
description=A thing | ||
bundleId=com.twasbrillig.loremipsum | ||
imagePath=launcher | ||
version=1.2.3 | ||
buildNumber=20250216 | ||
""".dedent()) | ||
|
||
test "Read a PDXInfo from a stream": | ||
let pdx = newStringStream(""" | ||
name=Lorem Ipsum | ||
author=Twas Brillig | ||
description=A thing | ||
bundleId=com.twasbrillig.loremipsum | ||
imagePath=launcher | ||
version=1.2.3 | ||
buildNumber=20250216 | ||
""").parsePdx("[stream]") | ||
|
||
check($pdx == """ | ||
name=Lorem Ipsum | ||
author=Twas Brillig | ||
description=A thing | ||
bundleId=com.twasbrillig.loremipsum | ||
imagePath=launcher | ||
version=1.2.3 | ||
buildNumber=20250216 | ||
""".dedent()) | ||
|
||
test "Join together multiple pdxinfo objects": | ||
let pdx1 = PdxInfo( | ||
name: "Lorem Ipsum", | ||
description: "A thing", | ||
imagePath: "launcher", | ||
version: "1.2.3", | ||
buildNumber: "20250216", | ||
) | ||
|
||
let pdx2 = PdxInfo( | ||
author: "Twas Brillig", | ||
bundleId: "com.twasbrillig.loremipsum", | ||
version: "3.4.5", | ||
) | ||
|
||
check($join(pdx1, pdx2) == """ | ||
name=Lorem Ipsum | ||
author=Twas Brillig | ||
description=A thing | ||
bundleId=com.twasbrillig.loremipsum | ||
imagePath=launcher | ||
version=3.4.5 | ||
buildNumber=20250216 | ||
""".dedent()) |