зеркало из https://github.com/microsoft/TACO.git
commands factory
This commit is contained in:
Родитель
2a6c42da46
Коммит
69fc554942
|
@ -5,11 +5,10 @@ var fs = require("fs");
|
|||
var gulp = require("gulp");
|
||||
var del = require("del");
|
||||
var path = require("path");
|
||||
var exec = require("child_process").exec;
|
||||
import dtsUtil = require ("../tools/tsdefinition-util");
|
||||
import stylecopUtil = require ("../tools/stylecop-util");
|
||||
import tsUtil = require ("./taco-cli/compile/typescript-util");
|
||||
var buildConfig = require("../../src/build_config.json");
|
||||
var buildConfig = require ("../../src/build_config.json");
|
||||
|
||||
/* Default task for building /src folder into /bin */
|
||||
gulp.task("default", ["build"]);
|
||||
|
@ -51,6 +50,7 @@ gulp.task("clean", function (callback: Function): void {
|
|||
gulp.task("copy", function (callback: Function): void {
|
||||
gulp.src(path.join(buildConfig.src, "/**/package.json")).pipe(gulp.dest(buildConfig.bin));
|
||||
gulp.src(path.join(buildConfig.src, "/**/resources.json")).pipe(gulp.dest(buildConfig.bin));
|
||||
gulp.src(path.join(buildConfig.src, "/**/commands.json")).pipe(gulp.dest(buildConfig.bin));
|
||||
});
|
||||
|
||||
/* auto-generate taco-utils.d.ts*/
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/// <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;
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"create": {
|
||||
"modulePath": "./create",
|
||||
"description": "Create a project",
|
||||
"args": {
|
||||
"[options]": "",
|
||||
"<PLATFORM>": ""
|
||||
},
|
||||
"options": {
|
||||
"--template": "generate template"
|
||||
}
|
||||
},
|
||||
"help": {
|
||||
"modulePath": "./help",
|
||||
"description": "Get help for a command",
|
||||
"args": {
|
||||
"[command]": "Command you want more info on"
|
||||
}
|
||||
},
|
||||
"info": {
|
||||
"modulePath": "./cordova",
|
||||
"description": "Generate project information"
|
||||
},
|
||||
"platform": {
|
||||
"modulePath": "./cordova",
|
||||
"description": "Manage project platforms"
|
||||
},
|
||||
"plugin": {
|
||||
"modulePath": "./cordova",
|
||||
"description": "Manage project plugins"
|
||||
},
|
||||
"prepare": {
|
||||
"modulePath": "./cordova",
|
||||
"description": "Copy files into platform(s) for building"
|
||||
},
|
||||
"compile": {
|
||||
"modulePath": "./cordova",
|
||||
"description": "Build platform(s)"
|
||||
},
|
||||
"run": {
|
||||
"modulePath": "./cordova",
|
||||
"description": "Run project (including prepare && compile)"
|
||||
},
|
||||
"serve": {
|
||||
"modulePath": "./cordova",
|
||||
"description": "Run project with a local webserver (including prepare)"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import commands = require("./command");
|
||||
|
||||
export class Platform extends commands.Command{
|
||||
run() {
|
||||
console.log("Create!!!");
|
||||
}
|
||||
}
|
|
@ -1,19 +1,76 @@
|
|||
/// <reference path="../../typings/taco-utils.d.ts" />
|
||||
/// <reference path="../../typings/node.d.ts" />
|
||||
/// <reference path="../../typings/nopt.d.ts" />
|
||||
/// <reference path="../../typings/cordova.d.ts" />
|
||||
|
||||
import tacoUtility = require ("taco-utils");
|
||||
import nopt = require ("nopt");
|
||||
import path = require ("path");
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
public run(): void {
|
||||
console.log(tacoUtility.ResourcesManager.getString("usage"));
|
||||
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");
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
CommandFactory.Listings = require(commandsInfoPath);
|
||||
var modulePath: string = CommandFactory.Listings["create"]["modulePath"];
|
||||
console.log("modulePath: " + modulePath);
|
||||
}
|
||||
|
||||
public static getTask(name: string): commands.Command {
|
||||
if (!name || !CommandFactory.Listings) {
|
||||
throw new Error("Cannot find command listing");
|
||||
}
|
||||
|
||||
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 commandMod: typeof commands.Command = require(modulePath);
|
||||
//CommandFactory.Instance = new commandMod();
|
||||
//if (!CommandFactory.Instance) {
|
||||
// throw new Error("Can't build command instance");
|
||||
//}
|
||||
|
||||
//CommandFactory.Instance.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,12 @@ import fs = require ("fs");
|
|||
import path = require ("path");
|
||||
|
||||
module TacoUtility {
|
||||
//export class CommandsManager {
|
||||
// public static init() {
|
||||
|
||||
// }
|
||||
//}
|
||||
|
||||
// put more classes here, known limitation that classes in external modules CANNOT span multiple files
|
||||
export class ResourcesManager {
|
||||
private static Resources: any = null;
|
||||
|
|
|
@ -34,7 +34,8 @@ declare module "cordova" {
|
|||
export function on(event: string, ...args: any[]) : void;
|
||||
export function off(event: string, ...args: any[]) : void;
|
||||
export function emit(event: string, ...args: any[]) : void;
|
||||
export function trigger(event: string, ...args: any[]) : void;
|
||||
export function trigger(event: string, ...args: any[]): void;
|
||||
export function cli(args: string[]): void;
|
||||
export var raw: ICordovaRaw;
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче