Skip to content

Commit

Permalink
Merge pull request #67 from SAP/humanizeString
Browse files Browse the repository at this point in the history
Show prettyName in generator selection
  • Loading branch information
tomer-epstein authored Dec 25, 2019
2 parents c5853ee + af2ace9 commit 9abb741
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"strip-ansi": "^6.0.0",
"ws": "^7.2.0",
"yeoman-environment": "^2.7.0",
"titleize": "^1.0.1",
"humanize-string": "^1.0.2",
"fs-extra": "^8.1.0"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as fsextra from "fs-extra";
import * as _ from "lodash";
import * as Environment from "yeoman-environment";
import * as inquirer from "inquirer";
const titleize = require('titleize');
const humanizeString = require('humanize-string');
const datauri = require("datauri");
import * as defaultImage from "./defaultImage";
import { YouiAdapter } from "./youi-adapter";
Expand All @@ -15,6 +17,7 @@ import { GeneratorType, GeneratorFilter } from "./filter";

export interface IGeneratorChoice {
name: string;
prettyName: string;
message: string;
imageUrl?: string;
}
Expand Down Expand Up @@ -264,9 +267,11 @@ export class YeomanUI {
}

const genMessage = _.get(packageJson, "description", YeomanUI.defaultMessage);
const genPrettyName = titleize(humanizeString(genName));

return {
name: genName,
prettyName: genPrettyName,
message: genMessage,
imageUrl: genImageUrl
};
Expand Down
30 changes: 30 additions & 0 deletions backend/tests/yeomanui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,36 @@ describe('yeomanui unit test', () => {
expect(test2Choice.name).to.be.equal("test2");
expect(test3Choice.name).to.be.equal("test4");
});

it("get generators with displayName", async () => {
envMock.expects("getGeneratorsMeta").returns({
"test1-project:app": {
packagePath: "test1Path"
},
"test2-module:app": {
packagePath: "test2Path"
},
"test3:app": {
packagePath: "test3Path"
}
});
envMock.expects("getGeneratorNames").returns(["test1-project", "test2-module", "test3"]);

fsExtraMock.expects("readFile").withExactArgs(path.join("test1Path", PACKAGE_JSON), UTF8).resolves(`{"generator-filter": {"type": "project"}, "description": "test1Description"}`);
fsExtraMock.expects("readFile").withExactArgs(path.join("test2Path", PACKAGE_JSON), UTF8).resolves(`{"generator-filter": {"type": "module"}}`);
fsExtraMock.expects("readFile").withExactArgs(path.join("test3Path", PACKAGE_JSON), UTF8).resolves(`{"description": "test3Description"}`);

yeomanUi.setGenFilter(GeneratorFilter.create());
const result = await yeomanUi.getGenerators();

expect(result.questions[0].choices).to.have.lengthOf(3);
const test1Choice = result.questions[0].choices[0];
const test2Choice = result.questions[0].choices[1];
const test3Choice = result.questions[0].choices[2];
expect(test1Choice.prettyName).to.be.equal("Test1 Project");
expect(test2Choice.prettyName).to.be.equal("Test2 Module");
expect(test3Choice.prettyName).to.be.equal("Test3");
});
});

describe("getEnv", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@click="emitSelection(item.name)"
v-on:click="select"
class="generator h-100"
:title="item.name"
:title="item.prettyName"
img-alt="Image"
img-top
tag="article"
Expand Down

0 comments on commit 9abb741

Please sign in to comment.