This commit is contained in:
Hubert Van De Walle 2021-04-03 22:40:56 +02:00
parent 8c50d1c727
commit bdc3deb8d1
2 changed files with 44 additions and 51 deletions

77
index.d.ts vendored
View File

@ -3,44 +3,41 @@
* *
* @param message * @param message
*/ */
declare function echo(message: string): void declare function echo(message: string): void
/** declare interface prompt {
* Prompt a user for text input
* /**
* @param text - The text to display for the prompt * Prompt a user for text input
* @param def - A default value *
*/ * @param text - The text to display for the prompt
declare function prompt(text: string, def?: string): string * @param def - A default value
*/
/** string(text: string, def?: string): string
* Prompt a user for text input
* /**
* @param text - The text to display for the prompt * Prompt a user for text input
* @param def - A default value *
*/ * @param text - The text to display for the prompt
declare function promptBoolean(text: string, def?: boolean): boolean * @param def - A default value
*/
/** boolean(text: string, def?: boolean): boolean
* Renders a template
* }
* @param name - The template name
* @param context - The template context /**
*/ * Renders a template
declare function render(name: string, context: any): string *
* @param name - The template name
/** * @param context - The template context
* Write a string to a file * @param output - The output path, if absent, default to the template name
* */
* @param input - The content of the file declare function render(name: string, context: any, output?: string): string
* @param output - The output path
*/ /**
declare function write(input: string, output: string): void * Copy a file
*
/** * @param input - The input path
* Copy a file * @param output - The output path, if absent, default to the input path
* */
* @param input - The input path declare function copy(input: string, output?: string): void
* @param output - The output path
*/
declare function copy(input: string, output: string): void

View File

@ -13,14 +13,12 @@ const files = [
"gradlew.bat", "gradlew.bat",
] ]
for (let file of files) { files.forEach(f => copy(f))
copy(file, file)
}
const projectName = prompt("Project name") const projectName = prompt.string("Project name")
const javaVersion = prompt("Java version", "15") const javaVersion = prompt.string("Java version", "15")
const basePackage = prompt("Base package") const basePackage = prompt.string("Base package")
const mainClassName = prompt("Main class", projectName) const mainClassName = prompt.string("Main class", projectName)
const mainClassNameWithPackage = `${basePackage}.${mainClassName}` const mainClassNameWithPackage = `${basePackage}.${mainClassName}`
@ -44,9 +42,7 @@ const templates = [
"buildSrc/src/main/kotlin/kotlin-convention.gradle.kts", "buildSrc/src/main/kotlin/kotlin-convention.gradle.kts",
] ]
for (let template of templates) { templates.forEach(t => render(t, ctx))
write(render(template, ctx), template)
}
const mainClassFile = "app/src/" + mainClassName + ".kt" const mainClassFile = "app/src/" + mainClassName + ".kt"
write(render("app/src/App.kt", ctx), mainClassFile) render("app/src/App.kt", ctx, mainClassFile)