Skip to content

Commit

Permalink
Fixed #606 & #604: Mill codegen unique to module
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Oct 14, 2023
1 parent b12b995 commit 5bd75e4
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 100 deletions.
104 changes: 36 additions & 68 deletions indigo-plugin/indigo-plugin/src/indigoplugin/IndigoGenerators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ import indigoplugin.generators.EmbedAseprite
* @param sources
* Accumulated source paths
*/
final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageName: String, sources: Seq[os.Path]) {
final case class IndigoGenerators(fullyQualifiedPackageName: String, sources: Seq[os.Path => Seq[os.Path]]) {

def toSources: Seq[os.Path] = sources
def toSourceFiles: Seq[File] = sources.map(_.toIO)

def withOutputDirectory(value: os.Path): IndigoGenerators =
this.copy(outDirectory = value)
def withOutputDirectory(value: File): IndigoGenerators =
this.copy(outDirectory = os.Path(value))
def withOutputDirectory(value: String): IndigoGenerators =
this.copy(outDirectory = os.Path(value))
def toSourcePaths(destination: os.Path): Seq[os.Path] = sources.flatMap(_(destination))
def toSourcePaths(destination: File): Seq[os.Path] = sources.flatMap(_(os.Path(destination)))
def toSourceFiles(destination: os.Path): Seq[File] = sources.flatMap(_(destination)).map(_.toIO)
def toSourceFiles(destination: File): Seq[File] = sources.flatMap(_(os.Path(destination))).map(_.toIO)

/** Set a fully qualified package names for your output sources, e.g. com.mycompany.generated.code */
def withPackage(packageName: String): IndigoGenerators =
Expand All @@ -42,8 +37,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
*/
def embedText(moduleName: String, file: os.Path): IndigoGenerators =
this.copy(
sources = sources ++
EmbedText.generate(outDirectory, moduleName, fullyQualifiedPackageName, file)
sources = sources :+
EmbedText.generate(moduleName, fullyQualifiedPackageName, file)
)

/** Embed raw text into a static variable.
Expand All @@ -55,8 +50,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
*/
def embedText(moduleName: String, file: File): IndigoGenerators =
this.copy(
sources = sources ++
EmbedText.generate(outDirectory, moduleName, fullyQualifiedPackageName, os.Path(file))
sources = sources :+
EmbedText.generate(moduleName, fullyQualifiedPackageName, os.Path(file))
)

/** Embed raw text into a static variable.
Expand All @@ -68,8 +63,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
*/
def embedText(moduleName: String, file: String): IndigoGenerators =
this.copy(
sources = sources ++
EmbedText.generate(outDirectory, moduleName, fullyQualifiedPackageName, os.RelPath(file).resolveFrom(os.pwd))
sources = sources :+
EmbedText.generate(moduleName, fullyQualifiedPackageName, os.RelPath(file).resolveFrom(os.pwd))
)

/** Embed a GLSL shader pair into a Scala module.
Expand Down Expand Up @@ -100,9 +95,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
validate: Boolean
): IndigoGenerators =
this.copy(
sources = sources ++
sources = sources :+
EmbedGLSLShaderPair.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
vertexShaderPath,
Expand Down Expand Up @@ -139,9 +133,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
validate: Boolean
): IndigoGenerators =
this.copy(
sources = sources ++
sources = sources :+
EmbedGLSLShaderPair.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.Path(vertexShaderPath),
Expand Down Expand Up @@ -178,9 +171,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
validate: Boolean
): IndigoGenerators =
this.copy(
sources = sources ++
sources = sources :+
EmbedGLSLShaderPair.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.RelPath(vertexShaderPath).resolveFrom(os.pwd),
Expand All @@ -202,9 +194,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
indigoAssets: IndigoAssets
): IndigoGenerators =
this.copy(
sources = sources ++
sources = sources :+
AssetListing.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
indigoAssets
Expand All @@ -223,9 +214,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
indigoOptions: IndigoOptions
): IndigoGenerators =
this.copy(
sources = sources ++
sources = sources :+
ConfigGen.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
indigoOptions
Expand Down Expand Up @@ -293,9 +283,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
/** Embed the data as a Scala 3 Enum. */
def asEnum(moduleName: String, file: os.Path): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
file,
Expand All @@ -308,9 +297,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
/** Embed the data as a Scala 3 Enum that extends some fully qualified module name. E.g. `com.example.MyData`. */
def asEnum(moduleName: String, file: os.Path, extendsFrom: String): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
file,
Expand All @@ -323,9 +311,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
/** Embed the data as a Scala 3 Enum. */
def asEnum(moduleName: String, file: File): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.Path(file),
Expand All @@ -338,9 +325,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
/** Embed the data as a Scala 3 Enum that extends some fully qualified module name. E.g. `com.example.MyData`. */
def asEnum(moduleName: String, file: File, extendsFrom: String): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.Path(file),
Expand All @@ -353,9 +339,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
/** Embed the data as a Scala 3 Enum. */
def asEnum(moduleName: String, file: String): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.RelPath(file).resolveFrom(os.pwd),
Expand All @@ -368,9 +353,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
/** Embed the data as a Scala 3 Enum that extends some fully qualified module name. E.g. `com.example.MyData`. */
def asEnum(moduleName: String, file: String, extendsFrom: String): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.RelPath(file).resolveFrom(os.pwd),
Expand All @@ -383,9 +367,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
/** Embed the data as a Map. */
def asMap(moduleName: String, file: os.Path): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
file,
Expand All @@ -398,9 +381,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
/** Embed the data as a Map. */
def asMap(moduleName: String, file: File): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.Path(file),
Expand All @@ -413,9 +395,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
/** Embed the data as a Map. */
def asMap(moduleName: String, file: String): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.RelPath(file).resolveFrom(os.pwd),
Expand Down Expand Up @@ -445,9 +426,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
*/
def asCustom(moduleName: String, file: os.Path)(present: List[List[DataType]] => String): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
file,
Expand Down Expand Up @@ -477,9 +457,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
*/
def asCustom(moduleName: String, file: File)(present: List[List[DataType]] => String): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.Path(file),
Expand Down Expand Up @@ -509,9 +488,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
*/
def asCustom(moduleName: String, file: String)(present: List[List[DataType]] => String): IndigoGenerators =
gens.copy(
sources = sources ++
sources = sources :+
EmbedData.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.RelPath(file).resolveFrom(os.pwd),
Expand All @@ -533,8 +511,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
*/
def embedAseprite(moduleName: String, file: os.Path): IndigoGenerators =
this.copy(
sources = sources ++
EmbedAseprite.generate(outDirectory, moduleName, fullyQualifiedPackageName, file)
sources = sources :+
EmbedAseprite.generate(moduleName, fullyQualifiedPackageName, file)
)

/** Embed Aseprite data in a module.
Expand All @@ -548,8 +526,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
*/
def embedAseprite(moduleName: String, file: File): IndigoGenerators =
this.copy(
sources = sources ++
EmbedAseprite.generate(outDirectory, moduleName, fullyQualifiedPackageName, os.Path(file))
sources = sources :+
EmbedAseprite.generate(moduleName, fullyQualifiedPackageName, os.Path(file))
)

/** Embed Aseprite data in a module.
Expand All @@ -563,9 +541,8 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
*/
def embedAseprite(moduleName: String, file: String): IndigoGenerators =
this.copy(
sources = sources ++
sources = sources :+
EmbedAseprite.generate(
outDirectory,
moduleName,
fullyQualifiedPackageName,
os.RelPath(file).resolveFrom(os.pwd)
Expand All @@ -577,18 +554,9 @@ final case class IndigoGenerators(outDirectory: os.Path, fullyQualifiedPackageNa
object IndigoGenerators {

val None: IndigoGenerators =
IndigoGenerators(os.Path("/tmp/indigo-build-null"), "", Seq())

def default(outputDirectory: os.Path, fullyQualifiedPackageName: String): IndigoGenerators =
IndigoGenerators(outputDirectory, fullyQualifiedPackageName, Seq())

def mill(fullyQualifiedPackageName: String): IndigoGenerators =
default(os.pwd / "out", fullyQualifiedPackageName)

def mill(outDirectory: os.Path, fullyQualifiedPackageName: String): IndigoGenerators =
default(outDirectory, fullyQualifiedPackageName)
IndigoGenerators("", Seq())

def sbt(sourceManagedDirectory: File, fullyQualifiedPackageName: String): IndigoGenerators =
default(os.Path(sourceManagedDirectory), fullyQualifiedPackageName)
def apply(fullyQualifiedPackageName: String): IndigoGenerators =
IndigoGenerators(fullyQualifiedPackageName, Seq())

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import scala.io.AnsiColor._
object AssetListing {

def generate(
outDir: os.Path,
moduleName: String,
fullyQualifiedPackage: String,
indigoAssets: IndigoAssets
): Seq[os.Path] = {
): os.Path => Seq[os.Path] = outDir => {

val toSafeName: (String, String) => String =
indigoAssets.rename.getOrElse(toDefaultSafeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import scala.util.matching.Regex
object ConfigGen {

def generate(
outDir: os.Path,
moduleName: String,
fullyQualifiedPackage: String,
indigoOptions: IndigoOptions
): Seq[os.Path] = {
): os.Path => Seq[os.Path] = outDir => {

val wd = outDir / Generators.OutputDirName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import indigoplugin.datatypes.Aseprite
object EmbedAseprite {

def generate(
outDir: os.Path,
moduleName: String,
fullyQualifiedPackage: String,
filePath: os.Path
): Seq[os.Path] = {
): os.Path => Seq[os.Path] = outDir => {

val asepriteJson =
if (!os.exists(filePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ object EmbedData {
// string is kept.
// Cells cannot be empty.
def generate(
outDir: os.Path,
moduleName: String,
fullyQualifiedPackage: String,
filePath: os.Path,
delimiter: String,
rowFilter: String => Boolean,
embedMode: Mode
): Seq[os.Path] = {
): os.Path => Seq[os.Path] = outDir => {

val lines =
if (!os.exists(filePath)) throw new Exception("Path to data file not found: " + filePath.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package indigoplugin.generators
object EmbedGLSLShaderPair {

def generate(
outDir: os.Path,
moduleName: String,
fullyQualifiedPath: String,
vertex: os.Path,
fragment: os.Path,
runValidator: Boolean
): Seq[os.Path] = {
): os.Path => Seq[os.Path] = outDir => {

val shaderFiles: Seq[os.Path] =
Seq(vertex, fragment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package indigoplugin.generators
object EmbedText {

def generate(
outDir: os.Path,
moduleName: String,
fullyQualifiedPackage: String,
filePath: os.Path
): Seq[os.Path] = {
): os.Path => Seq[os.Path] = outDir => {

val text =
if (!os.exists(filePath)) throw new Exception("Text file to embed not found: " + filePath.toString())
Expand Down
Loading

0 comments on commit 5bd75e4

Please sign in to comment.