34 lines
1.0 KiB
Kotlin
34 lines
1.0 KiB
Kotlin
package scaffold.commands
|
|
|
|
import com.github.ajalt.clikt.core.CliktCommand
|
|
import com.github.ajalt.clikt.core.ProgramResult
|
|
import com.github.ajalt.clikt.parameters.arguments.argument
|
|
import scaffold.Generators
|
|
import java.nio.file.Files
|
|
|
|
class NewCommand(private val generators: Generators) : CliktCommand("new") {
|
|
private val name by argument()
|
|
|
|
override fun run() {
|
|
val root = generators.configDirectory.resolve(name)
|
|
|
|
if (Files.exists(root)) {
|
|
echo("Generator already exists")
|
|
throw ProgramResult(1)
|
|
}
|
|
|
|
Files.createDirectories(root)
|
|
|
|
fun resource(path: String) = javaClass.getResource("/$path").readText()
|
|
|
|
Files.writeString(root.resolve("index.js"), resource("init/index.js"))
|
|
Files.writeString(root.resolve("index.d.ts"), resource("init/index.d.ts"))
|
|
|
|
val tree = root.resolve("tree")
|
|
Files.createDirectory(tree)
|
|
|
|
Files.writeString(tree.resolve("README.md"), resource("init/README.md"))
|
|
|
|
echo("Generator created in $root")
|
|
}
|
|
} |