Skip to content

Commit

Permalink
Merge pull request #118 from IgniteUI/tpaskalev/version-command
Browse files Browse the repository at this point in the history
Tpaskalev/version command
  • Loading branch information
damyanpetev authored Jan 11, 2018
2 parents 8e5744c + 1c27b0e commit cf68ac6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
8 changes: 8 additions & 0 deletions ignite-ui-cli.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_____ _ _ _ _ _____ _____ _ _____
|_ _| (_) | | | | |_ _| / ____| | |_ _|
| | __ _ _ __ _| |_ ___ | | | | | | | | | | | |
| | / _` | '_ \| | __/ _ \ | | | | | | | | | | | |
_| || (_| | | | | | || __/ | |__| |_| |_ | |____| |____ _| |_
|_____\__, |_| |_|_|\__\___| \____/|_____| \_____|______|_____|
__/ |
|___/
31 changes: 30 additions & 1 deletion lib/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,41 @@ class Util {
}
// tslint:enable:no-console
}
public static version() {
const configuration = require("../package.json");
const logo = fs.readFileSync(__dirname + "/../ignite-ui-cli.txt");
logo.toString().split("\n").forEach(line => {
// tslint:disable:no-console
console.log(line);
});
console.log("Ignite UI CLI version: " + configuration.version);
console.log("OS: " + this.getOSFriendlyName(process.platform));
// tslint:enable:no-console
}

public static getOSFriendlyName(platform: string): string {
let os = "";
switch (platform) {
case "win32":
os = "Windows";
break;
case "darwin":
os = "Mac OS";
break;
case "freebsd":
os = "FreeBSD";
break;
default:
os = "Unknown OS";
break;
}
return os;
}
/**
* lower-dashed string
*/
public static lowerDashed(text: string) {
return text.replace(/\s+/g, "-").toLowerCase();
return text.replace(/\s+/g, "-").toLowerCase();
}
}

Expand Down
15 changes: 14 additions & 1 deletion lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,22 @@ export async function run(args = null) {
.command(build)
.command(test)
.command(add)
.help()
.options({
v: {
alias: "version",
description: "Show current Ignite UI CLI version",
global: true,
type: "boolean"
}
})
.help().alias("help", "h")
.argv;

if (argv.version) {
Util.version();
return;
}

const command = argv._[0];
switch (command) {
case "new":
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"shelljs": "^0.7.8",
"through2": "^2.0.3",
"yargs": "^8.0.2",
"typescript": "^2.5.3"
"typescript": "^2.5.3"
},
"devDependencies": {
"@types/fs-extra": "^3.0.3",
Expand Down
21 changes: 12 additions & 9 deletions spec/acceptance/help-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ describe("Help command", () => {
encoding: "utf-8"
});
const originalHelpText: string = `Commands:
quickstart A quick start for your project
start start the project
new [name] Creating a new project
build build the project
test test the project
add [template] [name] Add component by it ID and providing a name.
Options:
--help Show help [boolean]`;
quickstart A quick start for your project
start start the project
new [name] Creating a new project
build build the project
test test the project
add [template] [name] Add component by it ID and providing a name.
Options:
-v, --version Show current Ignite UI CLI version [boolean]
--help, -h Show help [boolean]`;

const replacedHelpText: string = originalHelpText.replace(/\s/g, "");
const actualText: string = (child.stdout.toString("utf-8")).replace(/\s/g, "");
Expand All @@ -27,7 +29,8 @@ describe("Help command", () => {
encoding: "utf-8"
});
const originalNewHelpText: string = `Options:
--help Show help [boolean]
-v, --version Show current Ignite UI CLI version [boolean]
--help, -h Show help [boolean]
--name, -n Project name [string]
--framework, -f Framework to setup project for
[string] [choices: "angular", "jquery", "react"] [default: "jquery"]
Expand Down

0 comments on commit cf68ac6

Please sign in to comment.