diff --git a/index.d.ts b/index.d.ts index b7fcb1f..913a6f1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,44 +3,41 @@ * * @param message */ -declare function echo(message: string): void + declare function echo(message: string): void -/** - * 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 - * - * @param text - The text to display for the prompt - * @param def - A default value - */ -declare function promptBoolean(text: string, def?: boolean): boolean - -/** - * Renders a template - * - * @param name - The template name - * @param context - The template context - */ -declare function render(name: string, context: any): string - -/** - * 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 - * - * @param input - The input path - * @param output - The output path - */ -declare function copy(input: string, output: string): void \ No newline at end of file + declare interface prompt { + + /** + * Prompt a user for text input + * + * @param text - The text to display for the prompt + * @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 + * @param def - A default value + */ + boolean(text: string, def?: boolean): boolean + + } + + /** + * Renders a template + * + * @param name - The template name + * @param context - The template context + * @param output - The output path, if absent, default to the template name + */ + 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 \ No newline at end of file diff --git a/index.js b/index.js index 40d9b8b..149ae33 100644 --- a/index.js +++ b/index.js @@ -13,14 +13,12 @@ const files = [ "gradlew.bat", ] -for (let file of files) { - copy(file, file) -} +files.forEach(f => copy(f)) -const projectName = prompt("Project name") -const javaVersion = prompt("Java version", "15") -const basePackage = prompt("Base package") -const mainClassName = prompt("Main class", projectName) +const projectName = prompt.string("Project name") +const javaVersion = prompt.string("Java version", "15") +const basePackage = prompt.string("Base package") +const mainClassName = prompt.string("Main class", projectName) const mainClassNameWithPackage = `${basePackage}.${mainClassName}` @@ -44,9 +42,7 @@ const templates = [ "buildSrc/src/main/kotlin/kotlin-convention.gradle.kts", ] -for (let template of templates) { - write(render(template, ctx), template) -} +templates.forEach(t => render(t, ctx)) const mainClassFile = "app/src/" + mainClassName + ".kt" -write(render("app/src/App.kt", ctx), mainClassFile) +render("app/src/App.kt", ctx, mainClassFile)