1
+ import java .io .{File , BufferedWriter , FileWriter }
2
+ import scala .io .Source
3
+
4
+ object GenModulesJS {
5
+
6
+ private def uncommentJsExport (line : String ): String =
7
+ if (line.trim.startsWith(" //SCALATESTJS,NATIVE-ONLY " ))
8
+ line.substring(line.indexOf(" //SCALATESTJS,NATIVE-ONLY " ) + 26 )
9
+ else if (line.trim.startsWith(" //SCALATESTJS-ONLY " ))
10
+ line.substring(line.indexOf(" //SCALATESTJS-ONLY " ) + 19 )
11
+ else
12
+ line
13
+
14
+ private def transformLine (line : String ): String =
15
+ uncommentJsExport(line)
16
+
17
+ private def copyFile (sourceFile : File , destFile : File ): File = {
18
+ val destWriter = new BufferedWriter (new FileWriter (destFile))
19
+ try {
20
+ val lines = Source .fromFile(sourceFile).getLines.toList
21
+ var skipMode = false
22
+ for (line <- lines) {
23
+ if (line.trim == " // SKIP-SCALATESTJS,NATIVE-START" || line.trim == " // SKIP-SCALATESTJS-START" )
24
+ skipMode = true
25
+ else if (line.trim == " // SKIP-SCALATESTJS,NATIVE-END" || line.trim == " // SKIP-SCALATESTJS-END" )
26
+ skipMode = false
27
+ else if (! skipMode) {
28
+ destWriter.write(transformLine(line))
29
+ destWriter.newLine()
30
+ }
31
+ }
32
+ destFile
33
+ }
34
+ finally {
35
+ destWriter.flush()
36
+ destWriter.close()
37
+ println(" Copied " + destFile.getAbsolutePath)
38
+ }
39
+ }
40
+
41
+ private def copyDir (sourceDirName : String , packageDirName : String , targetDir : File , skipList : List [String ]): Seq [File ] = {
42
+ val packageDir = new File (targetDir, packageDirName)
43
+ packageDir.mkdirs()
44
+ val sourceDir = new File (sourceDirName)
45
+ sourceDir.listFiles.toList.filter(f => f.isFile && ! skipList.contains(f.getName) && (f.getName.endsWith(" .scala" ))).map { sourceFile =>
46
+ val destFile = new File (packageDir, sourceFile.getName)
47
+ if (! destFile.exists || sourceFile.lastModified > destFile.lastModified)
48
+ copyFile(sourceFile, destFile)
49
+
50
+ destFile
51
+ }
52
+ }
53
+
54
+ /* def genScalaTestCompatible(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
55
+ copyDir("scalatest/src/main/java/org/scalatest/compatible", "org/scalatest/compatible", targetDir,List.empty)
56
+ }*/
57
+
58
+ def genScalaTestCore (targetDir : File , version : String , scalaVersion : String ): Seq [File ] = {
59
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
60
+ List (
61
+ " org/scalatest" ,
62
+ " org/scalatest/concurrent" ,
63
+ " org/scalatest/enablers" ,
64
+ " org/scalatest/exceptions" ,
65
+ " org/scalatest/events" ,
66
+ " org/scalatest/fixture" ,
67
+ " org/scalatest/prop" ,
68
+ " org/scalatest/tagobjects" ,
69
+ " org/scalatest/time" ,
70
+ " org/scalatest/tools" ,
71
+ " org/scalatest/verbs" ,
72
+ ).contains(packagePath)
73
+ }.flatMap { case (packagePath, skipList) =>
74
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir,
75
+ if (packagePath == " org/scalatest" || packagePath == " org/scalatest/fixture" ) skipList ++ List (" package.scala" ) else skipList)
76
+ }.toList ++
77
+ copyDir(" scalatest.js/src/main/scala/org/scalatest" , " org/scalatest" , targetDir, List .empty) ++
78
+ copyDir(" scalatest.js/src/main/scala/org/scalatest/compatible" , " org/scalatest/compatible" , targetDir, List .empty) ++
79
+ copyDir(" scalatest.js/src/main/scala/org/scalatest/concurrent" , " org/scalatest/concurrent" , targetDir, List .empty) ++
80
+ copyDir(" scalatest.js/src/main/scala/org/scalatest/exceptions" , " org/scalatest/exceptions" , targetDir, List .empty) ++
81
+ copyDir(" scalatest.js/src/main/scala/org/scalatest/tools" , " org/scalatest/tools" , targetDir, List .empty) ++
82
+ copyDir(" modules/jvm/scalatest-core/src/main/scala/org/scalatest" , " org/scalatest" , targetDir, List .empty) ++
83
+ copyDir(" modules/jvm/scalatest-core/src/main/scala/org/scalatest/fixture" , " org/scalatest/fixture" , targetDir, List .empty)
84
+ }
85
+
86
+ def genScalaTestFeatureSpec (targetDir : File , version : String , scalaVersion : String ): Seq [File ] =
87
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
88
+ List (
89
+ " org/scalatest/featurespec"
90
+ ).contains(packagePath)
91
+ }.flatMap { case (packagePath, skipList) =>
92
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
93
+ }.toList
94
+
95
+ def genScalaTestFlatSpec (targetDir : File , version : String , scalaVersion : String ): Seq [File ] =
96
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
97
+ List (
98
+ " org/scalatest/flatspec"
99
+ ).contains(packagePath)
100
+ }.flatMap { case (packagePath, skipList) =>
101
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
102
+ }.toList
103
+
104
+ def genScalaTestFreeSpec (targetDir : File , version : String , scalaVersion : String ): Seq [File ] =
105
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
106
+ List (
107
+ " org/scalatest/freespec"
108
+ ).contains(packagePath)
109
+ }.flatMap { case (packagePath, skipList) =>
110
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
111
+ }.toList
112
+
113
+ def genScalaTestFunSuite (targetDir : File , version : String , scalaVersion : String ): Seq [File ] =
114
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
115
+ List (
116
+ " org/scalatest/funsuite"
117
+ ).contains(packagePath)
118
+ }.flatMap { case (packagePath, skipList) =>
119
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
120
+ }.toList
121
+
122
+ def genScalaTestPropSpec (targetDir : File , version : String , scalaVersion : String ): Seq [File ] =
123
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
124
+ List (
125
+ " org/scalatest/propspec"
126
+ ).contains(packagePath)
127
+ }.flatMap { case (packagePath, skipList) =>
128
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
129
+ }.toList
130
+
131
+ def genScalaTestWordSpec (targetDir : File , version : String , scalaVersion : String ): Seq [File ] =
132
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
133
+ List (
134
+ " org/scalatest/wordspec"
135
+ ).contains(packagePath)
136
+ }.flatMap { case (packagePath, skipList) =>
137
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
138
+ }.toList
139
+
140
+ def genScalaTestDiagrams (targetDir : File , version : String , scalaVersion : String ): Seq [File ] =
141
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
142
+ List (
143
+ " org/scalatest/diagrams"
144
+ ).contains(packagePath)
145
+ }.flatMap { case (packagePath, skipList) =>
146
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
147
+ }.toList
148
+
149
+ def genScalaTestMatchersCore (targetDir : File , version : String , scalaVersion : String ): Seq [File ] =
150
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
151
+ List (
152
+ " org/scalatest/matchers" ,
153
+ " org/scalatest/matchers/dsl"
154
+ ).contains(packagePath)
155
+ }.flatMap { case (packagePath, skipList) =>
156
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
157
+ }.toList
158
+
159
+ def genScalaTestShouldMatchers (targetDir : File , version : String , scalaVersion : String ): Seq [File ] =
160
+ GenScalaTestJS .genScalaPackages.filter { case (packagePath, skipList) =>
161
+ List (
162
+ " org/scalatest/matchers/should"
163
+ ).contains(packagePath)
164
+ }.flatMap { case (packagePath, skipList) =>
165
+ copyDir(" scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
166
+ }.toList
167
+ }
0 commit comments