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

69
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
* @param def - A default value
*/
declare function prompt(text: string, def?: string): string
/** /**
* Prompt a user for text input * Prompt a user for text input
* *
* @param text - The text to display for the prompt * @param text - The text to display for the prompt
* @param def - A default value * @param def - A default value
*/ */
declare function promptBoolean(text: string, def?: boolean): boolean string(text: string, def?: string): string
/** /**
* Renders a template * Prompt a user for text input
* *
* @param name - The template name * @param text - The text to display for the prompt
* @param context - The template context * @param def - A default value
*/ */
declare function render(name: string, context: any): string boolean(text: string, def?: boolean): boolean
/** }
* Write a string to a file
*
* @param input - The content of the file
* @param output - The output path
*/
declare function write(input: string, output: string): void
/** /**
* Copy a file * Renders a template
* *
* @param input - The input path * @param name - The template name
* @param output - The output path * @param context - The template context
*/ * @param output - The output path, if absent, default to the template name
declare function copy(input: string, output: string): void */
declare function render(name: string, context: any, output?: string): string
/**
* Copy a file
*
* @param input - The input path
* @param output - The output path, if absent, default to the input 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)