more stylecop + fixing DTS generation

Change Description:

     1. hooked up styleCop to look in everything under root
     2. fixed up stylecop issues in Tools
     3. Got dts generation to work properly with Q
This commit is contained in:
Leo Lee (DEVDIV) 2015-02-03 14:59:24 -08:00
Родитель a7ed325ea9
Коммит 2a6c42da46
4 изменённых файлов: 20 добавлений и 19 удалений

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

@ -36,7 +36,7 @@ gulp.task("rebuild", ["clean"], function (callback: Function): void {
gulp.task("run-stylecop", function (callback: Function): void {
if (fs.existsSync(buildConfig.copPath)) {
var styleCop = new stylecopUtil.StyleCopUtil();
styleCop.runCop(buildConfig.src, buildConfig.copPath, callback);
styleCop.runCop(path.join(buildConfig.src, ".."), buildConfig.copPath, callback);
} else {
callback();
}

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

@ -1,10 +1,9 @@
/// <reference path="../typings/node.d.ts" />
declare module TacoUtility {
class ResourcesManager {
static resources: any;
static defaultLanguage: string;
private static Resources;
private static DefaultLanguage;
static init(language: string, resourcesDir?: string): void;
/**** ...optionalArgs is only there for typings, function rest params***/
static getString(id: string, ...optionalArgs: any[]): string;
static bestLanguageMatchOrDefault(language: string, resourcesDir: string): string;
static loadLanguage(language: string, resourcesDir: string): any;

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

@ -2,7 +2,6 @@
import fs = require ("fs");
import path = require ("path");
/**
* Utility for launching TS style cop as a child process.
*/

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

@ -1,20 +1,21 @@
/// <reference path="../src/typings/node.d.ts" />
/// <reference path="../src/typings/q.d.ts" />
/// <disable code="SA1301" justification="it is more standard to use 'Q'" />
import Q = require ("q");
/// <enable code="SA1301" />
var exec = require("child_process").exec;
var fs = require("fs");
var path = require("path");
var del = require("del");
var ncp = require("ncp");
var Q = require("q");
/*utility to generate .d.ts file*/
export module DefinitionServices {
export function generateTSExportDefinition(fileName: string, srcFolderPath: string, destFolderPath: string, moduleName: string, moduleString: string) {
export function generateTSExportDefinition(fileName: string, srcFolderPath: string, destFolderPath: string, moduleName: string, moduleString: string): void {
var destDtsFile: string = path.join(destFolderPath, fileName + ".d.ts");
Q(compileDeclarationFile(fileName, srcFolderPath)).
then(copyDTSTypings(fileName, srcFolderPath, destFolderPath)).
then(addExportsInTypings(destDtsFile, "TacoUtility", "taco-utils")).
then(function (): void { copyDTSTypings(fileName, srcFolderPath, destFolderPath); }).
then(function (): void { addExportsInTypings(destDtsFile, "TacoUtility", "taco-utils"); }).
done();
}
@ -26,7 +27,7 @@ export module DefinitionServices {
console.log("---calling: " + tscCommand);
exec(tscCommand, { cwd: "." }, function (error: any, stdout: any, stderr: any): void {
if (error !== null) {
if (error) {
return d.reject(error);
} else {
d.resolve(stdout);
@ -35,27 +36,29 @@ export module DefinitionServices {
return d.promise;
}
function copyDTSTypings(tsFileName: string, srcFolderPath: string, destFolderPath: string) {
function copyDTSTypings(tsFileName: string, srcFolderPath: string, destFolderPath: string): void {
var srcDTSFilePath: string = path.join(srcFolderPath, tsFileName + ".d.ts");
var srcJSFilePath: string = path.join(srcFolderPath, tsFileName + ".js");
var destDTSFilePath: string = path.join(destFolderPath, tsFileName + ".d.ts");
console.log("copying: " + srcDTSFilePath + " to :" + destDTSFilePath);
fs.writeFileSync(destDTSFilePath, fs.readFileSync(srcDTSFilePath));
fs.writeFileSync(destDTSFilePath, fs.readFileSync(srcDTSFilePath));
del([srcDTSFilePath], { force: true });
del([srcJSFilePath], { force: true });
}
/*add wrap "export = moduleName" with "declare module "moduleString"{}"*/
function addExportsInTypings(dtsPath: string, moduleName: string, moduleString: string) {
function addExportsInTypings(dtsPath: string, moduleName: string, moduleString: string): Q.Promise<any> {
var d = Q.defer();
console.log("---reading: " + dtsPath);
var buf: any = fs.readFileSync(dtsPath, 'utf8');
console.log("---processing: " + dtsPath);
var buf: any = fs.readFileSync(dtsPath, "utf8");
var regex: string = "export.*=.*" + moduleName + ".*;";
var match: string[] = buf.match(regex);
if (match && match[0]) {
var foundMatch = match[0];
console.log(foundMatch);
var result = buf.replace(foundMatch, "declare module \"" + moduleString + "\"{\n" + foundMatch + "\n}");
fs.writeFileSync(dtsPath, result, 'utf8');
fs.writeFileSync(dtsPath, result, "utf8");
}
return d.promise;
}
}