Skip to content

Commit

Permalink
feat: add list command (#203)
Browse files Browse the repository at this point in the history
* feat: list command is working now

* test: fix failing test for help command

* test: help for list command test add

* test: add some unit test for list command

* chore: add text to log when called from project folder

* chore: add control groups to jQuery templates

* feat: update list command to show and descriptions of the listed templates
list also the views under the Views group

* chore: fix failing test after resolving conflicts

* chore: fix tslint issues

* chore: Grids&Lists changed to Grids & Lists

* chore: refactor list command
Fix all custom templates
  • Loading branch information
wnvko authored and bazal4o committed Mar 8, 2018
1 parent 1445d54 commit 1f532ef
Show file tree
Hide file tree
Showing 30 changed files with 407 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/templates/**/*.js.map
/lib/**/*.js.map
/lib/**/*.js
/lib/config/Config.schema.json
/spec/**/*.js.map
/spec/**/*.js
/templates/jquery/**/*.js
Expand Down
19 changes: 15 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
"t",
"-n=angular",
"-f=angular",
"-t=igx-ts",
"-t=igx-ts"
]
},
{
Expand All @@ -279,7 +279,7 @@
"t",
"-n=angular wrapper",
"-f=angular",
"-t=ig-ts",
"-t=ig-ts"
]
},
{
Expand All @@ -295,7 +295,7 @@
"t",
"-n=react",
"-f=react",
"-t=es6",
"-t=es6"
]
},
{
Expand All @@ -310,7 +310,7 @@
"g",
"t",
"-n=react no type",
"-f=react",
"-f=react"
]
},
{
Expand Down Expand Up @@ -350,6 +350,17 @@
"doc",
"igGrid"
]
},{
"type": "node",
"request": "launch",
"name": "Launch List command",
"cwd": "${workspaceRoot}/output",
"program": "${workspaceRoot}/bin/execute.js",
"console": "externalTerminal",
"preLaunchTask": "build",
"args": [
"list"
]
}
]
}
7 changes: 7 additions & 0 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { default as build } from "./commands/build";
import { default as config } from "./commands/config";
import { default as doc } from "./commands/doc";
import { default as generate } from "./commands/generate";
import { default as list } from "./commands/list";
import { default as newCommand } from "./commands/new";
import { default as quickstart } from "./commands/quickstart";
import { default as start } from "./commands/start";
Expand All @@ -23,6 +24,7 @@ export async function run(args = null) {
newCommand.builder.framework.choices = templateManager.getFrameworkIds();
add.templateManager = templateManager;
generate.templateManager = templateManager;
list.templateManager = templateManager;

const yargsModule = args ? yargs(args) : yargs;

Expand All @@ -36,6 +38,7 @@ export async function run(args = null) {
.command(config)
.command(doc)
.command(test)
.command(list)
.options({
version: {
alias: "v",
Expand Down Expand Up @@ -87,6 +90,10 @@ export async function run(args = null) {
case "start":
await start.execute(argv);
break;
case "l":
case "list":
list.execute(argv);
break;
default:
Util.log("Starting Step by step mode.", "green");
Util.log("For available commands, stop this execution and use --help.", "green");
Expand Down
8 changes: 4 additions & 4 deletions lib/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ const command = {
"framework": {
alias: "f",
default: "jquery",
describe: "Framework name.",
describe: "Framework to generate template for",
type: "string"
},
"name": {
alias: "n",
default: "custom-template",
describe: "Template name.",
describe: "Template name",
type: "string"
},
"skip-config": {
alias: "s",
default: false,
describe: "Runs generate command without updating the cli config.",
describe: "Runs generate command without updating the cli config",
type: "boolean"
},
"type": {
alias: "t",
describe: "Framework type.",
describe: "Project type (depends on framework)",
type: "string"
}
}
Expand Down
102 changes: 102 additions & 0 deletions lib/commands/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { ProjectConfig } from "../ProjectConfig";
import { TemplateManager } from "../TemplateManager";
import { Util } from "../Util";
import { PromptSession } from "./../PromptSession";

let command: {
[name: string]: any,
templateManager: TemplateManager,
execute: (argv: any) => void
};

// tslint:disable:object-literal-sort-keys
command = {
command: "list",
// use aliases here, instead of alias. With single alias yargs does not build correctly argv
aliases: ["l"],
desc: "list all templates",
builder: {
framework: {
alias: "f",
default: "jquery",
describe: "Framework to list templates for",
type: "string"
},
type: {
alias: "t",
describe: "Project type (depends on framework)",
type: "string"
}
},
templateManager: null,
execute(argv) {
let inProject = false;
const viewsGroupName = "Views";
if (ProjectConfig.hasLocalConfig()) {
const config: Config = ProjectConfig.getConfig();
argv.framework = config.project.framework;
argv.type = config.project.projectType;
inProject = true;
}

const templatesByGroup = [];
const controlGroups: string[] = [];

const framework: Framework = this.templateManager.getFrameworkById(argv.framework);
if (!framework) {
return Util.error("Wrong framework provided", "red");
}

let projectLib: ProjectLibrary;
if (argv.type) {
projectLib = command.templateManager.getProjectLibrary(argv.framework, argv.type) as ProjectLibrary;
if (!projectLib) {
return Util.error(`Project type '${argv.type}' not found in framework '${argv.framework}'`, "red");
}
} else {
projectLib = command.templateManager.getProjectLibrary(argv.framework) as ProjectLibrary;
}

let maxIdLength = 0;
projectLib.templates
.map(t => {
if (!t.listInCustomTemplates) {
if (controlGroups.indexOf(t.controlGroup) === -1) {
controlGroups.push(t.controlGroup);
templatesByGroup[t.controlGroup] = [];
}

templatesByGroup[t.controlGroup].push({ id: t.id, description: t.description });
} else {
if (controlGroups.indexOf(viewsGroupName) === -1) {
controlGroups.push(viewsGroupName);
templatesByGroup[viewsGroupName] = [];
}

templatesByGroup[viewsGroupName].push({ id: t.id, description: t.description });
}

if (t.id.length > maxIdLength) {
maxIdLength = t.id.length;
}
});

Util.log(`Available templates for '${framework.name}' framework '${projectLib.projectType}' type`);
const addSpacesCount = 5;
const spaceChar = " ";
for (const group of Object.keys(templatesByGroup)) {
Util.log(`'${group}' group:`);
for (const template of templatesByGroup[group]) {
const spacesCount = maxIdLength - template.id.length + addSpacesCount;
const output = "\t" + template.id + spaceChar.repeat(spacesCount) + template.description;
Util.log(output);
}
}

if (inProject) {
Util.log("To list available templates for other framework and project type run outside of a project folder");
}
}
};

export default command;
29 changes: 24 additions & 5 deletions spec/acceptance/help-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Help command", () => {
config gets, sets or adds a configuration property
doc [term] opens the Infragistics search for the given term
test tests the project
list list all templates [aliases: l]
Options:
--version, -v Show current Ignite UI CLI version [boolean]
--help, -h Show help [boolean]`;
Expand Down Expand Up @@ -92,11 +92,30 @@ describe("Help command", () => {
Options:
--version, -v Show current Ignite UI CLI version [boolean]
--help, -h Show help [boolean]
--framework, -f Framework name. [string] [default: "jquery"]
--name, -n Template name. [string] [default: "custom-template"]
--skip-config, -s Runs generate command without updating the cli config.
--framework, -f Framework to generate template for
[string] [default: "jquery"]
--name, -n Template name [string] [default: "custom-template"]
--skip-config, -s Runs generate command without updating the cli config
[boolean] [default: false]
--type, -t Framework type. [string]
--type, -t Project type (depends on framework) [string]
`;

const replacedNewHelpText: string = originalNewHelpText.replace(/\s/g, "");
const actualNewText: string = (child.stdout.toString("utf-8")).replace(/\s/g, "");

expect(actualNewText).toContain(replacedNewHelpText);
done();
});
it("should show help for list command", async done => {
const child = spawnSync("node", ["bin/execute.js", "list", "-h" ], {
encoding: "utf-8"
});
const originalNewHelpText: string = `
Options:
--version, -v Show current Ignite UI CLI version [boolean]
--help, -h Show help [boolean]
--framework, -f Framework to list templates for [string] [default: "jquery"]
--type, -t Project type (depends on framework) [string]
`;

const replacedNewHelpText: string = originalNewHelpText.replace(/\s/g, "");
Expand Down
Loading

0 comments on commit 1f532ef

Please sign in to comment.