Skip to content

Commit

Permalink
Add filtering for PKGNAME (#4)
Browse files Browse the repository at this point in the history
* Add filtering for \@PKGNAME\@ token so pathing can be autogenerated at build time
* 0.3 release
  • Loading branch information
demonnic committed Aug 10, 2019
1 parent 38fb99f commit 7b436b8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Expand Up @@ -16,16 +16,14 @@ plugins {
id 'com.github.johnrengelman.shadow' version '5.0.0'

}
version = '0.2'
version = '0.3'
mainClassName = "muddler.App"

repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
version = '0.2-SNAPSHOT'
mainClassName = "muddler.App"

//jar {
// manifest {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>muddler</groupId>
<artifactId>muddler</artifactId>
<version>0.2-SNAPSHOT</version>
<version>0.3</version>
<inceptionYear>2019</inceptionYear>
<dependencies>
<dependency>
Expand Down
27 changes: 22 additions & 5 deletions src/main/groovy/muddler/App.groovy
Expand Up @@ -12,6 +12,7 @@ import java.util.regex.Pattern

class App {
static void main(String[] args) {
// read mfile and setup packageName and packageVersion
def file = new File('./mfile')
def packageName = ""
def packageVersion = "1.0"
Expand All @@ -24,6 +25,25 @@ class App {
def fullPath = System.properties['user.dir']
packageName = fullPath.split(Pattern.quote(File.separator))[-1]
}
// we will leberage Ant for token filtering and zip creation
def ant = new AntBuilder()
def outputDir = new File('build')
// all builds are clean builds. fight me.
outputDir.deleteDir()
def tmp = new File(outputDir, 'tmp')
tmp.mkdirs()
// filter our source files from src into build/filtered/src and replace @PKGNAME@ with the package name as used by Mudlet
// no more images failing to load because the package name changed or you bumped version
ant.copy(todir:'build/filtered/src') {
fileset(dir: "src/") {
exclude(name: "resources/")
}
filterset(){
filter(token: "PKGNAME", value: "$packageName-$packageVersion")
}
}

// now create the individual item type packages
def aliasP = new AliasPackage()
def scriptP = new ScriptPackage()
def timerP = new TimerPackage()
Expand All @@ -43,17 +63,14 @@ class App {
}
}
def mpXML = XmlUtil.serialize(mudletPackage)
def outputDir = new File('build')
outputDir.deleteDir()
def tmp = new File(outputDir, 'tmp')
tmp.mkdirs()

new File(outputDir,packageName + ".xml").withWriter { writer ->
writer.write(mpXML)
}
new File(tmp, 'config.lua').withWriter { writer ->
writer.write("mpackage = \"$packageName-$packageVersion\"")
}
def ant = new AntBuilder()

def resDir = new File("src${File.separator}resources")
if (resDir.exists()) {
ant.copy(toDir: 'build/tmp') {
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/muddler/mudlet/items/Item.groovy
Expand Up @@ -33,7 +33,7 @@ abstract class Item {

def readScripts(String itemType) {
if (this.script == "" && this.isFolder != "yes" ) {
def fullPath = "src${File.separator}$itemType${File.separator}${this.path}${File.separator}${this.name.replaceAll(" ", "_")}.lua"
def fullPath = "build/filtered/src${File.separator}$itemType${File.separator}${this.path}${File.separator}${this.name.replaceAll(" ", "_")}.lua"
def scriptFile = new File(fullPath)
if (scriptFile.exists()) {
this.script = scriptFile.text.normalize()
Expand Down
5 changes: 3 additions & 2 deletions src/main/groovy/muddler/mudlet/packages/Package.groovy
Expand Up @@ -13,7 +13,7 @@ abstract class Package {
abstract def newItem(Map options)

def Package(String packageType ) {
this.baseDir = new File("src/$packageType")
this.baseDir = new File("build/filtered/src/$packageType")
this.children = []
if (baseDir.exists()) {
this.files = this.findFiles()
Expand All @@ -38,7 +38,8 @@ abstract class Package {
def fullItemsAsArrays = []
this.files.each {
def fileArray = "${it}".split(Pattern.quote(File.separator)).toList()
def directoriesInPath = fileArray[2..-2]
// 4..-2 as we don't want to include build/filtered/src/$type
def directoriesInPath = fileArray[4..-2]
def filePath = directoriesInPath.join(File.separator)
def itemPayload = []
def itemArray = []
Expand Down

0 comments on commit 7b436b8

Please sign in to comment.