forked from ScalablyTyped/Converter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle globs properly (ScalablyTyped#638)
- Loading branch information
Showing
8 changed files
with
150 additions
and
151 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...er-portable/src/main/scala/org/scalablytyped/converter/internal/importer/GlobWalker.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.scalablytyped.converter.internal.importer | ||
|
||
import geny.Generator | ||
import org.scalablytyped.converter.internal.IArray | ||
|
||
import java.nio.file.FileSystems | ||
import scala.util.Try | ||
|
||
object GlobWalker { | ||
|
||
/** | ||
* Traverses the base directory and returns all files that match a given glob. | ||
* | ||
* Only returns files, not directories. If a directory matches a glob then all its descendents are included. | ||
* | ||
* @see the glob syntax in [[java.nio.file.FileSystem#getPathMatcher]] | ||
*/ | ||
def walkFiles(baseDirectory: os.Path, globs: IArray[String]): IndexedSeq[os.Path] = { | ||
val pathOrMatchers = globs.map { glob => | ||
Try(FileSystems.getDefault.getPathMatcher(s"glob:$glob")).toOption.toRight(baseDirectory / glob) | ||
} | ||
|
||
def matches(path: os.Path) = { | ||
val relativePath = path.relativeTo(baseDirectory) | ||
pathOrMatchers.exists { | ||
case Left(invalidGlob) => invalidGlob.toString == relativePath.toString | ||
case Right(matcher) => matcher.matches(relativePath.toNIO) | ||
} | ||
} | ||
|
||
val builder = IndexedSeq.newBuilder[os.Path] | ||
|
||
def processDirectoryAndSkip(dir: os.Path): Boolean = { | ||
if (matches(dir)) { | ||
os.walk.stream(dir).generate { path => | ||
if (path.toIO.isFile) builder += path | ||
Generator.Continue | ||
} | ||
true | ||
} else false | ||
} | ||
|
||
os.walk.stream(baseDirectory, processDirectoryAndSkip).generate { path => | ||
if (path.toIO.isFile && matches(path)) builder += path | ||
Generator.Continue | ||
} | ||
|
||
builder.result() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
tests/stripe/check-3/s/stripe-js/src/main/scala/typings/stripeJs/distPureMod.scala
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
tests/stripe/check-3/s/stripe-js/src/main/scala/typings/stripeJs/distSharedMod.scala
This file was deleted.
Oops, something went wrong.
94 changes: 0 additions & 94 deletions
94
tests/stripe/check-3/s/stripe-js/src/main/scala/typings/stripeJs/distStripeJsStripeMod.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters