Skip to content

Commit b6f0ca3

Browse files
committed
Added support for pre-req and some clean-up
1 parent fdb058d commit b6f0ca3

File tree

8 files changed

+55
-22
lines changed

8 files changed

+55
-22
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ Configure the parameters for your hands-on tutorial using a JSON configuration f
1616
"title": "Introduction to Ktor",
1717
"projectName": "introduction-to-ktor",
1818
"pathHandsOn": "./hands-on",
19-
"pathProject": "./hands-on-project"
19+
"pathProject": "./hands-on-project",
20+
"pre": [
21+
{
22+
"text": "How to set up a project",
23+
"link": "https://play.kotlinlang.org/hands-on/how-to"
24+
},
25+
{
26+
"text": "How to start a server",
27+
"link": "https://play.kotlinlang.org/hands-on/start-server"
28+
}
29+
]
2030
}
2131
```
2232

@@ -37,3 +47,4 @@ You can binaries on the [Releases](https://github.com/kotlin-hands-on/hands-on-i
3747

3848
Apache 2.0
3949

50+

src/macosMain/kotlin/com/jetbrains/handson/handson/init/Configuration.kt

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,16 @@ package com.jetbrains.handson.handson.init
33
import kotlinx.serialization.Serializable
44

55
@Serializable
6-
data class Configuration(val title: String, val projectName: String, val pathHandsOn: String, val pathProject: String)
6+
data class Configuration(
7+
val title: String,
8+
val projectName: String,
9+
val pathHandsOn: String,
10+
val pathProject: String,
11+
val pre: List<PreRequisite>
12+
)
13+
14+
@Serializable
15+
data class PreRequisite(
16+
val text: String,
17+
val link: String
18+
)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.jetbrains.handson.handson.init
22

33
import kotlinx.cinterop.toKString
4-
import platform.posix.errno
54
import platform.posix.strerror
65

76
class FileIOException(errorCode: Int) : Throwable(strerror(errorCode)?.toKString() ?: "Error: $errorCode")

src/macosMain/kotlin/com/jetbrains/handson/handson/init/HandsOnInitiator.kt

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.jetbrains.handson.handson.init
22

3+
import kotlinx.serialization.PrimitiveKind
4+
35
class HandsOnInitiator(private val configuration: Configuration) {
46
private val fileIO = FileIO()
57

@@ -30,7 +32,7 @@ class HandsOnInitiator(private val configuration: Configuration) {
3032
fileIO.createFile("${configuration.pathProject}/${configuration.projectName}/LICENSE", generateLicenseContent())
3133
}
3234

33-
fun createGitIngoreFile() {
35+
fun createGitIgnoreFile() {
3436
println("\nCreating .gitignore file")
3537
fileIO.createFile("${configuration.pathProject}/${configuration.projectName}/.gitignore", generateGitIgnoreContent())
3638
}
@@ -259,8 +261,23 @@ class HandsOnInitiator(private val configuration: Configuration) {
259261
"This repository is the code corresponding to the hands-on lab [${configuration.title}](https://play.kotlinlang.org/hands-on/${configuration.title.replace(" ", "%%20")}/01_Introduction). \n"
260262
}
261263

264+
private fun generatePrerequisites(): String {
265+
var topics = ""
266+
configuration.pre.forEach {
267+
topics += "* [${it.text}](${it.link})\n"
268+
}
269+
270+
return "This tutorial assumes that you're already familiar with the following topics:\n" +
271+
"\n" +
272+
topics +
273+
"\n"
274+
}
275+
262276
private fun generateIntroductionContent(): String {
277+
val prereq = generatePrerequisites()
263278
return "# Introduction\n" +
279+
"\n" +
280+
prereq +
264281
"\n" +
265282
"TODO - Provide introduction here" +
266283
"\n" +

src/macosMain/kotlin/com/jetbrains/handson/handson/init/HandsOnInitiatorException.kt

-4
This file was deleted.

src/macosMain/kotlin/com/jetbrains/handson/handson/init/Main.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ fun main(args: Array<String>) {
1010
println("\n usage: hands-on-init {config.json}")
1111
exitProcess(-1)
1212
}
13-
1413
val configurationFile = ConfigurationFile()
1514
try {
1615
val config = configurationFile.load(args[0])
1716
val handsOnInitiator = HandsOnInitiator(config)
1817
handsOnInitiator.createFolderStructure()
1918
handsOnInitiator.createMarkdownFiles()
2019
handsOnInitiator.createLicenseFile()
21-
handsOnInitiator.createGitIngoreFile()
20+
handsOnInitiator.createGitIgnoreFile()
2221
handsOnInitiator.outputInstructions()
2322
} catch (e: Exception) {
2423
printErrorMessage(e)

src/macosMain/resources/config.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,15 @@
22
"title": "Introduction to Ktor",
33
"projectName": "introduction-to-ktor",
44
"pathHandsOn": "./hands-on",
5-
"pathProject": "./"
5+
"pathProject": "./",
6+
"pre": [
7+
{
8+
"text": "How to set up a project",
9+
"link": "https://play.kotlinlang.org/hands-on/how-to"
10+
},
11+
{
12+
"text": "How to start a server",
13+
"link": "https://play.kotlinlang.org/hands-on/start-server"
14+
}
15+
]
616
}

src/macosTest/kotlin/com/jetbrains/handson/handson/init/SampleTests.kt

-11
This file was deleted.

0 commit comments

Comments
 (0)