Skip to content

Commit 0c7769e

Browse files
CI JS (#64)
1 parent 372ee43 commit 0c7769e

File tree

9 files changed

+35
-31
lines changed

9 files changed

+35
-31
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (${{ matrix.branch }})'
3636
runs-on: ${{ matrix.builder }}
3737
steps:
38+
- uses: actions/setup-node@v2
3839
- name: Checkout fusion
3940
uses: actions/checkout@v2
4041
with:
@@ -131,17 +132,3 @@ jobs:
131132
target_branch: gh-pages
132133
env:
133134
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134-
135-
- name: Cache choosenim
136-
id: cache-choosenim
137-
uses: actions/cache@v1
138-
with:
139-
path: ~/.choosenim
140-
key: ${{ runner.os }}-choosenim-devel-latest
141-
142-
- name: Cache nimble
143-
id: cache-nimble
144-
uses: actions/cache@v1
145-
with:
146-
path: ~/.nimble
147-
key: ${{ runner.os }}-nimble-devel-latest

fusion.nimble

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ srcDir = "src"
1111
requires "nim >= 1.0.0"
1212

1313
task docs, "":
14-
# can customize, e.g.:
15-
# exec "nim r src/fusion/docutils " & srcDir & " --outdir:htmldocs2 -d:foo"
14+
# JavaScript
15+
when (NimMajor, NimMinor) >= (1, 5):
16+
exec "nim c -r -d:fusionDocJs src/fusion/docutils " & srcDir
17+
# C
1618
exec "nim c -r src/fusion/docutils " & srcDir

src/fusion/docutils.nim

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import std/[os, strformat, sugar, osproc]
1+
import std/[os, sugar, strutils, osproc]
22
import std/private/globs
33

44

5-
const blockList =
6-
when not defined(js): ["nimcache", "htmldocs", "js"]
7-
else: ["nimcache", "htmldocs"]
5+
const
6+
blockList = ["nimcache", "htmldocs"] # Folders to explicitly ignore.
7+
baseCmd = " doc --project --docroot --outdir:htmldocs --styleCheck:hint " # nim doc command part that never changes
8+
jsDocOpts = # nim doc command part that changes for JS compat.
9+
when defined(fusionDocJs): "-b:js "
10+
else: ""
11+
docComand = baseCmd & jsDocOpts
12+
813

914
iterator findNimSrcFiles*(dir: string): string =
10-
proc follow(a: PathEntry): bool =
15+
func follow(a: PathEntry): bool =
1116
a.path.lastPathPart notin blockList
1217

1318
for entry in walkDirRecFilter(dir, follow = follow):
@@ -17,18 +22,24 @@ iterator findNimSrcFiles*(dir: string): string =
1722

1823
proc genCodeImportAll*(dir: string): string =
1924
result = "{.warning[UnusedImport]: off.}\n"
20-
for a in findNimSrcFiles(dir):
21-
let s = "".dup(addQuoted(a))
22-
result.add &"import {s}\n"
25+
var name, prefix: string
26+
for nimfile in findNimSrcFiles(dir):
27+
name = nimfile.extractFilename
28+
prefix =
29+
if name.startsWith "js":
30+
"when defined(js): import "
31+
else:
32+
"when not defined(js): import "
33+
result.add prefix & "".dup(addQuoted(nimfile)) & "\n"
2334

2435

2536
proc genDocs(dir: string, nim = "", args: seq[string]) =
2637
let code = genCodeImportAll(dir)
2738
let extra = quoteShellCommand(args)
2839
let nim = if nim.len == 0: getCurrentCompilerExe() else: nim
29-
let ret = execCmdEx(fmt"{nim} doc -r --project --docroot --outdir:htmldocs {extra} -", input = code)
40+
let ret = execCmdEx(nim & docComand & extra & " - ", input = code)
3041
if ret.exitCode != 0:
31-
doAssert false, ret.output & "\n" & code
42+
doAssert false, ret.output & '\n' & code
3243

3344

3445
when isMainModule:

src/fusion/js/jsheaders.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## - HTTP Headers for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/Headers
2-
when not defined(js) and not defined(nimdoc):
2+
when not defined(js):
33
{.fatal: "Module jsheaders is designed to be used with the JavaScript backend.".}
44

55
type Headers* = ref object of JsRoot ## HTTP Headers for the JavaScript target.

src/fusion/js/jssets.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## `Set` for the JavaScript target.
22
## * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
3-
when not defined(js) and not defined(nimdoc):
3+
when not defined(js):
44
{.fatal: "Module jssets is designed to be used with the JavaScript backend.".}
55

66
import std/jsffi

src/fusion/js/jsxmlserializer.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## - `XMLSerializer` for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer
2-
when not defined(js) and not defined(nimdoc):
2+
when not defined(js):
33
{.fatal: "Module jsxmlserializer is designed to be used with the JavaScript backend.".}
44

55
from std/dom import Node

src/fusion/matching.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,7 @@ macro match*(n: untyped): untyped =
21542154
# `mixinList`
21552155
`pos`
21562156
let expr {.inject.} = `head`
2157-
let pos {.inject.}: int = 0
2157+
let pos {.inject, used.}: int = 0
21582158
`matchcase`
21592159

21602160
# echo result.repr

tests/config.nims

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
switch("path", "$projectDir/../src")
2+
switch("styleCheck", "hint")

tests/tmatching.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import std/[strutils, sequtils, strformat, sugar,
2-
macros, options, tables, json, algorithm]
2+
macros, options, tables, json]
33

44
import fusion/matching
55
{.experimental: "caseStmtMacros".}
6+
{.push hint[XDeclaredButNotUsed]: off.}
7+
{.push hint[ConvFromXtoItselfNotNeeded]: off.}
8+
{.push hint[CondTrue]: off.}
69

710
import unittest
811

0 commit comments

Comments
 (0)