From 654705b56626fbdde4564a3d17e1fe54f1c1384c Mon Sep 17 00:00:00 2001 From: Damien Butt <22627489+damienbutt@users.noreply.github.com> Date: Sun, 11 Feb 2024 16:42:28 +0000 Subject: [PATCH] refactor: further updates --- src/@types/Answers.ts | 32 +++++++++---------- src/app.ts | 1 + src/helpers/CliHelper.ts | 50 +++++++++++++++++++----------- src/questions/Author.ts | 10 +++--- src/questions/Git.ts | 4 +-- src/questions/PackageManager.ts | 10 +++--- src/questions/ProjectId.ts | 6 ++-- src/questions/ProjectName.ts | 4 +-- templates/html/CONTRIBUTING.md.ejs | 2 +- tests/c.test.ts | 15 +++++++-- tests/html.test.ts | 41 +++++++++++++++--------- tests/javascript.test.ts | 36 +++++++++++++++------ tests/nodecli.test.ts | 36 +++++++++++++++------ tests/python.test.ts | 14 ++++++--- tests/simpl.test.ts | 36 +++++++++++++++------ tests/typescript.test.ts | 36 +++++++++++++++------ 16 files changed, 222 insertions(+), 111 deletions(-) diff --git a/src/@types/Answers.ts b/src/@types/Answers.ts index 8d5f9d5..55aacc4 100644 --- a/src/@types/Answers.ts +++ b/src/@types/Answers.ts @@ -1,34 +1,32 @@ import { NodePackageManager } from "./index.js"; export type Answers = { - type: string; - name: string; - id: string; - description: string; - author: string; - git: boolean; - pkg: NodePackageManager; - openWith: "code" | "skip"; -}; - -export type Answers2 = { // The project type type: string; - // The display name of the project - // Defaults to the folder name + // The name of the project + // This will be used as the directory name + // Will be taken from the 'destination' argument + // Defaults to the name of the CWD name: string; - // The name of the project - // Defaults to lowercased name - // with spaces replaced by dashes + // The id of the project + // This will be used as the package name + // Defaults to the name in kebab-case id: string; + + // The description of the project description: string; // The author of the project - // Defaults to the git user name author: string; + + // Whether to initialize a git repository git: boolean; + + // The package manager to use pkg: NodePackageManager; + + // Whether to open the project with VS Code openWith: "code" | "skip"; }; diff --git a/src/app.ts b/src/app.ts index fa8fb5e..08e0fae 100644 --- a/src/app.ts +++ b/src/app.ts @@ -29,6 +29,7 @@ class AppGenerator extends Generator { constructor(args: string | Array, options: AppOptions) { super(args, options); + CliHelper.initialize(ConfigHelper.getInstance().getConfig()); this._initializeCliArguments(); this._initializeCliOptions(); diff --git a/src/helpers/CliHelper.ts b/src/helpers/CliHelper.ts index c9561c7..3592c50 100644 --- a/src/helpers/CliHelper.ts +++ b/src/helpers/CliHelper.ts @@ -1,7 +1,14 @@ import { ArgumentSpec, CliOptionSpec } from "yeoman-generator"; import { GeneratorFactory } from "../generators/index.js"; +import { ResolvedConfig } from "../@types/index.js"; export class CliHelper { + private static config: ResolvedConfig; + + public static initialize(config: ResolvedConfig): void { + this.config = config; + } + public static getArguments(): Array<{ name: string; config: Partial; @@ -30,6 +37,12 @@ export class CliHelper { .map((signature) => signature.aliases[0]) .join(", ")}...`, }, + { + name: "id", + type: String, + alias: "i", + description: "Id of the project", + }, { name: "description", type: String, @@ -38,35 +51,36 @@ export class CliHelper { default: "", }, { - name: "yes", - type: Boolean, - alias: "y", - description: - "Quick mode, skip all optional prompts and use defaults", + name: "author", + type: String, + alias: "a", + description: "Author of the project", + default: "", }, { - name: "open", + name: "git", type: Boolean, - alias: "o", - description: "Open the generated project in Visual Studio Code", - }, - { - name: "id", - type: String, - description: "Id of the project", + alias: "g", + description: "Initialize a git repo", }, { name: "pkg", type: String, alias: "p", - description: - 'Package manager to use. Possible values: ["pnpm", "yarn", "npm"]', + description: `Package manager to use. Possible values: ${this.config.pkgmanager.node!.choices.join(", ")}`, }, { - name: "git", + name: "open", type: Boolean, - alias: "g", - description: "Initialize a git repo", + alias: "o", + description: "Open the generated project in Visual Studio Code", + }, + { + name: "yes", + type: Boolean, + alias: "y", + description: + "Quick mode, skip all optional prompts and use defaults", }, ]; } diff --git a/src/questions/Author.ts b/src/questions/Author.ts index a732a40..7e38e06 100644 --- a/src/questions/Author.ts +++ b/src/questions/Author.ts @@ -9,8 +9,8 @@ export class Author extends BaseQuestion { // this.generator.options.author = this.generator.git.name(); } - private getDefault(): boolean { - return true; + private getDefault(): string { + return ""; } public getQuestion(): PromptQuestion { @@ -18,8 +18,10 @@ export class Author extends BaseQuestion { type: "input", name: "author", message: "Who's the author of this project?", - default: this.generator.options.author, - when: !this.generator.options.skipPrompts, + default: this.getDefault(), + when: + !this.generator.options.author && + !this.generator.options.skipPrompts, }; } } diff --git a/src/questions/Git.ts b/src/questions/Git.ts index c64fa54..7000fef 100644 --- a/src/questions/Git.ts +++ b/src/questions/Git.ts @@ -6,7 +6,7 @@ import AppGenerator from "../app.js"; export class Git extends BaseQuestion { constructor(generator: AppGenerator) { super(generator); - this.generator.options.git = this.getDefault(); + // this.generator.options.git = this.getDefault(); } private getDefault(): boolean { @@ -18,7 +18,7 @@ export class Git extends BaseQuestion { type: "confirm", name: "git", message: "Initialize a git repository?", - default: this.generator.options.git, + default: this.getDefault(), when: !this.generator.options.skipPrompts, }; } diff --git a/src/questions/PackageManager.ts b/src/questions/PackageManager.ts index 79fc544..12e5019 100644 --- a/src/questions/PackageManager.ts +++ b/src/questions/PackageManager.ts @@ -15,8 +15,8 @@ export class PackageManager extends BaseQuestion { this.default = config.pkgmanager.node!.default; this.choices = config.pkgmanager.node!.choices; - this.generator.options.pkg = - this.generator.options.pkg || this.getDefault(); + // this.generator.options.pkg = + // this.generator.options.pkg || this.getDefault(); } private getDefault(): NodePackageManager { @@ -34,8 +34,10 @@ export class PackageManager extends BaseQuestion { value: choice, }; }), - default: this.generator.options.pkg, - when: !this.generator.options.skipPrompts, + default: this.getDefault(), + when: + !this.generator.options.pkg && + !this.generator.options.skipPrompts, }; } } diff --git a/src/questions/ProjectId.ts b/src/questions/ProjectId.ts index 725dfd7..ad704f0 100644 --- a/src/questions/ProjectId.ts +++ b/src/questions/ProjectId.ts @@ -8,9 +8,9 @@ export class ProjectId extends BaseQuestion { constructor(generator: AppGenerator) { super(generator); - this.generator.options.id = this.getDefault( - this.generator.options.name, - ); + // this.generator.options.id = this.getDefault( + // this.generator.options.name, + // ); } private getDefault(name: string): string { diff --git a/src/questions/ProjectName.ts b/src/questions/ProjectName.ts index 4bac13a..4a00180 100644 --- a/src/questions/ProjectName.ts +++ b/src/questions/ProjectName.ts @@ -7,7 +7,7 @@ import { BaseQuestion } from "./index.js"; export class ProjectName extends BaseQuestion { constructor(generator: AppGenerator) { super(generator); - this.generator.options.name = this.getDefault(); + // this.generator.options.name = this.getDefault(); } private getDefault(): string { @@ -21,7 +21,7 @@ export class ProjectName extends BaseQuestion { type: "input", name: "name", message: "What's the name of your project?", - default: this.generator.options.name, + default: this.getDefault(), when: !this.generator.options.name && !this.generator.options.skipPrompts, diff --git a/templates/html/CONTRIBUTING.md.ejs b/templates/html/CONTRIBUTING.md.ejs index c222408..fdb9f44 100644 --- a/templates/html/CONTRIBUTING.md.ejs +++ b/templates/html/CONTRIBUTING.md.ejs @@ -55,7 +55,7 @@ You can add yourself in one of two ways: > or -2. Run the `yarn contrib:add` command to add yourself to the contributors list. +2. Run the `<%- pkg %> contrib:add` command to add yourself to the contributors list. ```bash <%- pkg %> contrib:add ,,... diff --git a/tests/c.test.ts b/tests/c.test.ts index d76e1f9..d521f33 100644 --- a/tests/c.test.ts +++ b/tests/c.test.ts @@ -27,6 +27,7 @@ describe("generator-norgate-av:app", () => { name: "test", id: "test-id", description: "test-description", + author: "Yeoman", git: false, pkg: "pnpm", openWith: "skip", @@ -36,6 +37,7 @@ describe("generator-norgate-av:app", () => { name: "test", id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "yarn", openWith: "skip", @@ -45,13 +47,14 @@ describe("generator-norgate-av:app", () => { name: "test", id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "npm", openWith: "skip", }, ])( 'c with type $type, package manager $pkg, and git "$git"', - ({ type, name, id, description, git, pkg, openWith }) => { + ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; beforeAll(async () => { @@ -62,6 +65,7 @@ describe("generator-norgate-av:app", () => { name, id, description, + author, git, pkg, openWith, @@ -169,7 +173,6 @@ describe("generator-norgate-av:app", () => { assert.fileContent("CONTRIBUTING.md", `/${id}.git`); assert.fileContent("CONTRIBUTING.md", `cd ${id}`); assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent("CONTRIBUTING.md", `${pkg} contrib:add`); assert.fileContent( "CONTRIBUTING.md", `If in doubt, you can use the \`${pkg} commit\``, @@ -178,6 +181,14 @@ describe("generator-norgate-av:app", () => { "CONTRIBUTING.md", `Be sure to run \`${pkg} test\``, ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); }); it("should create the correct CHANGELOG.md", () => { diff --git a/tests/html.test.ts b/tests/html.test.ts index 9862731..14638d3 100644 --- a/tests/html.test.ts +++ b/tests/html.test.ts @@ -25,7 +25,9 @@ describe("generator-norgate-av:app", () => { { type: "html", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: false, pkg: "pnpm", openWith: "skip", @@ -33,7 +35,9 @@ describe("generator-norgate-av:app", () => { { type: "web", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "yarn", openWith: "skip", @@ -41,14 +45,16 @@ describe("generator-norgate-av:app", () => { { type: "vanilla", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "npm", openWith: "skip", }, ])( 'html with type $type, package manager $pkg, and git "$git"', - ({ type, name, description, git, pkg, openWith }) => { + ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; beforeAll(async () => { @@ -57,7 +63,9 @@ describe("generator-norgate-av:app", () => { .withAnswers({ type, name, + id, description, + author, git, pkg, openWith, @@ -111,7 +119,8 @@ describe("generator-norgate-av:app", () => { it("should create the correct package.json", () => { assert.jsonFileContent("package.json", { - name, + name: id, + displayName: name, description, engines: { node: `>=${engine}`, @@ -150,17 +159,14 @@ describe("generator-norgate-av:app", () => { }); it("should create the correct index.html", () => { - assert.fileContent( - "public/index.html", - `${name}`, - ); + assert.fileContent("public/index.html", `${id}`); }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${name}`); + assert.fileContent("README.md", `# ${id}`); assert.fileContent( "README.md", - `This is the README for your project "${name}". After writing up a brief description, we recommend including the following sections.`, + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, ); }); @@ -179,12 +185,11 @@ describe("generator-norgate-av:app", () => { it("should create the correct CONTRIBUTING.md", () => { assert.fileContent( "CONTRIBUTING.md", - `/${name}/issues/new/choose`, + `/${id}/issues/new/choose`, ); - assert.fileContent("CONTRIBUTING.md", `/${name}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${name}`); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent("CONTRIBUTING.md", `${pkg} contrib:add`); assert.fileContent( "CONTRIBUTING.md", `If in doubt, you can use the \`${pkg} commit\``, @@ -193,19 +198,27 @@ describe("generator-norgate-av:app", () => { "CONTRIBUTING.md", `Be sure to run \`${pkg} test\``, ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); }); it("should create the correct CHANGELOG.md", () => { assert.fileContent( "CHANGELOG.md", - `All notable changes to the "${name}" project will be documented in this file.`, + `All notable changes to the "${id}" project will be documented in this file.`, ); }); it("should create the correct .all-contributorsrc", () => { assert.fileContent( ".all-contributorsrc", - `"projectName": "${name}"`, + `"projectName": "${id}"`, ); }); diff --git a/tests/javascript.test.ts b/tests/javascript.test.ts index 1a936ea..29f92aa 100644 --- a/tests/javascript.test.ts +++ b/tests/javascript.test.ts @@ -25,7 +25,9 @@ describe("generator-norgate-av:app", () => { { type: "javascript", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: false, pkg: "pnpm", openWith: "skip", @@ -33,7 +35,9 @@ describe("generator-norgate-av:app", () => { { type: "js", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "yarn", openWith: "skip", @@ -41,14 +45,16 @@ describe("generator-norgate-av:app", () => { { type: "node-js", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "npm", openWith: "skip", }, ])( 'javascript with type $type, package manager $pkg, and git "$git"', - ({ type, name, description, git, pkg, openWith }) => { + ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; beforeAll(async () => { @@ -57,7 +63,9 @@ describe("generator-norgate-av:app", () => { .withAnswers({ type, name, + id, description, + author, git, pkg, openWith, @@ -108,7 +116,8 @@ describe("generator-norgate-av:app", () => { it("should create the correct package.json", () => { assert.jsonFileContent("package.json", { - name, + name: id, + displayName: name, description, engines: { node: `>=${engine}`, @@ -146,10 +155,10 @@ describe("generator-norgate-av:app", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${name}`); + assert.fileContent("README.md", `# ${id}`); assert.fileContent( "README.md", - `This is the README for your project "${name}". After writing up a brief description, we recommend including the following sections.`, + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, ); }); @@ -168,12 +177,11 @@ describe("generator-norgate-av:app", () => { it("should create the correct CONTRIBUTING.md", () => { assert.fileContent( "CONTRIBUTING.md", - `/${name}/issues/new/choose`, + `/${id}/issues/new/choose`, ); - assert.fileContent("CONTRIBUTING.md", `/${name}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${name}`); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent("CONTRIBUTING.md", `${pkg} contrib:add`); assert.fileContent( "CONTRIBUTING.md", `If in doubt, you can use the \`${pkg} commit\``, @@ -182,19 +190,27 @@ describe("generator-norgate-av:app", () => { "CONTRIBUTING.md", `Be sure to run \`${pkg} test\``, ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); }); it("should create the correct CHANGELOG.md", () => { assert.fileContent( "CHANGELOG.md", - `All notable changes to the "${name}" project will be documented in this file.`, + `All notable changes to the "${id}" project will be documented in this file.`, ); }); it("should create the correct .all-contributorsrc", () => { assert.fileContent( ".all-contributorsrc", - `"projectName": "${name}"`, + `"projectName": "${id}"`, ); }); diff --git a/tests/nodecli.test.ts b/tests/nodecli.test.ts index d9cfd27..99aef85 100644 --- a/tests/nodecli.test.ts +++ b/tests/nodecli.test.ts @@ -25,7 +25,9 @@ describe("generator-norgate-av:app", () => { { type: "nodecli", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: false, pkg: "pnpm", openWith: "skip", @@ -33,7 +35,9 @@ describe("generator-norgate-av:app", () => { { type: "node-cli", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "yarn", openWith: "skip", @@ -41,14 +45,16 @@ describe("generator-norgate-av:app", () => { { type: "cli-js", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "npm", openWith: "skip", }, ])( 'nodecli with type $type, package manager $pkg, and git "$git"', - ({ type, name, description, git, pkg, openWith }) => { + ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; beforeAll(async () => { @@ -57,7 +63,9 @@ describe("generator-norgate-av:app", () => { .withAnswers({ type, name, + id, description, + author, git, pkg, openWith, @@ -108,7 +116,8 @@ describe("generator-norgate-av:app", () => { it("should create the correct package.json", () => { assert.jsonFileContent("package.json", { - name, + name: id, + displayName: name, description, engines: { node: `>=${engine}`, @@ -146,10 +155,10 @@ describe("generator-norgate-av:app", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${name}`); + assert.fileContent("README.md", `# ${id}`); assert.fileContent( "README.md", - `This is the README for your project "${name}". After writing up a brief description, we recommend including the following sections.`, + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, ); }); @@ -168,12 +177,11 @@ describe("generator-norgate-av:app", () => { it("should create the correct CONTRIBUTING.md", () => { assert.fileContent( "CONTRIBUTING.md", - `/${name}/issues/new/choose`, + `/${id}/issues/new/choose`, ); - assert.fileContent("CONTRIBUTING.md", `/${name}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${name}`); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent("CONTRIBUTING.md", `${pkg} contrib:add`); assert.fileContent( "CONTRIBUTING.md", `If in doubt, you can use the \`${pkg} commit\``, @@ -182,19 +190,27 @@ describe("generator-norgate-av:app", () => { "CONTRIBUTING.md", `Be sure to run \`${pkg} test\``, ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); }); it("should create the correct CHANGELOG.md", () => { assert.fileContent( "CHANGELOG.md", - `All notable changes to the "${name}" project will be documented in this file.`, + `All notable changes to the "${id}" project will be documented in this file.`, ); }); it("should create the correct .all-contributorsrc", () => { assert.fileContent( ".all-contributorsrc", - `"projectName": "${name}"`, + `"projectName": "${id}"`, ); }); diff --git a/tests/python.test.ts b/tests/python.test.ts index 9389655..b644ca6 100644 --- a/tests/python.test.ts +++ b/tests/python.test.ts @@ -13,20 +13,24 @@ describe("generator-norgate-av:app", () => { { type: "python", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: false, openWith: "skip", }, { type: "py", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, openWith: "skip", }, ])( 'python using type "$type" and git "$git"', - ({ type, name, description, git, openWith }) => { + ({ type, name, id, description, author, git, openWith }) => { let result: RunResult; beforeAll(async () => { @@ -35,7 +39,9 @@ describe("generator-norgate-av:app", () => { .withAnswers({ type, name, + id, description, + author, git, openWith, }); @@ -70,10 +76,10 @@ describe("generator-norgate-av:app", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${name}`); + assert.fileContent("README.md", `# ${id}`); assert.fileContent( "README.md", - `This is the README for your project "${name}". After writing up a brief description, we recommend including the following sections.`, + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, ); }); @@ -88,7 +94,7 @@ describe("generator-norgate-av:app", () => { it("should create the correct CHANGELOG.md", () => { assert.fileContent( "CHANGELOG.md", - `All notable changes to the "${name}" project will be documented in this file.`, + `All notable changes to the "${id}" project will be documented in this file.`, ); }); diff --git a/tests/simpl.test.ts b/tests/simpl.test.ts index 4dac123..d12aaec 100644 --- a/tests/simpl.test.ts +++ b/tests/simpl.test.ts @@ -25,7 +25,9 @@ describe("generator-norgate-av:app", () => { { type: "simpl", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: false, pkg: "pnpm", openWith: "skip", @@ -33,7 +35,9 @@ describe("generator-norgate-av:app", () => { { type: "crestron-simpl", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "yarn", openWith: "skip", @@ -41,14 +45,16 @@ describe("generator-norgate-av:app", () => { { type: "simpl", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "npm", openWith: "skip", }, ])( 'crestron-simpl with type $type, package manager $pkg, and git "$git"', - ({ type, name, description, git, pkg, openWith }) => { + ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; beforeAll(async () => { @@ -57,7 +63,9 @@ describe("generator-norgate-av:app", () => { .withAnswers({ type, name, + id, description, + author, git, pkg, openWith, @@ -110,7 +118,8 @@ describe("generator-norgate-av:app", () => { it("should create the correct package.json", () => { assert.jsonFileContent("package.json", { - name, + name: id, + displayName: name, description, engines: { node: `>=${engine}`, @@ -139,10 +148,10 @@ describe("generator-norgate-av:app", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${name}`); + assert.fileContent("README.md", `# ${id}`); assert.fileContent( "README.md", - `This is the README for your project "${name}". After writing up a brief description, we recommend including the following sections.`, + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, ); }); @@ -161,12 +170,11 @@ describe("generator-norgate-av:app", () => { it("should create the correct CONTRIBUTING.md", () => { assert.fileContent( "CONTRIBUTING.md", - `/${name}/issues/new/choose`, + `/${id}/issues/new/choose`, ); - assert.fileContent("CONTRIBUTING.md", `/${name}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${name}`); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent("CONTRIBUTING.md", `${pkg} contrib:add`); assert.fileContent( "CONTRIBUTING.md", `If in doubt, you can use the \`${pkg} commit\``, @@ -175,19 +183,27 @@ describe("generator-norgate-av:app", () => { "CONTRIBUTING.md", `Be sure to run \`${pkg} test\``, ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); }); it("should create the correct CHANGELOG.md", () => { assert.fileContent( "CHANGELOG.md", - `All notable changes to the "${name}" project will be documented in this file.`, + `All notable changes to the "${id}" project will be documented in this file.`, ); }); it("should create the correct .all-contributorsrc", () => { assert.fileContent( ".all-contributorsrc", - `"projectName": "${name}"`, + `"projectName": "${id}"`, ); }); diff --git a/tests/typescript.test.ts b/tests/typescript.test.ts index b875aa8..74d3165 100644 --- a/tests/typescript.test.ts +++ b/tests/typescript.test.ts @@ -31,7 +31,9 @@ describe("generator-norgate-av:app", () => { { type: "typescript", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: false, pkg: "pnpm", openWith: "skip", @@ -39,7 +41,9 @@ describe("generator-norgate-av:app", () => { { type: "ts", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "yarn", openWith: "skip", @@ -47,14 +51,16 @@ describe("generator-norgate-av:app", () => { { type: "node-ts", name: "test", + id: "test-id", description: "test-description", + author: "Yeoman", git: true, pkg: "npm", openWith: "skip", }, ])( 'typescript using type $type, package manager $pkg, and git "$git"', - ({ type, name, description, git, pkg, openWith }) => { + ({ type, name, id, description, author, git, pkg, openWith }) => { let result: RunResult; beforeAll(async () => { @@ -63,7 +69,9 @@ describe("generator-norgate-av:app", () => { .withAnswers({ type, name, + id, description, + author, git, pkg, openWith, @@ -121,7 +129,8 @@ describe("generator-norgate-av:app", () => { it("should create the correct package.json", () => { assert.jsonFileContent("package.json", { - name, + name: id, + displayName: name, description, engines: { node: `>=${engine}`, @@ -178,10 +187,10 @@ describe("generator-norgate-av:app", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${name}`); + assert.fileContent("README.md", `# ${id}`); assert.fileContent( "README.md", - `This is the README for your project "${name}". After writing up a brief description, we recommend including the following sections.`, + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, ); }); @@ -200,12 +209,11 @@ describe("generator-norgate-av:app", () => { it("should create the correct CONTRIBUTING.md", () => { assert.fileContent( "CONTRIBUTING.md", - `/${name}/issues/new/choose`, + `/${id}/issues/new/choose`, ); - assert.fileContent("CONTRIBUTING.md", `/${name}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${name}`); + assert.fileContent("CONTRIBUTING.md", `/${id}.git`); + assert.fileContent("CONTRIBUTING.md", `cd ${id}`); assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent("CONTRIBUTING.md", `${pkg} contrib:add`); assert.fileContent( "CONTRIBUTING.md", `If in doubt, you can use the \`${pkg} commit\``, @@ -214,19 +222,27 @@ describe("generator-norgate-av:app", () => { "CONTRIBUTING.md", `Be sure to run \`${pkg} test\``, ); + assert.fileContent( + "CONTRIBUTING.md", + `Run the \`${pkg} contrib:add\``, + ); + assert.fileContent( + "CONTRIBUTING.md", + `${pkg} contrib:add `, + ); }); it("should create the correct CHANGELOG.md", () => { assert.fileContent( "CHANGELOG.md", - `All notable changes to the "${name}" project will be documented in this file.`, + `All notable changes to the "${id}" project will be documented in this file.`, ); }); it("should create the correct .all-contributorsrc", () => { assert.fileContent( ".all-contributorsrc", - `"projectName": "${name}"`, + `"projectName": "${id}"`, ); });