Skip to content

Commit

Permalink
feat: Add generate command
Browse files Browse the repository at this point in the history
Fix ts-lint errors and some failing test
  • Loading branch information
wnvko committed Feb 19, 2018
1 parent 75fe4ef commit f750832
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 16 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Expand Up @@ -242,6 +242,20 @@
"-t=igx-ts",
"-s=false",
]
},
{
"type": "node",
"request": "launch",
"name": "Add testing",
"cwd": "${workspaceRoot}/output/add-spec",
"program": "${workspaceRoot}/bin/execute.js",
"console": "externalTerminal",
"preLaunchTask": "build",
"args": [
"add",
"wrong",
"name"
]
}
]
}
4 changes: 4 additions & 0 deletions lib/BaseProjectLibrary.ts
Expand Up @@ -62,6 +62,10 @@ export class BaseProjectLibrary implements ProjectLibrary {
.filter(x => x !== this._projectsPath && x !== this._customTemplatesPath);

for (const componentFolder of componentFolders) {
if (componentFolder === "generate") {
continue;
}

this._components.push(require(path.join(this.rootPath, componentFolder)) as Component);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cli.ts
Expand Up @@ -4,8 +4,8 @@ import * as yargs from "yargs";
import { default as add } from "./commands/add";
import { default as build } from "./commands/build";
import { default as config } from "./commands/config";
import { default as newCommand } from "./commands/new";
import { default as generate } from "./commands/generate";
import { default as newCommand } from "./commands/new";
import { default as quickstart } from "./commands/quickstart";
import { default as start } from "./commands/start";
import { default as test } from "./commands/test";
Expand Down
28 changes: 13 additions & 15 deletions lib/commands/generate.ts
@@ -1,11 +1,10 @@
import { utimes } from "fs-extra";
import * as path from "path";
import { Util } from "../Util";
import { TemplateManager } from "../TemplateManager";
import { utimes } from "fs-extra";
import { Util } from "../Util";
import { default as config } from "./config";

const command = {
// tslint:disable:object-literal-sort-keys
command: "generate",
aliases: ["g"],
templateManager: new TemplateManager(),
Expand All @@ -17,19 +16,19 @@ const command = {
aliases: ["t"],
desc: "Generates custom template",
builder: {
name: {
"name": {
describe: "Template name.",
alias: "n",
default: "custom-template",
type: "string"
},
framework: {
"framework": {
describe: "Framework name.",
alias: "f",
default: "jquery",
type: "string"
},
type: {
"type": {
describe: "Framework type.",
alias: "t",
default: "js",
Expand All @@ -47,14 +46,13 @@ const command = {
// at least one command is required
.demandCommand(1, "Please select command");
},
// tslint:enable:object-literal-sort-keys
async template(argv) {
// trim
argv.name = argv.name.trim();

// letter+alphanumeric check
if (!Util.isAlphanumericExt(argv.name)) {
Util.error("Name '${argv.name}' is not valid. "
Util.error(`Name '${argv.name}' is not valid. `
+ "Name should start with a letter and can also contain numbers, dashes and spaces.",
"red");
return;
Expand All @@ -78,7 +76,7 @@ const command = {
}
}

let templatesFolder = path.join(__dirname, "..", "..", "templates", argv.framework, argv.type, "generate");
const templatesFolder = path.join(__dirname, "..", "..", "templates", argv.framework, argv.type, "generate");
argv.className = Util.className(argv.name);

Util.log(`Project Name: ${argv.name}, framework ${argv.framework}, type ${argv.type}`);
Expand All @@ -88,20 +86,20 @@ const command = {
{
"$(name)": argv.name,
"$(framework)": argv.framework,
"$(type)": argv.type, __name__: argv.name,
"$(type)": argv.type,
"__name__": argv.name,
"$(ClassName)": argv.className
},
null);
promise.then((res) => {
promise.then(res => {
if (res) {
if (argv.skipConfig == false) {
if (argv.skipConfig === false) {
config.addHandler({ property: "customTemplates", value: "parth:" + outDir, global: true });
}
}
else {
} else {
return Util.log("Project creation failed!");
}
}).catch((err) => {
}).catch(err => {
return Util.log("Project creation failed!");
});
}
Expand Down
19 changes: 19 additions & 0 deletions spec/acceptance/help-spec.ts
Expand Up @@ -9,6 +9,7 @@ describe("Help command", () => {
quickstart A quick start for your project
start start the project
new [name] Creating a new project
generate Generates new project [aliases: g]
build build the project
config Get or set configuration properties
test test the project
Expand Down Expand Up @@ -61,6 +62,24 @@ describe("Help command", () => {
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 generate sub-commands", async done => {
const child = spawnSync("node", ["bin/execute.js", "generate", "--help" ], {
encoding: "utf-8"
});
const originalNewHelpText: string = `Commands:
template [name] [framework] [type] Generates custom template
[skip-config] [aliases: t]
Options:
--version, -v Show current Ignite UI CLI version [boolean]
--help, -h Show help [boolean]`;

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

expect(actualNewText).toContain(replacedNewHelpText);
done();
});
Expand Down

0 comments on commit f750832

Please sign in to comment.