diff --git a/src/config/buildInQuestions.ts b/src/config/buildInQuestions.ts index 40ab924..3126cec 100644 --- a/src/config/buildInQuestions.ts +++ b/src/config/buildInQuestions.ts @@ -1,5 +1,5 @@ -import spdxLicenseList from '@ovyerus/licenses'; import type { DistinctQuestionModified } from '../shared/inquirer'; +import spdxLicenseList from '@ovyerus/licenses'; // declare module inquire to add the new question type declare module 'inquirer' { diff --git a/src/helper/AfterHookHelper.ts b/src/helper/AfterHookHelper.ts index 099979f..dcd3623 100644 --- a/src/helper/AfterHookHelper.ts +++ b/src/helper/AfterHookHelper.ts @@ -1,10 +1,8 @@ -import { blueBright } from 'colorette'; import type { AfterCreationHookOptions, HookHelperObject } from '../shared/create'; import { HookHelper } from './HookHelper'; +import { blueBright } from 'colorette'; export class AfterHookHelper extends HookHelper { - private readonly options: AfterCreationHookOptions; - public constructor( // Make the hook object available to have context hookHelperObject: HookHelperObject, @@ -36,4 +34,6 @@ export class AfterHookHelper extends HookHelper { await this.runCommand(`${this.options.packageManager}`, ['install']); console.log(blueBright('Dependencies installed')); } + + private readonly options: AfterCreationHookOptions; } diff --git a/src/helper/HookHelper.ts b/src/helper/HookHelper.ts index 20c04b2..45c6543 100644 --- a/src/helper/HookHelper.ts +++ b/src/helper/HookHelper.ts @@ -1,6 +1,6 @@ -import type { SpawnOptions } from 'child_process'; import type { HookHelperObject } from '../shared/create'; import { execute } from '../util/command.util'; +import type { SpawnOptions } from 'child_process'; export class HookHelper { public constructor( diff --git a/src/helper/PromptHelper.ts b/src/helper/PromptHelper.ts index c31eed0..40cb78e 100644 --- a/src/helper/PromptHelper.ts +++ b/src/helper/PromptHelper.ts @@ -1,20 +1,25 @@ +import type { DistinctQuestionModified } from '../shared/inquirer'; +import { logAndFail } from '../util/helper.util'; import { underline } from 'colorette'; import type { Answers } from 'inquirer'; import inquirer from 'inquirer'; -import type { DistinctQuestionModified } from '../shared/inquirer'; -import { logAndFail } from '../util/helper.util'; // Class for all interactive related stuff. Wrapper class to have a somewhat replaceable interface export class UIHelper { private inquirer = inquirer; - // Array of registered questions. Order in this array is order questions are being asked - private registeredQuestions: DistinctQuestionModified[] = []; + /** + * Prompts the user with registered questions in order. Will skip question if found in initialAnswers + */ + public async prompt(initialAnswers?: Partial) { + // Prompt the questions but skip based on initialAnswers + return await this.inquirer.prompt(this.registeredQuestions, initialAnswers); + } /** * Registers a new prompt type */ - public registerPrompt(...args: Parameters) { + public registerPrompt(...args: Parameters<(typeof inquirer)['registerPrompt']>) { this.inquirer.registerPrompt(...args); } @@ -47,11 +52,6 @@ export class UIHelper { } } - /** - * Prompts the user with registered questions in order. Will skip question if found in initialAnswers - */ - public prompt(initialAnswers?: Partial) { - // Prompt the questions but skip based on initialAnswers - return this.inquirer.prompt(this.registeredQuestions, initialAnswers); - } + // Array of registered questions. Order in this array is order questions are being asked + private registeredQuestions: DistinctQuestionModified[] = []; } diff --git a/src/helper/TemplateHelper.ts b/src/helper/TemplateHelper.ts index 9ee1ff9..166b05e 100644 --- a/src/helper/TemplateHelper.ts +++ b/src/helper/TemplateHelper.ts @@ -1,20 +1,20 @@ +import { defaultLiquidOptions } from '../config/defaultOptions'; import { Liquid } from 'liquidjs'; import type { LiquidOptions } from 'liquidjs/dist/liquid-options'; -import { defaultLiquidOptions } from '../config/defaultOptions'; // Class for all template related stuff. Wrapper class to have a somewhat replaceable interface export class TemplateHelper { - private readonly liquid: Liquid; - public constructor(options: LiquidOptions = {}) { this.liquid = new Liquid({ ...defaultLiquidOptions, ...options }); } + private readonly liquid: Liquid; + /** - * Register a new tag + * Renders a string with values */ - public registerTag(...args: Parameters) { - this.liquid.registerTag(...args); + public async parseAndRender(...args: Parameters) { + return await this.liquid.parseAndRender(...args); } /** @@ -25,10 +25,10 @@ export class TemplateHelper { } /** - * Renders a string with values + * Register a new tag */ - public async parseAndRender(...args: Parameters) { - return await this.liquid.parseAndRender(...args); + public registerTag(...args: Parameters) { + this.liquid.registerTag(...args); } /** diff --git a/src/index.ts b/src/index.ts index f909084..28ee035 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,3 @@ -import { existsSync } from 'fs'; -import { chmod, copyFile, mkdir, readdir, stat, writeFile } from 'fs/promises'; -import { resolve, dirname } from 'path'; -import { gray, green, underline } from 'colorette'; -import parseArgs from 'minimist'; import { buildInQuestions } from './config/buildInQuestions'; import { AfterHookHelper } from './helper/AfterHookHelper'; import { HookHelper } from './helper/HookHelper'; @@ -10,6 +5,11 @@ import { UIHelper } from './helper/PromptHelper'; import { TemplateHelper } from './helper/TemplateHelper'; import type { CreateOptions } from './shared/create'; import { getAllFiles, logAndFail } from './util/helper.util'; +import { gray, green, underline } from 'colorette'; +import { existsSync } from 'fs'; +import { chmod, copyFile, mkdir, readdir, stat, writeFile } from 'fs/promises'; +import parseArgs from 'minimist'; +import { dirname, resolve } from 'path'; export const create = async (options: CreateOptions) => { try { diff --git a/src/shared/inquirer.ts b/src/shared/inquirer.ts index 258e4a4..c9fbd55 100644 --- a/src/shared/inquirer.ts +++ b/src/shared/inquirer.ts @@ -1,5 +1,5 @@ -import type { DistinctQuestion } from 'inquirer'; import type { RequiredProperty } from './until'; +import type { DistinctQuestion } from 'inquirer'; // Make name required because we use it as identifier export type DistinctQuestionModified = RequiredProperty; diff --git a/src/util/helper.util.ts b/src/util/helper.util.ts index 23501a3..9b0d0b2 100644 --- a/src/util/helper.util.ts +++ b/src/util/helper.util.ts @@ -1,6 +1,6 @@ +import { red } from 'colorette'; import { readdir, stat } from 'fs/promises'; import { join } from 'path'; -import { red } from 'colorette'; // Helper function to print nice errors export const logAndFail = (error: string, trivia?: string): never => {