Skip to content

Commit

Permalink
build,compiler,js: add new jsProps option to BuildPod.
Browse files Browse the repository at this point in the history
This option allows you to explictily configure file/directories
for inclusion when compiling to javascript. The default behavior is
to compiling all .props files found in resDirs.
  • Loading branch information
Matthew Giannini authored and Matthew Giannini committed Mar 18, 2024
1 parent 576ea0d commit 25fd019
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
42 changes: 25 additions & 17 deletions src/build/fan/BuildPod.fan
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ abstract class BuildPod : BuildScript
**
Uri[]? jsDirs

**
** List of Uris relative to build script that should be searched for '.props'
** files to compile to JavaScript. You may also give relative paths to files
** with a '.props' ext. If this field is null, it defaults to `resDirs`.
**
Uri[]? jsProps

**
** The directory to look in for the dependency pod file (and
** potentially their recursive dependencies). If null then we
Expand Down Expand Up @@ -270,23 +277,24 @@ abstract class BuildPod : BuildScript

// map my config to CompilerInput structure
ci := CompilerInput()
ci.inputLoc = Loc.makeFile(scriptFile)
ci.podName = podName
ci.summary = summary
ci.version = version
ci.depends = depends.map |s->Depend| { Depend(applyMacros(s)) }
ci.meta = meta
ci.index = index
ci.baseDir = scriptDir
ci.srcFiles = srcDirs
ci.resFiles = resDirs
ci.jsFiles = jsDirs
ci.log = log
ci.includeDoc = docApi
ci.includeSrc = docSrc
ci.mode = CompilerInputMode.file
ci.outDir = outPodDir.toFile
ci.output = CompilerOutputMode.podFile
ci.inputLoc = Loc.makeFile(scriptFile)
ci.podName = podName
ci.summary = summary
ci.version = version
ci.depends = depends.map |s->Depend| { Depend(applyMacros(s)) }
ci.meta = meta
ci.index = index
ci.baseDir = scriptDir
ci.srcFiles = srcDirs
ci.resFiles = resDirs
ci.jsFiles = jsDirs
ci.jsPropsFiles = jsProps ?: resDirs
ci.log = log
ci.includeDoc = docApi
ci.includeSrc = docSrc
ci.mode = CompilerInputMode.file
ci.outDir = outPodDir.toFile
ci.output = CompilerOutputMode.podFile

if (dependsDir != null)
{
Expand Down
1 change: 1 addition & 0 deletions src/compiler/fan/Compiler.fan
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Compiler
File[]? srcFiles // InitInput
File[]? resFiles // InitInput
File[]? jsFiles // InitInput
File[]? jsPropsFiles // InitInput
TypeDef[]? types // Parse
ClosureExpr[]? closures // Parse
Str:CField wrappers // ClosureVars
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/fan/CompilerInput.fan
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ class CompilerInput
**
Uri[]? jsFiles

**
** List of files or directores containing '.props' files that should
** be compiled to JavaScript. If this field is null then it defaults
** to `resFiles`. Uris are relative to `baseDir`.
** This field is used only in file mode.
**
Uri[]? jsPropsFiles

//////////////////////////////////////////////////////////////////////////
// CompilerInputMode.str
//////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/fan/steps/CompileJs.fan
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CompileJs : CompilerStep
if (compiler.input.forceJs) return true

// are there any props files that need to be written to JS?
if (compiler.resFiles?.any |file| { file.ext == "props" } ?: false) return true
if (compiler.jsPropsFiles != null && !compiler.jsPropsFiles.isEmpty) return true

// run JS compiler if any type has @Js facet
return compiler.types.any { it.hasFacet("sys::Js") }
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/fan/steps/InitInput.fan
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ class InitInput : CompilerStep
if (input.mode !== CompilerInputMode.file) return

// map pod facets to src/res files
compiler.srcFiles = findFiles(input.srcFiles, "fan")
compiler.resFiles = findFiles(input.resFiles, null)
compiler.jsFiles = findFiles(input.jsFiles, "js")
compiler.srcFiles = findFiles(input.srcFiles, "fan")
compiler.resFiles = findFiles(input.resFiles, null)
compiler.jsFiles = findFiles(input.jsFiles, "js")
compiler.jsPropsFiles = findFiles(input.jsPropsFiles, "props")

if (compiler.srcFiles.isEmpty && compiler.resFiles.isEmpty)
throw err("No fan source files found", input.inputLoc)
Expand Down
2 changes: 1 addition & 1 deletion src/compilerEs/fan/ast/JsPod.fan
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class JsPod : JsNode
baseDir := c.input.baseDir
if (baseDir != null)
{
c.resFiles?.each |file|
c.jsPropsFiles?.each |file|
{
if (file.ext != "props") return
uri := file.uri.relTo(baseDir.uri)
Expand Down
2 changes: 1 addition & 1 deletion src/compilerJs/fan/ast/JsPod.fan
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class JsPod : JsNode
baseDir := s.compiler.input.baseDir
if (baseDir != null)
{
s.compiler.resFiles?.each |file|
s.compiler.jsPropsFiles?.each |file|
{
if (file.ext != "props") return
uri := file.uri.relTo(baseDir.uri)
Expand Down

0 comments on commit 25fd019

Please sign in to comment.