@@ -20,7 +20,8 @@ package io.viash.config.resources
2020import java .net .URI
2121import io .viash .config .arguments .Argument
2222import io .viash .config .Config
23- import io .viash .language .Language
23+ import io .viash .languages .Language
24+ import io .viash .languages .{Bash , Python , R , JavaScript , Nextflow , Scala , CSharp }
2425
2526trait Script extends Resource {
2627 val language : Language
@@ -37,7 +38,7 @@ trait Script extends Resource {
3738 val mods = generateInjectionMods(argsMetaAndDeps, config)
3839
3940 val viashLines = Array (
40- companion .commentStr + " The following code has been auto-generated by Viash." ,
41+ language .commentStr + " The following code has been auto-generated by Viash." ,
4142 mods.params
4243 )
4344
@@ -55,9 +56,9 @@ trait Script extends Resource {
5556 viashLinesWDelimiter ++
5657 lines.slice(endIndex, lines.length)
5758 } else {
58- Array (companion .commentStr + companion .commentStr + " VIASH START" ) ++
59+ Array (language .commentStr + language .commentStr + " VIASH START" ) ++
5960 viashLines ++
60- Array (companion .commentStr + companion .commentStr + " VIASH END" ) ++
61+ Array (language .commentStr + language .commentStr + " VIASH END" ) ++
6162 lines
6263 }
6364 val li2 =
@@ -82,15 +83,15 @@ trait Script extends Resource {
8283 li.mkString(" \n " )
8384 }
8485
85- def command (script : String ): String = (companion .executor :+ s " \" $script\" " ).mkString(" " )
86- def commandSeq (script : String ): Seq [String ] = companion .executor ++ Seq (script)
86+ def command (script : String ): String = (language .executor :+ s " \" $script\" " ).mkString(" " )
87+ def commandSeq (script : String ): Seq [String ] = language .executor ++ Seq (script)
8788}
8889
8990object Script {
9091 val languages = List (Bash , Python , R , JavaScript , Nextflow , Scala , CSharp )
9192 val extensions =
9293 languages
93- .map(x => (x.extension. toLowerCase, x ))
94+ .flatMap(lang => lang.extensions. map(ext => (ext. toLowerCase, lang) ))
9495 .toMap
9596
9697 def fromExt (extension : String ): Language = {
@@ -106,25 +107,26 @@ object Script {
106107 entrypoint : Option [String ] = None ,
107108 `type` : String
108109 ): Script = {
110+ val languageId = `type`.replaceAll(" _script$" , " " )
109111
110- if (`type` != NextflowScript .`type` )
112+ if (languageId != Nextflow .id )
111113 assert(entrypoint.isEmpty, message = s " Entrypoints are not (yet) supported for resources of type ${`type`}. " )
112114
113- `type` match {
114- case BashScript .`type` =>
115+ languageId match {
116+ case Bash .id =>
115117 BashScript (path = path, text = text, dest = dest, is_executable = is_executable, parent = parent)
116- case CSharpScript .`type` =>
118+ case CSharp .id =>
117119 CSharpScript (path = path, text = text, dest = dest, is_executable = is_executable, parent = parent)
118- case JavaScriptScript .`type` =>
120+ case JavaScript .id =>
119121 JavaScriptScript (path = path, text = text, dest = dest, is_executable = is_executable, parent = parent)
120- case NextflowScript .`type` =>
122+ case Nextflow .id =>
121123 assert(entrypoint.isDefined, " In a Nextflow script, the 'entrypoint' argument needs to be specified." )
122124 NextflowScript (path = path, text = text, dest = dest, is_executable = is_executable, parent = parent, entrypoint = entrypoint.get)
123- case PythonScript .`type` =>
125+ case Python .id =>
124126 PythonScript (path = path, text = text, dest = dest, is_executable = is_executable, parent = parent)
125- case RScript .`type` =>
127+ case R .id =>
126128 RScript (path = path, text = text, dest = dest, is_executable = is_executable, parent = parent)
127- case ScalaScript .`type` =>
129+ case Scala .id =>
128130 ScalaScript (path = path, text = text, dest = dest, is_executable = is_executable, parent = parent)
129131 }
130132 }
0 commit comments