This commit is contained in:
Leo Lee (DEVDIV) 2015-02-04 23:40:28 -08:00
Родитель 69fc554942
Коммит 5dd81533c3
7 изменённых файлов: 169 добавлений и 100 удалений

Просмотреть файл

@ -1,31 +0,0 @@
/// <reference path="../../typings/cordova.d.ts" />
import cordova = require("cordova");
module Commands {
export interface CommandInfo {
modulePath: string;
description: string;
args: any;
options: any;
}
export class Command {
info: CommandInfo;
constructor() {
}
run() {
cordova.cli(["a", "b"]);
}
}
export class Platform extends Command {
run() {
super.run();
}
}
}
export = Commands;

Просмотреть файл

@ -2,24 +2,30 @@
"create": {
"modulePath": "./create",
"description": "Create a project",
"args": {
"[options]": "",
"<PLATFORM>": ""
},
"options": {
"--template": "generate template"
}
"args": [
{ "name": "arg1", "description": "d1" },
{ "name": "arg2", "description": "d2" }
],
"options": [
{ "name": "opt1", "description": "d1" },
{ "name": "opt2", "description": "d2" }
]
},
"help": {
"modulePath": "./help",
"description": "Get help for a command",
"args": {
"[command]": "Command you want more info on"
}
"description": "Get help for a command"
},
"info": {
"modulePath": "./cordova",
"description": "Generate project information"
"description": "Generate project information",
"args": [
{ "name": "arg1", "description": "d1" },
{ "name": "arg2", "description": "d2" }
],
"options": [
{ "name": "opt1", "description": "d1" },
{ "name": "opt2", "description": "d2" }
]
},
"platform": {
"modulePath": "./cordova",

Просмотреть файл

@ -0,0 +1,20 @@
/// <reference path="../../typings/taco-utils.d.ts" />
/// <reference path="../../typings/node.d.ts" />
/// <reference path="../../typings/cordova.d.ts" />
import cordova = require("cordova");
import tacoUtility = require("taco-utils");
/**
* dfdf
*/
class Cordova extends tacoUtility.Commands.Command {
run() {
console.log("Cordova!!!");
console.log("args: " + this.info.args.length);
console.log("options: " + this.info.args.length);
cordova.cli(["cc", "dd"]);
}
}
export = Cordova;

Просмотреть файл

@ -1,7 +1,16 @@
import commands = require("./command");
/// <reference path="../../typings/taco-utils.d.ts" />
/// <reference path="../../typings/node.d.ts" />
export class Platform extends commands.Command{
import tacoUtility = require("taco-utils");
import cordovaCommand = require("./cordova");
class Create extends cordovaCommand{
run() {
console.log("Create!!!");
console.log("args: " + this.info.args.length);
console.log("options: " + this.info.args.length);
super.run();
}
}
}
export = Create;

Просмотреть файл

@ -7,72 +7,57 @@ import tacoUtility = require("taco-utils");
import nopt = require("nopt");
import fs = require("fs");
import path = require("path");
import cordova = require("cordova");
import commands = require("./command");
class Taco {
constructor() {
var resourcePath: string = path.resolve("../resources");
tacoUtility.ResourcesManager.init("en", resourcePath);
tacoUtility.ResourcesManager.init("en", resourcePath);
}
public run(): void {
CommandFactory.init("./commands.json");
CommandFactory.getTask("create");
//console.log(tacoUtility.ResourcesManager.getString("usage"));
//cordova.cli(["a", "b"]);
//var commandListings = require("./commands.json");
//console.log(commandListings["help"]["module"]);
//if (process.argv[2]) {
// console.log("found");
// console.log("argv[2]: " + process.argv[2]);
//} else {
// console.log("not found");
//}
tacoUtility.Commands.CommandFactory.init("./commands.json");
tacoUtility.Commands.CommandFactory.getTask("info").run();
}
}
class CommandFactory {
private static Listings: any;
private static Instance: commands.Command;
//class CommandFactory {
// private static Listings: any;
// private static Instance: commands.Command;
//private static info: commands.CommandInfo;
public static init(commandsInfoPath: string) {
if (!fs.existsSync(commandsInfoPath)) {
throw new Error("Cannot find commands listing file");
}
// // initialize with json file containing commands
// public static init(commandsInfoPath: string) {
// if (!fs.existsSync(commandsInfoPath)) {
// throw new Error("Cannot find commands listing file");
// }
CommandFactory.Listings = require(commandsInfoPath);
var modulePath: string = CommandFactory.Listings["create"]["modulePath"];
console.log("modulePath: " + modulePath);
}
// CommandFactory.Listings = require(commandsInfoPath);
// }
public static getTask(name: string): commands.Command {
if (!name || !CommandFactory.Listings) {
throw new Error("Cannot find command listing");
}
// // get specific task object, given task name
// public static getTask(name: string): commands.Command {
// if (!name || !CommandFactory.Listings) {
// throw new Error("Cannot find command listing file");
// }
if (CommandFactory.Instance) {
return CommandFactory.Instance;
}
// if (CommandFactory.Instance) {
// return CommandFactory.Instance;
// }
var modulePath: string = CommandFactory.Listings[name]["modulePath"];
console.log(modulePath);
//if (!fs.existsSync(modulePath)) {
// throw new Error("Cannot find command module: " + modulePath);
//}
// var moduleInfo: commands.CommandInfo = CommandFactory.Listings[name];
// var modulePath: string = moduleInfo.modulePath;
// if (!fs.existsSync(modulePath + ".js")) {
// throw new Error("Cannot find command module");
// }
//var commandMod: typeof commands.Command = require(modulePath);
//CommandFactory.Instance = new commandMod();
//if (!CommandFactory.Instance) {
// throw new Error("Can't build command instance");
//}
// var commandMod: typeof commands.Command = require(modulePath);
// CommandFactory.Instance = new commandMod(moduleInfo);
// if (!CommandFactory.Instance) {
// throw new Error("Can't build command instance");
// }
//CommandFactory.Instance.run();
}
}
// CommandFactory.Instance.run();
// }
//}
var taco = new Taco();
taco.run();

Просмотреть файл

@ -5,11 +5,68 @@ import fs = require ("fs");
import path = require ("path");
module TacoUtility {
//export class CommandsManager {
// public static init() {
// }
//}
export module Commands {
export interface nameDescription {
name: string;
description: string;
}
export interface CommandInfo {
modulePath: string;
description: string;
args: nameDescription[];
options: nameDescription[];
}
export class Command {
info: CommandInfo;
constructor(input: CommandInfo) {
this.info = input;
}
public run() {
}
}
export class CommandFactory {
private static Listings: any;
private static Instance: Command;
// initialize with json file containing commands
public static init(commandsInfoPath: string) {
commandsInfoPath = path.resolve(commandsInfoPath);
if (!fs.existsSync(commandsInfoPath)) {
throw new Error("Cannot find commands listing file");
}
CommandFactory.Listings = require(commandsInfoPath);
}
// get specific task object, given task name
public static getTask(name: string): Command {
if (!name || !CommandFactory.Listings) {
throw new Error("Cannot find command listing file");
}
if (CommandFactory.Instance) {
return CommandFactory.Instance;
}
var moduleInfo: CommandInfo = CommandFactory.Listings[name];
var modulePath: string = path.resolve(moduleInfo.modulePath);
if (!fs.existsSync(modulePath + ".js")) {
throw new Error("Cannot find command module");
}
var commandMod: typeof Command = require(modulePath);
CommandFactory.Instance = new commandMod(moduleInfo);
if (!CommandFactory.Instance) {
throw new Error("Can't build command instance");
}
return CommandFactory.Instance;
}
}
}
// put more classes here, known limitation that classes in external modules CANNOT span multiple files
export class ResourcesManager {

23
src/typings/taco-utils.d.ts поставляемый
Просмотреть файл

@ -1,5 +1,28 @@
/// <reference path="../typings/node.d.ts" />
declare module TacoUtility {
module Commands {
interface nameDescription {
name: string;
description: string;
}
interface CommandInfo {
modulePath: string;
description: string;
args: nameDescription[];
options: nameDescription[];
}
class Command {
info: CommandInfo;
constructor(input: CommandInfo);
run(): void;
}
class CommandFactory {
private static Listings;
private static Instance;
static init(commandsInfoPath: string): void;
static getTask(name: string): Command;
}
}
class ResourcesManager {
private static Resources;
private static DefaultLanguage;