@@ -22,6 +22,7 @@ final case class Inputs(
22
22
baseProjectName : String ,
23
23
mayAppendHash : Boolean ,
24
24
workspaceOrigin : Option [WorkspaceOrigin ],
25
+ enableMarkdown : Boolean ,
25
26
withRestrictedFeatures : Boolean
26
27
) {
27
28
@@ -31,7 +32,7 @@ final case class Inputs(
31
32
def singleFiles (): Seq [Inputs .SingleFile ] =
32
33
elements.flatMap {
33
34
case f : Inputs .SingleFile => Seq (f)
34
- case d : Inputs .Directory => Inputs .singleFilesFromDirectory(d)
35
+ case d : Inputs .Directory => Inputs .singleFilesFromDirectory(d, enableMarkdown )
35
36
case _ : Inputs .ResourceDirectory => Nil
36
37
case _ : Inputs .Virtual => Nil
37
38
}
@@ -52,7 +53,7 @@ final case class Inputs(
52
53
def flattened (): Seq [Inputs .SingleElement ] =
53
54
elements.flatMap {
54
55
case f : Inputs .SingleFile => Seq (f)
55
- case d : Inputs .Directory => Inputs .singleFilesFromDirectory(d)
56
+ case d : Inputs .Directory => Inputs .singleFilesFromDirectory(d, enableMarkdown )
56
57
case _ : Inputs .ResourceDirectory => Nil
57
58
case v : Inputs .Virtual => Seq (v)
58
59
}
@@ -110,7 +111,7 @@ final case class Inputs(
110
111
case elem : Inputs .OnDisk =>
111
112
val content = elem match {
112
113
case dirInput : Inputs .Directory =>
113
- Seq (" dir:" ) ++ Inputs .singleFilesFromDirectory(dirInput)
114
+ Seq (" dir:" ) ++ Inputs .singleFilesFromDirectory(dirInput, enableMarkdown )
114
115
.map(file => s " ${file.path}: " + os.read(file.path))
115
116
case resDirInput : Inputs .ResourceDirectory =>
116
117
// Resource changes for SN require relinking, so they should also be hashed
@@ -199,6 +200,10 @@ object Inputs {
199
200
extends OnDisk with SourceFile with Compiled {
200
201
lazy val path : os.Path = base / subPath
201
202
}
203
+ final case class MarkdownFile (base : os.Path , subPath : os.SubPath )
204
+ extends OnDisk with SourceFile {
205
+ lazy val path : os.Path = base / subPath
206
+ }
202
207
final case class Directory (path : os.Path ) extends OnDisk with Compiled
203
208
final case class ResourceDirectory (path : os.Path ) extends OnDisk
204
209
@@ -218,7 +223,10 @@ object Inputs {
218
223
final case class VirtualData (content : Array [Byte ], source : String )
219
224
extends Virtual
220
225
221
- def singleFilesFromDirectory (d : Inputs .Directory ): Seq [Inputs .SingleFile ] = {
226
+ def singleFilesFromDirectory (
227
+ d : Inputs .Directory ,
228
+ enableMarkdown : Boolean
229
+ ): Seq [Inputs .SingleFile ] = {
222
230
import Ordering .Implicits .seqOrdering
223
231
os.walk.stream(d.path, skip = _.last.startsWith(" ." ))
224
232
.filter(os.isFile(_))
@@ -229,6 +237,8 @@ object Inputs {
229
237
Inputs .ScalaFile (d.path, p.subRelativeTo(d.path))
230
238
case p if p.last.endsWith(" .sc" ) =>
231
239
Inputs .Script (d.path, p.subRelativeTo(d.path))
240
+ case p if p.last.endsWith(" .md" ) && enableMarkdown =>
241
+ Inputs .MarkdownFile (d.path, p.subRelativeTo(d.path))
232
242
}
233
243
.toVector
234
244
.sortBy(_.subPath.segments)
@@ -244,6 +254,7 @@ object Inputs {
244
254
case _ : Inputs .JavaFile => " java:"
245
255
case _ : Inputs .ScalaFile => " scala:"
246
256
case _ : Inputs .Script => " sc:"
257
+ case _ : Inputs .MarkdownFile => " md:"
247
258
}
248
259
Iterator (prefix, elem.path.toString, " \n " ).map(bytes)
249
260
case v : Inputs .Virtual =>
@@ -268,6 +279,7 @@ object Inputs {
268
279
baseProjectName : String ,
269
280
directories : Directories ,
270
281
forcedWorkspace : Option [os.Path ],
282
+ enableMarkdown : Boolean ,
271
283
withRestrictedFeatures : Boolean
272
284
): Inputs = {
273
285
@@ -313,7 +325,8 @@ object Inputs {
313
325
baseProjectName,
314
326
mayAppendHash = needsHash,
315
327
workspaceOrigin = Some (workspaceOrigin0),
316
- withRestrictedFeatures
328
+ enableMarkdown = enableMarkdown,
329
+ withRestrictedFeatures = withRestrictedFeatures
317
330
)
318
331
}
319
332
@@ -410,6 +423,7 @@ object Inputs {
410
423
else if (arg.endsWith(" .sc" )) Right (Seq (Script (dir, subPath)))
411
424
else if (arg.endsWith(" .scala" )) Right (Seq (ScalaFile (dir, subPath)))
412
425
else if (arg.endsWith(" .java" )) Right (Seq (JavaFile (dir, subPath)))
426
+ else if (arg.endsWith(" .md" )) Right (Seq (MarkdownFile (dir, subPath)))
413
427
else if (os.isDir(path)) Right (Seq (Directory (path)))
414
428
else if (acceptFds && arg.startsWith(" /dev/fd/" )) {
415
429
val content = os.read.bytes(os.Path (arg, cwd))
@@ -436,6 +450,7 @@ object Inputs {
436
450
javaSnippetList : List [String ],
437
451
acceptFds : Boolean ,
438
452
forcedWorkspace : Option [os.Path ],
453
+ enableMarkdown : Boolean ,
439
454
withRestrictedFeatures : Boolean
440
455
): Either [BuildException , Inputs ] = {
441
456
val validatedArgs : Seq [Either [String , Seq [Element ]]] =
@@ -457,6 +472,7 @@ object Inputs {
457
472
baseProjectName,
458
473
directories,
459
474
forcedWorkspace,
475
+ enableMarkdown,
460
476
withRestrictedFeatures
461
477
))
462
478
}
@@ -477,13 +493,14 @@ object Inputs {
477
493
javaSnippetList : List [String ] = List .empty,
478
494
acceptFds : Boolean = false ,
479
495
forcedWorkspace : Option [os.Path ] = None ,
496
+ enableMarkdown : Boolean = false ,
480
497
withRestrictedFeatures : Boolean
481
498
): Either [BuildException , Inputs ] =
482
499
if (
483
500
args.isEmpty && scriptSnippetList.isEmpty && scalaSnippetList.isEmpty && javaSnippetList.isEmpty
484
501
)
485
502
defaultInputs().toRight(new InputsException (
486
- " No inputs provided (expected files with .scala or .sc extensions, and / or directories)."
503
+ " No inputs provided (expected files with .scala, .sc, .java or .md extensions, and / or directories)."
487
504
))
488
505
else
489
506
forNonEmptyArgs(
@@ -498,22 +515,25 @@ object Inputs {
498
515
javaSnippetList,
499
516
acceptFds,
500
517
forcedWorkspace,
518
+ enableMarkdown,
501
519
withRestrictedFeatures
502
520
)
503
521
504
522
def default (): Option [Inputs ] =
505
523
None
506
524
507
- def empty (workspace : os.Path ): Inputs =
525
+ def empty (workspace : os.Path , enableMarkdown : Boolean ): Inputs =
508
526
Inputs (
509
527
elements = Nil ,
510
528
defaultMainClassElement = None ,
511
529
workspace = workspace,
512
530
baseProjectName = " project" ,
513
531
mayAppendHash = true ,
514
532
workspaceOrigin = None ,
533
+ enableMarkdown = enableMarkdown,
515
534
withRestrictedFeatures = false
516
535
)
517
536
518
- def empty (projectName : String ) = Inputs (Nil , None , os.pwd, projectName, false , None , false )
537
+ def empty (projectName : String ): Inputs =
538
+ Inputs (Nil , None , os.pwd, projectName, false , None , true , false )
519
539
}
0 commit comments