This commit is contained in:
Leo Lee (DEVDIV) 2015-01-30 17:08:53 -08:00
Родитель 294df730ed
Коммит 2e42fd0a93
19 изменённых файлов: 405 добавлений и 517 удалений

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

@ -19,18 +19,13 @@
],
"main": "utility.js",
"dependencies": {
"cordova": "^4.2.0",
"nconf": "^0.7.1",
"nopt": "^3.0.1",
"q": "^1.1.2"
},
},
"private": true,
"devDependencies": {
"typescript": ">=1.4.1",
"del": "^1.0.0",
"event-stream": "^3.1.7",
"gulp": "^3.8.10",
"gulp-concat": "^2.4.2",
"jake": "latest",
"mocha": "latest"
"ncp": "^1.0.1",
"q": "^1.1.2"
}
}

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

@ -1,79 +0,0 @@
/// <reference path="typings/node.d.ts" />
var fs = require("fs");
var gulp = require("gulp");
var path = require("path");
var exec = require("child_process").exec;
import typescriptUtil = require("../tools/typescript-util");
import styleCopUtil = require("../tools/stylecop-util");
var del = require("del");
var ncp = require("ncp");
var compilerPath = {
src: "../../src", // gulp task compiles all source under "taco-cli" source folder
bin: "../../bin",
};
////////////////// to add additional gulp tasks, add gulpfile in folder and reference it below
// for example: require('./src/compile/gulpfile');
///////////////////////
/* Default task for compiler - runs clean, compile, combine. */
gulp.task("default", ["installBinDependencies", "styleCop", "copyResources"]);
/* Compiles the typescript files in the project, for fast iterative use */
gulp.task("fast-compile", function (cb: Function): void {
var tsUtil = new typescriptUtil.TacoUtils.TypescriptServices();
console.log("compilerPath.src: " + path.resolve(compilerPath.src));
console.log("compilerPath.bin: " + path.resolve(compilerPath.bin));
tsUtil.compileDirectory(compilerPath.src, compilerPath.bin, cb);
});
/* full clean build */
gulp.task("compile", ["clean"], function (cb: Function): void {
var tsUtil = new typescriptUtil.TacoUtils.TypescriptServices();
console.log("compilerPath.src: " + path.resolve(compilerPath.src));
console.log("compilerPath.bin: " + path.resolve(compilerPath.bin));
tsUtil.compileDirectory(compilerPath.src, compilerPath.bin, cb);
});
/* Runs style cop on the sources. */
gulp.task("styleCop", function (cb: Function): void {
var copFile = "../../tools/TSStyleCop/TSStyleCop.js";
if (fs.existsSync("copFile")) {
var styleCop = new styleCopUtil.TacoUtils.StyleCopUtil();
styleCop.runCop(compilerPath.src, copFile, cb);
} else {
cb();
}
});
/* Cleans up the bin location. */
gulp.task("clean", function (cb: Function): void {
del([compilerPath.bin + "**"], { force: true }, cb);
});
/* copy package.json files from source to bin */
gulp.task("copyPackageJSON", ["compile"], function (cb: Function): void {
var cliPath: string = "/taco-cli/package.json";
var utilPath: string = "/taco-utility/package.json";
fs.writeFileSync("../../bin" + cliPath, fs.readFileSync("../../src" + cliPath));
fs.writeFileSync("../../bin" + utilPath, fs.readFileSync("../../src" + utilPath));
cb();
});
/* copy package.json files from source to bin */
gulp.task("copyResources", ["compile"], function (cb: Function): void {
ncp("../../src/taco-cli/resources", "../../bin/taco-cli/resources", {clobber: true}, cb)
});
/* with package.json files setup in Bin folder, call npm install */
gulp.task("installBinDependencies", ["copyPackageJSON"], function (cb: Function): void {
exec("npm install", { cwd: "../../bin/taco-cli" }, cb);
});
/* Task to generate NPM package */
/* Test */
module.exports = gulp;

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

@ -5,7 +5,7 @@ var exec = require("child_process").exec,
gulp = require("gulp");
/*default task*/
gulp.task("default", ["runCompiledGulp"], function (cb) {
gulp.task("default", ["run-compiled-gulp"], function (callback) {
console.log("************************************************************");
console.log("Prepared taco-cli project for first use.....");
console.log("Run 'gulp' in current folder or 'gulp fast-compile --gulpfile gulp-compile.js' in ../build/src for incremental builds");
@ -13,33 +13,24 @@ gulp.task("default", ["runCompiledGulp"], function (cb) {
});
/* Runs the compiled gulp file */
gulp.task("runCompiledGulp", ["compileTSGulpFiles"], function (cb) {
exec("gulp --gulpfile gulp-compile.js", { cwd: "../build/src" }, cb);
gulp.task("run-compiled-gulp", ["compile-gulpmain"], function (callback) {
var arg = process.argv.slice(2);
var gulpOption = "";
if (arg && arg[0])
gulpOption = arg[0].replace("--", "");
var gulpCommand = "gulp " + gulpOption + " --gulpfile gulpmain.js";
console.log("---executing: " + gulpCommand);
exec(gulpCommand, { cwd: "../build" }, callback);
});
/* compile the gulp-compile.ts file into JS */
gulp.task("compileTSGulpFiles", ["installRootFolderGulp", "installRootFolderTypeScript", "installRootFolderDel", "installRootFolderNcp"], function (cb) {
exec("tsc gulp-compile.ts --outdir ../build --module commonjs", { cwd: "." }, cb);
gulp.task("compile-gulpmain", ["install-root-folder-packages"], function (callback) {
exec("tsc gulpmain.ts --outdir ../build --module commonjs", { cwd: "." }, callback);
});
/* install gulp in root folder */
gulp.task("installRootFolderGulp", function (cb) {
exec("npm install gulp", { cwd: ".." }, cb);
});
/* install typescript in root folder */
gulp.task("installRootFolderTypeScript", function (cb) {
exec("npm install typescript", { cwd: ".." }, cb);
});
/* install del in root folder */
gulp.task("installRootFolderDel", function (cb) {
exec("npm install del", { cwd: ".." }, cb);
});
/* install del in root folder */
gulp.task("installRootFolderNcp", function (cb) {
exec("npm install ncp", { cwd: ".." }, cb);
gulp.task("install-root-folder-packages", function (callback) {
exec("npm install", { cwd: ".." }, callback);
});
module.exports = gulp;

82
src/gulpmain.ts Normal file
Просмотреть файл

@ -0,0 +1,82 @@
/// <reference path="typings/node.d.ts" />
/// <reference path="typings/q.d.ts" />
var fs = require("fs");
var gulp = require("gulp");
var path = require("path");
var exec = require("child_process").exec;
import stylecopUtil = require("./taco-cli/compile/stylecop-util");
import tsUtil = require("./taco-cli/compile/typescript-util");
var del = require("del");
var ncp = require("ncp");
var Q = require("q");
var compilerPath = {
src: "../src", // gulp task compiles all source under "taco-cli" source folder
bin: "../bin",
};
var copFile = path.join(compilerPath.src, "taco-cli/compile/TSStyleCop/TSStyleCop.js");
////////////////// to add additional gulp tasks, add gulpfile in folder and reference it below
// for example: require('./src/compile/gulpfile');
///////////////////////
/* Default task for building /src folder into /bin */
gulp.task("default", ["copy-package-json", "rebuild", "run-stylecop", "copy-resources"]);
/* Compiles the typescript files in the project, for fast iterative use */
gulp.task("compile", function (callback: Function): void {
compileTS(callback);
});
/* full clean build */
gulp.task("rebuild", ["clean"], function (callback: Function): void {
compileTS(callback);
});
/* Runs style cop on the sources. */
gulp.task("run-stylecop", function (callback: Function): void {
if (fs.existsSync("copFile")) {
var styleCop = new stylecopUtil.StyleCopUtil();
styleCop.runCop(compilerPath.src, copFile, callback);
} else {
callback();
}
});
/* Cleans up the bin location. */
gulp.task("clean", function (callback: Function): void {
del([compilerPath.bin + "**"], { force: true }, callback);
});
/* copy package.json files from source to bin */
gulp.task("copy-package-json", ["rebuild"], function (callback: Function): void {
var cliPath: string = "/taco-cli/package.json";
var utilPath: string = "/taco-utils/package.json";
fs.writeFileSync(path.join(compilerPath.bin, cliPath), fs.readFileSync(path.join(compilerPath.src, cliPath)));
fs.writeFileSync(path.join(compilerPath.bin, utilPath), fs.readFileSync(path.join(compilerPath.src, utilPath)));
callback();
});
/* copy package.json files from source to bin */
gulp.task("copy-resources", ["rebuild"], function (callback: Function): void {
ncp(path.join(compilerPath.src, "taco-cli/resources"), path.join(compilerPath.bin, "taco-cli/resources"), {clobber: true}, callback)
});
/* with package.json files setup in Bin folder, call npm install */
gulp.task("install-bin-modules", ["copy-package-json"], function (callback: Function): void {
exec("npm install", { cwd: path.join(compilerPath.bin, "taco-cli")}, callback);
});
function compileTS(callback: Function) {
var tsCompiler = new tsUtil.TypeScriptServices();
console.log("compilerPath.src: " + path.resolve(compilerPath.src));
console.log("compilerPath.bin: " + path.resolve(compilerPath.bin));
tsCompiler.compileDirectory(compilerPath.src, compilerPath.bin, callback);
}
/* Task to generate NPM package */
/* Task to run tests */
module.exports = gulp;

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

@ -8,5 +8,5 @@
* [Node.js](http://nodejs.org/)
# Development
To get started, run "node PreProject.js from taco-cli folder"
To get started, run "gulp" from /src folder

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

@ -1,20 +1,21 @@
///<reference path="../../typings/taco-utility.d.ts"/>
///<reference path="../../typings/taco-utils.d.ts"/>
///<reference path="../../typings/node.d.ts"/>
///<reference path="../../typings/nopt.d.ts"/>
import tacoUtility = require("taco-utility");
import tacoUtility = require("taco-utils");
import nopt = require("nopt");
import path = require("path");
class Taco {
tacoResources: tacoUtility.Resources;
resources: tacoUtility.ResourcesManager;
constructor() {
var resourcePath : string = path.resolve("../resources");
this.tacoResources = new tacoUtility.Resources("en", resourcePath);
var resourcePath: string = path.resolve("../resources");
this.resources = tacoUtility.ResourcesManager.getInstance();
this.resources.init("en", resourcePath);
}
run(): void {
console.log(this.tacoResources.getString("usage"));
console.log(this.resources.getString("usage"));
}
}

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

@ -0,0 +1,62 @@
import child_process = require ("child_process");
import fs = require ("fs");
import path = require ("path");
/**
* Utility for launching TS style cop as a child process.
*/
export class StyleCopUtil {
private _errorMessage: string = "Style cop validation failed.";
public runCop(srcPath: string, copPath: string, cb: Function): void {
var childProcessCallback = (error: Error, stdout: Buffer, stderr: Buffer): void => {
if (stdout) {
console.log(stdout);
cb(this._errorMessage);
}
if (stderr) {
console.error(stderr);
cb(this._errorMessage);
}
if (error) {
console.error(error);
cb(this._errorMessage);
}
if (!stdout && !stderr && !error) {
cb();
}
};
var excludedFiles = this.getProjectTypescriptDefinitionFiles(srcPath, []);
var styleCopCommand = "node " + copPath + " -analyze " + srcPath + (excludedFiles ? " -exclude " + excludedFiles.join(" ") : "");
child_process.exec(styleCopCommand, childProcessCallback);
}
/**
* Recursively finds all the typescript files under the filesRoot path.
*/
public getProjectTypescriptDefinitionFiles(filesRoot: string, result: string[]): string[] {
if (fs.existsSync(filesRoot)) {
var files = fs.readdirSync(filesRoot);
for (var i = 0; i < files.length; i++) {
var currentPath = path.join(filesRoot, files[i]);
if (!fs.statSync(currentPath).isDirectory()) {
/* push the typescript files */
if (currentPath.match("d.ts$")) {
result.push(path.basename(currentPath));
}
} else {
/* call the function recursively for subdirectories */
this.getProjectTypescriptDefinitionFiles(currentPath, result);
}
}
}
return result;
}
}

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

@ -0,0 +1,86 @@
/// <reference path="../../typings/typescript.d.ts" />
import ts = require ("typescript");
import fs = require ("fs");
import path = require ("path");
export class TypeScriptServices {
private static FailureMessage = "Typescript compilation failed.";
/**
* Compiles typescript files based on the provided compiler options.
*/
public compileTypescript(options: ts.CompilerOptions, filenames: string[], cb: Function): void {
var host = ts.createCompilerHost(options);
var program = ts.createProgram(filenames, options, host);
var checker = ts.createTypeChecker(program, true);
var result = checker.emitFiles();
var allDiagnostics = program.getDiagnostics()
.concat(checker.getDiagnostics())
.concat(result.diagnostics);
allDiagnostics.forEach(diagnostic => this.logDiagnosticMessage(diagnostic));
if (result.emitResultStatus !== 0) {
/* compilation failed */
if (cb) {
cb(TypeScriptServices.FailureMessage);
}
} else {
/* compilation succeeded */
cb();
}
}
/**
* Recursively finds all the typescript files under the filesRoot path.
*/
public getProjectTypescriptFiles(filesRoot: string, result: string[]): string[] {
if (fs.existsSync(filesRoot)) {
var files = fs.readdirSync(filesRoot);
for (var i = 0; i < files.length; i++) {
var currentPath = path.join(filesRoot, files[i]);
if (!fs.statSync(currentPath).isDirectory()) {
/* push the typescript files */
if (path.extname(currentPath) === ".ts" &&
!currentPath.match("d.ts$") &&
!currentPath.match("gulpfile.ts") &&
!currentPath.match("gulp-compile.ts")) {
result.push(currentPath);
}
} else {
/* call the function recursively for subdirectories */
this.getProjectTypescriptFiles(currentPath, result);
}
}
}
return result;
}
/**
* Compiles a diectory using the default settings, and the given source and destination location.
*/
public compileDirectory(sourceDirectory: string, outputDirectory: string, cb: Function): void {
var sourceFiles = this.getProjectTypescriptFiles(sourceDirectory, []);
this.compileTypescript({
noImplicitAny: true,
noEmitOnError: true,
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
outDir: outputDirectory
}, sourceFiles, cb);
}
/**
* Pretty-prints a diagnostic message to the console.
*/
private logDiagnosticMessage(diagnostic: ts.Diagnostic): void {
var sourceFile = diagnostic.file;
var lineAndCharacter = sourceFile.getLineAndCharacterFromPosition(diagnostic.start);
console.warn(sourceFile.filename + "(" + lineAndCharacter.line + "," + lineAndCharacter.character + "): " + diagnostic.messageText);
}
}

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

@ -8,7 +8,7 @@
"licenses": [
{
"type": "Apache License 2.0",
"url": "https://xxxxxxxgithub.com/Microsoft/TypeScript/blob/master/LICENSE.txt"
"url": "https://xxxxxgithub.com/Microsoft/TypeScript/blob/master/LICENSE.txt"
}
],
"description": "taco-cli is a command-line interface for rapid Apache Cordova development",
@ -20,11 +20,11 @@
"cross-platform"
],
"bugs": {
"url": "https://xxxxxxxgithub.com/Microsoft/taco-cli/issues"
"url": "https://xxxxxgithub.com/Microsoft/taco-cli/issues"
},
"repository": {
"type": "git",
"url": "https://xxxxxxxxxxgithub.com/Microsoft/taco-cli.git"
"url": "https://xxxxxgithub.com/Microsoft/taco-cli.git"
},
"preferGlobal": true,
"main": "./bin/taco-cli.js",
@ -39,9 +39,9 @@
"nconf": "^0.7.1",
"nopt": "^3.0.1",
"q": "^1.1.2",
"taco-utility": "file:../taco-utility"
"taco-utils": "file:../taco-utils"
},
"bundledDependencies": ["taco-utility"],
"bundledDependencies": ["taco-utils"],
"devDependencies": {
"typescript": ">=1.4.1",
"del": "^1.0.0",
@ -53,13 +53,5 @@
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"maintainers": [
{
"name": "xxxxxxx",
"email": "xxxxxxxxxxx@microsoft.com"
}
],
"directories": {},
"_resolved": "https://xxxxxxregistry.npmjs.org/typescript/-/typescript-1.4.1.tgz"
}
}

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

@ -1,3 +1,4 @@
{
"usage": "Usage: taco-cli command args"
{
"usage": "Usage: taco-cli command args",
"_usage.comment": "Usage string shown on first use in CLI"
}

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

@ -1,174 +0,0 @@
///<reference path="../typings/node.d.ts"/>
"use strict";
import fs = require("fs");
import path = require("path");
module TacoUtility {
//put more classes here, known limitation that classes in external modules CANNOT span multiple files
export class Remote {
resources: any = null;
defaultLanguage: string = "en";
constructor(language: string, resourcesDir?: string) {
if (!resourcesDir) {
resourcesDir = path.join(__dirname, "..", "resources");
}
var lang = this.bestLanguageMatchOrDefault(language, resourcesDir);
this.resources = this.loadLanguage(lang, resourcesDir);
}
getString(id: string, ...optionalArgs: any[]): string {
if (!this.resources) {
throw new Error("Resources have not been loaded");
}
var s = this.resources[id];
if (!s) {
return s;
}
var args = this.getOptionalArgsArrayFromFunctionCall(arguments, 1);
if (args) {
for (var i: number = 0; i < args.length; i++) {
s = s.replace("{" + i + "}", args[i]);
}
}
return s;
}
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string {
if (!language) {
return this.defaultLanguage;
}
var supportedLanguages: string[] = [];
fs.readdirSync(resourcesDir).filter(function (c: string): boolean {
return fs.existsSync(path.join(resourcesDir, c, "resources.json"));
}).forEach(function (l: string): void {
supportedLanguages.push(l.toLowerCase());
});
// TODO: remove assumption of case insensitive file system, so this can work on non-windows systems.
var lang = language.toLowerCase();
if (supportedLanguages.indexOf(lang) !== -1) {
// exact match on language, which could include the region (e.g. it-CH), return the match
return lang;
}
var primaryLang = lang.split("-")[0];
if (supportedLanguages.indexOf(primaryLang) !== -1) {
// match on primary language (e.g. it from it-CH).
return primaryLang;
}
return this.defaultLanguage;
}
loadLanguage(language: string, resourcesDir: string): any {
var resourcesPath = path.join(resourcesDir, language, "resources.json");
return require(resourcesPath);
}
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[] {
if (functionArguments.length <= startFrom) {
return null;
}
if (Array.isArray(functionArguments[startFrom])) {
return functionArguments[startFrom];
}
return Array.prototype.slice.apply(functionArguments, [startFrom]);
}
}
export class Resources {
resources: any = null;
defaultLanguage: string = "en";
constructor(language: string, resourcesDir?: string) {
if (!resourcesDir) {
resourcesDir = path.join(__dirname, "..", "resources");
}
var lang = this.bestLanguageMatchOrDefault(language, resourcesDir);
this.resources = this.loadLanguage(lang, resourcesDir);
}
getString(id: string, ...optionalArgs: any[]): string {
if (!this.resources) {
throw new Error("Resources have not been loaded");
}
var s = this.resources[id];
if (!s) {
return s;
}
var args = this.getOptionalArgsArrayFromFunctionCall(arguments, 1);
if (args) {
for (var i: number = 0; i < args.length; i++) {
s = s.replace("{" + i + "}", args[i]);
}
}
return s;
}
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string {
if (!language) {
return this.defaultLanguage;
}
var supportedLanguages: string[] = [];
fs.readdirSync(resourcesDir).filter(function (c: string): boolean {
return fs.existsSync(path.join(resourcesDir, c, "resources.json"));
}).forEach(function (l: string): void {
supportedLanguages.push(l.toLowerCase());
});
// TODO: remove assumption of case insensitive file system, so this can work on non-windows systems.
var lang = language.toLowerCase();
if (supportedLanguages.indexOf(lang) !== -1) {
// exact match on language, which could include the region (e.g. it-CH), return the match
return lang;
}
var primaryLang = lang.split("-")[0];
if (supportedLanguages.indexOf(primaryLang) !== -1) {
// match on primary language (e.g. it from it-CH).
return primaryLang;
}
return this.defaultLanguage;
}
loadLanguage(language: string, resourcesDir: string): any {
var resourcesPath = path.join(resourcesDir, language, "resources.json");
return require(resourcesPath);
}
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[] {
if (functionArguments.length <= startFrom) {
return null;
}
if (Array.isArray(functionArguments[startFrom])) {
return functionArguments[startFrom];
}
return Array.prototype.slice.apply(functionArguments, [startFrom]);
}
}
}
export = TacoUtility;

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

@ -1,5 +1,5 @@
{
"name": "taco-utility",
"name": "taco-utils",
"author": {
"name": "Microsoft Corp."
},
@ -17,10 +17,11 @@
"Apache",
"cross-platform"
],
"main": "taco-utility.js",
"dependencies" : {
"typescript": ">=1.4.1"
"main": "taco-utils.js",
"dependencies": {
},
"private": true,
"devDependencies": {
"typescript": ">=1.4.1"
}
}

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

@ -0,0 +1,116 @@
///<reference path="../typings/node.d.ts"/>
"use strict";
import fs = require("fs");
import path = require("path");
module TacoUtility {
//put more classes here, known limitation that classes in external modules CANNOT span multiple files
export class ResourcesManager {
private static _instance: ResourcesManager = null;
private resources: any = null;
private defaultLanguage: string = "en";
public static getInstance(): ResourcesManager {
if (!ResourcesManager._instance) {
ResourcesManager._instance = new ResourcesManager();
}
return ResourcesManager._instance;
}
constructor() {
if (ResourcesManager._instance) {
throw new Error("Error: instantiation failed, use ResourcesManager.getInstance() instead of new()");
}
else
return this;
}
init(language: string, resourcesDir?: string) {
if (!resourcesDir) {
resourcesDir = path.join(__dirname, "..", "resources");
}
var lang = this.bestLanguageMatchOrDefault(language, resourcesDir);
this.resources = this.loadLanguage(lang, resourcesDir);
}
/**** ...optionalArgs is only there for typings, function rest params***/
getString(id: string, ...optionalArgs: any[]): string {
if (!this.resources) {
throw new Error("Resources have not been loaded");
}
var s = this.resources[id];
if (!s) {
return s;
}
/*All args passed to current function:
you can call getString('foo', 'bar', 'baz') or getString('foo',['bar', 'baz'])
and the utility function will extract ['bar', 'baz'] as args in both cases*/
var args = this.getOptionalArgsArrayFromFunctionCall(arguments, 1);
if (args) {
for (var i: number = 0; i < args.length; i++) {
s = s.replace("{" + i + "}", args[i]);
}
}
return s;
}
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string {
if (!language) {
return this.defaultLanguage;
}
var supportedLanguages: string[] = [];
fs.readdirSync(resourcesDir).filter(function (c: string): boolean {
return fs.existsSync(path.join(resourcesDir, c, "resources.json"));
}).forEach(function (l: string): void {
supportedLanguages.push(l.toLowerCase());
});
// TODO: remove assumption of case insensitive file system, so this can work on non-windows systems.
var lang = language.toLowerCase();
if (supportedLanguages.indexOf(lang) !== -1) {
// exact match on language, which could include the region (e.g. it-CH), return the match
return lang;
}
var primaryLang = lang.split("-")[0];
if (supportedLanguages.indexOf(primaryLang) !== -1) {
// match on primary language (e.g. it from it-CH).
return primaryLang;
}
return this.defaultLanguage;
}
loadLanguage(language: string, resourcesDir: string): any {
var resourcesPath = path.join(resourcesDir, language, "resources.json");
return require(resourcesPath);
}
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[] {
if (functionArguments.length <= startFrom) {
return null;
}
if (Array.isArray(functionArguments[startFrom])) {
return functionArguments[startFrom];
}
return Array.prototype.slice.apply(functionArguments, [startFrom]);
}
}
}
export = TacoUtility;

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

@ -1,56 +0,0 @@
/// <reference path="../typings/node.d.ts" />
//declare module TacoUtility {
// //put more classes definitions here, known limitation that classes definitions in external modules CANNOT span multiple files
// export class Resources {
// resources: any;
// defaultLanguage: string;
// constructor(language: string, resourcesDir?: string);
// getString(id: string, ...optionalArgs: any[]): string;
// bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
// loadLanguage(language: string, resourcesDir: string): any;
// getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[];
// }
//}
//declare module "taco-utility" {
// module TacoUtility {
// class Resources {
// resources: any;
// defaultLanguage: string;
// constructor(language: string, resourcesDir?: string);
// getString(id: string, ...optionalArgs: any[]): string;
// bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
// loadLanguage(language: string, resourcesDir: string): any;
// getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[];
// }
// }
// export = TacoUtility;
//}
/// <reference path="../typings/node.d.ts" />
declare module TacoUtility {
class Remote {
resources: any;
defaultLanguage: string;
constructor(language: string, resourcesDir?: string);
getString(id: string, ...optionalArgs: any[]): string;
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
loadLanguage(language: string, resourcesDir: string): any;
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[];
}
class Resources {
resources: any;
defaultLanguage: string;
constructor(language: string, resourcesDir?: string);
getString(id: string, ...optionalArgs: any[]): string;
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
loadLanguage(language: string, resourcesDir: string): any;
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[];
}
}
declare module "taco-utility" {
export = TacoUtility;
}

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

@ -0,0 +1,20 @@
/// <reference path="../typings/node.d.ts" />
declare module TacoUtility {
class ResourcesManager {
private static _instance;
private resources;
private defaultLanguage;
static getInstance(): ResourcesManager;
constructor();
init(language: string, resourcesDir?: string): void;
/**** ...optionalArgs is only there for typings, function rest params***/
getString(id: string, ...optionalArgs: any[]): string;
bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
loadLanguage(language: string, resourcesDir: string): any;
getOptionalArgsArrayFromFunctionCall(functionArguments: IArguments, startFrom: number): any[];
}
}
declare module "taco-utils" {
export = TacoUtility;
}

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

@ -1,63 +0,0 @@
import child_process = require ("child_process");
import fs = require ("fs");
import path = require ("path");
export module TacoUtils {
/**
* Utility for launching TS style cop as a child process.
*/
export class StyleCopUtil {
private _errorMessage: string = "Style cop validation failed.";
public runCop(srcPath: string, copPath: string, cb: Function): void {
var childProcessCallback = (error: Error, stdout: Buffer, stderr: Buffer): void => {
if (stdout) {
console.log(stdout);
cb(this._errorMessage);
}
if (stderr) {
console.error(stderr);
cb(this._errorMessage);
}
if (error) {
console.error(error);
cb(this._errorMessage);
}
if (!stdout && !stderr && !error) {
cb();
}
};
var excludedFiles = this.getProjectTypescriptDefinitionFiles(srcPath, []);
var styleCopCommand = "node " + copPath + " -analyze " + srcPath + (excludedFiles ? " -exclude " + excludedFiles.join(" ") : "");
child_process.exec(styleCopCommand, childProcessCallback);
}
/**
* Recursively finds all the typescript files under the filesRoot path.
*/
public getProjectTypescriptDefinitionFiles(filesRoot: string, result: string[]): string[] {
if (fs.existsSync(filesRoot)) {
var files = fs.readdirSync(filesRoot);
for (var i = 0; i < files.length; i++) {
var currentPath = path.join(filesRoot, files[i]);
if (!fs.statSync(currentPath).isDirectory()) {
/* push the typescript files */
if (currentPath.match("d.ts$")) {
result.push(path.basename(currentPath));
}
} else {
/* call the function recursively for subdirectories */
this.getProjectTypescriptDefinitionFiles(currentPath, result);
}
}
}
return result;
}
}
}

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

@ -1,87 +0,0 @@
/// <reference path="../src/typings/typescript.d.ts" />
import ts = require ("typescript");
import fs = require ("fs");
import path = require ("path");
export module TacoUtils {
export class TypescriptServices {
private static FailureMessage = "Typescript compilation failed.";
/**
* Compiles typescript files based on the provided compiler options.
*/
public compileTypescript(options: ts.CompilerOptions, filenames: string[], cb: Function): void {
var host = ts.createCompilerHost(options);
var program = ts.createProgram(filenames, options, host);
var checker = ts.createTypeChecker(program, true);
var result = checker.emitFiles();
var allDiagnostics = program.getDiagnostics()
.concat(checker.getDiagnostics())
.concat(result.diagnostics);
allDiagnostics.forEach(diagnostic => this.logDiagnosticMessage(diagnostic));
if (result.emitResultStatus !== 0) {
/* compilation failed */
if (cb) {
cb(TypescriptServices.FailureMessage);
}
} else {
/* compilation succeeded */
cb();
}
}
/**
* Recursively finds all the typescript files under the filesRoot path.
*/
public getProjectTypescriptFiles(filesRoot: string, result: string[]): string[] {
if (fs.existsSync(filesRoot)) {
var files = fs.readdirSync(filesRoot);
for (var i = 0; i < files.length; i++) {
var currentPath = path.join(filesRoot, files[i]);
if (!fs.statSync(currentPath).isDirectory()) {
/* push the typescript files */
if (path.extname(currentPath) === ".ts" &&
!currentPath.match("d.ts$") &&
!currentPath.match("gulpfile.ts") &&
!currentPath.match("gulp-compile.ts")) {
result.push(currentPath);
}
} else {
/* call the function recursively for subdirectories */
this.getProjectTypescriptFiles(currentPath, result);
}
}
}
return result;
}
/**
* Compiles a diectory using the default settings, and the given source and destination location.
*/
public compileDirectory(sourceDirectory: string, outputDirectory: string, cb: Function): void {
var sourceFiles = this.getProjectTypescriptFiles(sourceDirectory, []);
this.compileTypescript({
noImplicitAny: true,
noEmitOnError: true,
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
outDir: outputDirectory
}, sourceFiles, cb);
}
/**
* Pretty-prints a diagnostic message to the console.
*/
private logDiagnosticMessage(diagnostic: ts.Diagnostic): void {
var sourceFile = diagnostic.file;
var lineAndCharacter = sourceFile.getLineAndCharacterFromPosition(diagnostic.start);
console.warn(sourceFile.filename + "(" + lineAndCharacter.line + "," + lineAndCharacter.character + "): " + diagnostic.messageText);
}
}
}