Skip to content

Commit

Permalink
update to org
Browse files Browse the repository at this point in the history
  • Loading branch information
beuluis committed Aug 27, 2023
1 parent c8a5e2f commit 212e190
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/config/buildInQuestions.ts
Original file line number Diff line number Diff line change
@@ -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' {
Expand Down
6 changes: 3 additions & 3 deletions src/helper/AfterHookHelper.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/helper/HookHelper.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
24 changes: 12 additions & 12 deletions src/helper/PromptHelper.ts
Original file line number Diff line number Diff line change
@@ -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<Answers>) {
// 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<typeof inquirer['registerPrompt']>) {
public registerPrompt(...args: Parameters<(typeof inquirer)['registerPrompt']>) {
this.inquirer.registerPrompt(...args);
}

Expand Down Expand Up @@ -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<Answers>) {
// 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[] = [];
}
18 changes: 9 additions & 9 deletions src/helper/TemplateHelper.ts
Original file line number Diff line number Diff line change
@@ -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<Liquid['registerTag']>) {
this.liquid.registerTag(...args);
public async parseAndRender(...args: Parameters<Liquid['parseAndRender']>) {
return await this.liquid.parseAndRender(...args);
}

/**
Expand All @@ -25,10 +25,10 @@ export class TemplateHelper {
}

/**
* Renders a string with values
* Register a new tag
*/
public async parseAndRender(...args: Parameters<Liquid['parseAndRender']>) {
return await this.liquid.parseAndRender(...args);
public registerTag(...args: Parameters<Liquid['registerTag']>) {
this.liquid.registerTag(...args);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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';
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/inquirer.ts
Original file line number Diff line number Diff line change
@@ -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<DistinctQuestion, 'name'>;
2 changes: 1 addition & 1 deletion src/util/helper.util.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down

0 comments on commit 212e190

Please sign in to comment.