Skip to content

Commit

Permalink
refactor: further updates
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbutt committed Feb 12, 2024
1 parent e401a48 commit 0dc9d2c
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 58 deletions.
53 changes: 5 additions & 48 deletions src/generators/TypescriptGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from "node:path";
import util from "node:util";
import { fileURLToPath } from "node:url";
import chalk from "chalk";
import { PromptQuestion } from "@yeoman/types";
Expand All @@ -23,30 +22,11 @@ import { NodeEnvironment } from "../environments/index.js";
export class TypescriptGenerator implements GeneratorInterface {
private readonly generator: AppGenerator;
private readonly name = TypescriptGenerator.getSignature().name;

// private readonly questions = [
// ProjectName,
// ProjectId,
// ProjectDescription,
// Git,
// PackageManager,
// ];
private readonly questions: Array<PromptQuestion<Answers>> = [];

public constructor(generator: AppGenerator) {
this.generator = generator;
this.generator.options.node = new NodeEnvironment();

// if (this.generator.options.skipPrompts) {
// const config = ConfigHelper.getInstance().getConfig();
// const { pkgmanager } = config.environments.node;

// this.generator.options.pkg = pkgmanager.default;

// // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment.
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
// this.generator.env.options.nodePackageManager = pkgmanager.default;
// }
}

public async initialize(): Promise<void> {
Expand Down Expand Up @@ -79,11 +59,6 @@ export class TypescriptGenerator implements GeneratorInterface {
}

public async prompting(): Promise<void> {
// const questions = this.questions.map((Question) =>
// new Question(this.generator).getQuestion(),
// );
console.log("Prompting");

const answers = await this.generator.prompt<Answers>(
this.questions.map((q) => {
return {
Expand All @@ -97,42 +72,24 @@ export class TypescriptGenerator implements GeneratorInterface {
}

private updateOptions(answers: Answers): void {
console.log("Updating");
console.log("Answers:");
console.log(
util.inspect(answers, {
showHidden: false,
depth: null,
colors: true,
}),
);

console.log("Current Options:");
console.log(
util.inspect(this.generator.options, {
showHidden: false,
depth: null,
colors: true,
}),
);

this.generator.options.type =
this.generator.options.type || answers.type;

this.generator.options.name =
this.generator.options.name || answers.name;

this.generator.options.id = this.generator.options.id || answers.id;

this.generator.options.description =
this.generator.options.description || answers.description;
this.generator.options.description || answers.description || "";

this.generator.options.git = this.generator.options.git || answers.git;
this.generator.options.pkg = this.generator.options.pkg || answers.pkg;

// @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment.
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
this.generator.env.options.nodePackageManager =
this.generator.options.pkg || answers.pkg;

// this.generator.options.displayName =
// this.generator.options.displayName || answers.displayName;
}

private getFilePaths(): Array<PathMap> {
Expand Down
5 changes: 4 additions & 1 deletion src/questions/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export class Git extends BaseQuestion {
constructor(generator: AppGenerator) {
super(generator);

if (!this.generator.options.git && this.generator.options.skipPrompts) {
if (
this.generator.options.git === undefined &&
this.generator.options.skipPrompts
) {
this.generator.options.git = this.getDefault();
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/questions/ProjectDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class ProjectDescription extends BaseQuestion {
super(generator);

if (
!this.generator.options.description &&
this.generator.options.description === undefined &&
this.generator.options.skipPrompts
) {
this.generator.options.description = this.getDefault();
Expand All @@ -24,8 +24,10 @@ export class ProjectDescription extends BaseQuestion {
type: "input",
name: "description",
message: "What's the description of your project?",
default: this.generator.options.description,
when: !this.generator.options.skipPrompts,
default: this.getDefault(),
when:
this.generator.options.description === undefined &&
!this.generator.options.skipPrompts,
};
}
}
Loading

0 comments on commit 0dc9d2c

Please sign in to comment.