Exit Full View

Feather2 / feather2-foocad / src / main / kotlin / uk.co.nickthecoder / feather / foocad / CompileExtensions.kt

package uk.co.nickthecoder.feather.foocad

import uk.co.nickthecoder.feather.core.*
import java.io.File

object CompileExtensions {

    @JvmStatic
    fun main(vararg args: String) {
        enableDebugging(true)
        val results = compileExtensions()
        println("Compiled class count : ${results.allClassNames.size}")
    }

    fun compileExtensions(): CompilationResults {
        val compiler = FeatherCompiler(createConfig())
        val files = collectExtensions()
        val results = compiler.compile(files.map { FileFeatherScript(it) })
        return results
    }

    private fun collectExtensions(): List<File> {
        val result = mutableListOf<File>()
        fun add(dir: File) {
            dir.listFiles { file: File -> file.extension == "feather" }?.let {
                result.addAll(it)
            }
            dir.listFiles { file: File -> file.isDirectory }?.let {
                for (subDir in it) {
                    add(subDir)
                }
            }
        }
        add(File("/home/nick/projects/foocad/src/dist/extensions/uk.co.nickthecoder.foocad"))

        return result
    }

    fun createConfig() = FeatherConfiguration().apply {
        val base = "uk.co.nickthecoder.foocad"
        val core = "$base.core"
        val build = "$base.build"

        featherVersion = 1

        sandbox = PermissiveSandbox
        with(impliedImportPackages) {
            add(base)
            add("$base.target")

            add(core)
            add("$core.primitives")
            add("$core.transformations")
            add("$core.compounds")
            add("$core.util")

            add("$base.build")
            add("$base.extension")

            add("java.util")
        }

        with(impliedImportStaticClasses) {
            add("$core.primitives.Text")
            add("$core.primitives.FontNames")
            add("$core.primitives.HAlignment")
            add("$core.primitives.VAlignment")
            add("$core.primitives.TextDirection")
            add("$core.compounds.Cavity")
            add("$core.util.Eases")
            add("$build.util.Helper")
            //add("$build.SlicerSettings") // TODO Remove?

            // println will end up using Log.println instead, so messages will go into the log.
            //remove("uk.co.nickthecoder.feather.runtime.Print")
            //add("$core.util.Log")

        }
    }
}