diff --git a/src/taco-cli/cli/commands.json b/src/taco-cli/cli/commands.json index 240b1723..1f973457 100644 --- a/src/taco-cli/cli/commands.json +++ b/src/taco-cli/cli/commands.json @@ -1,19 +1,23 @@ { "create": { + "synopsis": " [ID] [NAME] [options]", "modulePath": "../cli/create", - "description": "Create a project", + "description": "Create a Cordova project", "args": [ - { "name": "", "description": "Where to create the project" }, - { "name": "[ID]", "description": "reverse-domain-style package name - used in " }, - { "name": "[NAME]", "description": "human readable field" }, - { "name": "[options]", "description": "" } + { "name": "PATH", "description": "Where to create the project" }, + { "name": "ID", "description": "Package ID for the project" }, + { "name": "NAME", "description": "Human readable app name" } ], "options": [ - { "name": "template", "description": "template name" }, - { "name": "kit", "description": "kit version" } + { "name": "--kit ", "description": "Use the specified Cordova Dev Kit for this project rather than the default. Use \"taco kit list\" to see a list of available Kits." }, + { "name": "--template ", "description": "Use an alternate project template instead of blank." }, + { "name": "--cli ", "description": "Use a version of the Cordova CLI rather than a Cordova Dev Kit." }, + { "name": "--copy-from|src ", "description": "Use custom www assets instead using a template." }, + { "name": "--link-to ", "description": "Symlink to custom www assets without creating a copy." } ] }, "plugin": { + "Synopsis" : "", "modulePath": "../cli/cordova", "description": "Add/remove a plugin", "args": [ diff --git a/src/taco-cli/cli/cordova.ts b/src/taco-cli/cli/cordova.ts index 458d697d..cc8e6e9d 100644 --- a/src/taco-cli/cli/cordova.ts +++ b/src/taco-cli/cli/cordova.ts @@ -11,11 +11,7 @@ import tacoUtility = require("taco-utils"); */ class Cordova extends tacoUtility.Commands.Command { public run(): void { - console.log("Cordova!!!"); - //console.log("args: " + this.info.args.length); - //console.log("options: " + this.info.options.length); - console.log(this.cliArgs); - cordova.cli(["cc", "dd"]); + cordova.cli(this.cliArgs); //call into Cordova CLI } } diff --git a/src/taco-cli/cli/create.ts b/src/taco-cli/cli/create.ts index 600a1d85..a77a92fe 100644 --- a/src/taco-cli/cli/create.ts +++ b/src/taco-cli/cli/create.ts @@ -1,8 +1,12 @@ /// /// +/// import tacoUtility = require("taco-utils"); import cordovaCommand = require("./cordova"); +var nopt = require("nopt"); +import logger = tacoUtility.Logger; +import level = logger.Level; /* * Create @@ -12,6 +16,21 @@ import cordovaCommand = require("./cordova"); class Create extends cordovaCommand { run() { console.log("create!!!"); + var knownOpts: any = { + "template": String + }; + var shortHands: any = { + "t": ["--template"] + }; + + var args = nopt(knownOpts, shortHands, process.argv, 2); + + //sample getting args specific to taco + logger.logNewLine("Creating new project using template : " + args.template, level.Success); + + //sample routing remaining args to Cordova + this.cliArgs = args.argv.remain; + super.run(); } } diff --git a/src/taco-cli/cli/help.ts b/src/taco-cli/cli/help.ts new file mode 100644 index 00000000..409144af --- /dev/null +++ b/src/taco-cli/cli/help.ts @@ -0,0 +1,71 @@ +/// +/// +/// +/// + + +import nopt = require("nopt"); +var colors = require("colors"); +import tacoUtility = require("taco-utils"); +import commandsFactory = tacoUtility.Commands.CommandFactory; +import logger = tacoUtility.Logger; +import level = logger.Level; +/* + * Help + * + * handles "Taco Help" + */ +class Help extends tacoUtility.Commands.Command { + private indent: string = " "; + private charsToDescription: number = 35; + private maxRight = 70; + + run() { + this.printHeader(); + if (this.cliArgs.length == 0) { + this.printGeneralUsage(); + } else if (this.cliArgs.length == 1) { + this.printCommandUsage(this.cliArgs[0]) + } + } + + public printHeader(): void { + logger.logNewLine("\n=================================================================", level.Normal); + } + + public printGeneralUsage(): void { + console.log("General Help!!"); + } + + public printCommandUsage(command: string): void { + if (!commandsFactory.Listings || !commandsFactory.Listings[command]) { + this.printGeneralUsage(); + return; + } + + var list: tacoUtility.Commands.ICommandInfo = commandsFactory.Listings[command]; + logger.logNewLine("Synopsis\n", level.NormalBold); + logger.logNewLine(this.indent + list.synopsis + "\n", level.Success); + logger.logNewLine(list.description + "\n", level.NormalBold); + this.printCommandTable(list.args, this.indent); + logger.logNewLine("\n" + this.indent + "Options:\n", level.NormalBold); + this.printCommandTable(list.options, this.indent + this.indent); + } + + public printCommandTable(nameValuePairs: tacoUtility.Commands.INameDescription[], indentFromLeft: string) { + nameValuePairs.forEach(nvp => { + logger.log(indentFromLeft + nvp.name, level.Warn); + logger.log(" ", level.Normal); + for (var i: number = indentFromLeft.length + nvp.name.length + 2; + i < this.charsToDescription; i++) { + logger.log(".", level.Normal); + } + + if (this.charsToDescription + nvp.description.length > this.maxRight) { + } + logger.log(" " + nvp.description + "\n", level.Normal); + }); + } +} + +export = Help; \ No newline at end of file diff --git a/src/taco-cli/cli/taco.ts b/src/taco-cli/cli/taco.ts index 74f56b87..903d5587 100644 --- a/src/taco-cli/cli/taco.ts +++ b/src/taco-cli/cli/taco.ts @@ -1,12 +1,10 @@ /// /// -/// /// import tacoUtility = require("taco-utils"); import resourcesManager = tacoUtility.ResourcesManager; import commandsFactory = tacoUtility.Commands.CommandFactory; -import nopt = require("nopt"); import fs = require("fs"); import path = require("path"); @@ -14,10 +12,10 @@ class Taco { constructor() { var resourcePath: string = path.resolve("../resources"); resourcesManager.init("en", resourcePath); + commandsFactory.init("../cli/commands.json"); } public run(): void { - commandsFactory.init("../cli/commands.json"); commandsFactory.runTask(); } } diff --git a/src/taco-cli/package.json b/src/taco-cli/package.json index 6cb5a5ba..234157ce 100644 --- a/src/taco-cli/package.json +++ b/src/taco-cli/package.json @@ -39,6 +39,7 @@ "nconf": "^0.7.1", "nopt": "^3.0.1", "q": "^1.1.2", + "colors": "^1.0.3", "taco-utils": "file:../taco-utils" }, "bundledDependencies": ["taco-utils"], diff --git a/src/taco-utils/package.json b/src/taco-utils/package.json index eb5f6f4f..36ec0115 100644 --- a/src/taco-utils/package.json +++ b/src/taco-utils/package.json @@ -4,9 +4,10 @@ "name": "Microsoft Corp." }, "description": "strictly internal use to enable require in utility folder", - "version": "0.0.1", + "version": "0.0.1", "main": "taco-utils.js", "dependencies": { + "colors": "^1.0.3" }, "private": true, "devDependencies": { diff --git a/src/taco-utils/taco-utils.ts b/src/taco-utils/taco-utils.ts index 1cb0ada3..eea05c91 100644 --- a/src/taco-utils/taco-utils.ts +++ b/src/taco-utils/taco-utils.ts @@ -1,10 +1,60 @@ /// -"use strict"; +/// -import fs = require ("fs"); +"use strict"; +import fs = require("fs"); +var colors = require("colors"); import path = require ("path"); module TacoUtility { + export module Logger { + export enum Level { Warn, Error, Link, Normal, Success, NormalBold }; + export function colorize(msg: string, level: Level): string { + //not yet possible to combine themes yet so still need to wrap this: https://github.com/Marak/colors.js/issues/72 + colors.setTheme({ + error: "red", + warn: "yellow", + link: "blue", + normalBold: "bold", + success: "green" + }); + + switch (level) { + case Level.Error: return msg.error.bold; + case Level.Warn: return msg.warn.bold; + case Level.Link: return msg.link.underline; + case Level.Normal: return msg; + case Level.NormalBold: return msg.normalBold; + case Level.Success: return msg.success.bold; + } + } + + export function logNewLine(msg: string, level: Level): void { + log(msg + "\n", level); + } + + /** + * + * + */ + export function log(msg: string, level: Level): void { + msg = colorize(msg, level); + switch (level) { + case Level.Error: + case Level.Warn: + process.stderr.write(msg); + return; + + case Level.Link: + case Level.Success: + case Level.Normal: + case Level.NormalBold: + process.stdout.write(msg); + break; + } + } + } + export module Commands { export interface INameDescription { name: string; @@ -12,6 +62,7 @@ module TacoUtility { } export interface ICommandInfo { + synopsis: string; modulePath: string; description: string; args: INameDescription[]; @@ -23,7 +74,7 @@ module TacoUtility { cliArgs: string[]; constructor(info: ICommandInfo) { this.info = info; - this.cliArgs = process.argv.slice(2); + this.cliArgs = process.argv.slice(3); } public run() { @@ -31,9 +82,8 @@ module TacoUtility { } export class CommandFactory { - private static Listings: any; + public static Listings: any; private static Instance: Command; - public static CommandsInfoFile: string; // initialize with json file containing commands public static init(commandsInfoPath: string) { @@ -42,7 +92,6 @@ module TacoUtility { throw new Error("Cannot find commands listing file"); } - CommandFactory.CommandsInfoFile = commandsInfoPath; CommandFactory.Listings = require(commandsInfoPath); } diff --git a/src/typings/colors.d.ts b/src/typings/colors.d.ts new file mode 100644 index 00000000..830f3726 --- /dev/null +++ b/src/typings/colors.d.ts @@ -0,0 +1,47 @@ +// Type definitions for Colors.js 0.6.0-1 +// Project: https://github.com/Marak/colors.js +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module colors { + export function setTheme(theme: any): any; + export function black(text: string): string; + export function red(text: string): string; + export function green(text: string): string; + export function yellow(text: string): string; + export function blue(text: string): string; + export function magenta(text: string): string; + export function cyan(text: string): string; + export function white(text: string): string; + export function gray(text: string): string; + export function grey(text: string): string; + + +} + +interface String { + bold: string; + italic: string; + underline: string; + inverse: string; + yellow: string; + cyan: string; + white: string; + magenta: string; + green: string; + red: string; + grey: string; + blue: string; + rainbow: string; + zebra: string; + random: string; + error: string; + warn: string; + link: string; + normalBold: string; + success: string; +} + +declare module "colors" { + export = colors; +} \ No newline at end of file diff --git a/src/typings/taco-utils.d.ts b/src/typings/taco-utils.d.ts index 28ae7e76..3cfee064 100644 --- a/src/typings/taco-utils.d.ts +++ b/src/typings/taco-utils.d.ts @@ -1,11 +1,30 @@ /// +/// declare module TacoUtility { + module Logger { + enum Level { + Warn = 0, + Error = 1, + Link = 2, + Normal = 3, + Success = 4, + NormalBold = 5, + } + function colorize(msg: string, level: Level): string; + function logNewLine(msg: string, level: Level): void; + /** + * + * + */ + function log(msg: string, level: Level): void; + } module Commands { interface INameDescription { name: string; description: string; } interface ICommandInfo { + synopsis: string; modulePath: string; description: string; args: INameDescription[]; @@ -18,9 +37,8 @@ declare module TacoUtility { run(): void; } class CommandFactory { - private static Listings; + static Listings: any; private static Instance; - static CommandsInfoFile: string; static init(commandsInfoPath: string): void; static getTask(name: string): Command; static runTask(): void;