From 2a6c42da46d4bc083b8a673204372a9263e5c28d Mon Sep 17 00:00:00 2001 From: "Leo Lee (DEVDIV)" Date: Tue, 3 Feb 2015 14:59:24 -0800 Subject: [PATCH] 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 --- src/gulpmain.ts | 2 +- src/typings/taco-utils.d.ts | 5 ++--- tools/stylecop-util.ts | 1 - tools/tsdefinition-util.ts | 31 +++++++++++++++++-------------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/gulpmain.ts b/src/gulpmain.ts index 8ea41b0a..63a6f267 100644 --- a/src/gulpmain.ts +++ b/src/gulpmain.ts @@ -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(); } diff --git a/src/typings/taco-utils.d.ts b/src/typings/taco-utils.d.ts index 45b5ffdd..58890253 100644 --- a/src/typings/taco-utils.d.ts +++ b/src/typings/taco-utils.d.ts @@ -1,10 +1,9 @@ /// 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; diff --git a/tools/stylecop-util.ts b/tools/stylecop-util.ts index 459dfc2d..71ab6ede 100644 --- a/tools/stylecop-util.ts +++ b/tools/stylecop-util.ts @@ -2,7 +2,6 @@ import fs = require ("fs"); import path = require ("path"); - /** * Utility for launching TS style cop as a child process. */ diff --git a/tools/tsdefinition-util.ts b/tools/tsdefinition-util.ts index 3547e63e..c2fd291a 100644 --- a/tools/tsdefinition-util.ts +++ b/tools/tsdefinition-util.ts @@ -1,20 +1,21 @@ /// /// - +/// +import Q = require ("q"); +/// 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 { 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; } } \ No newline at end of file