diff --git a/src/gulpfile.js b/src/gulpfile.js index 16ba44d7..d807c028 100644 --- a/src/gulpfile.js +++ b/src/gulpfile.js @@ -17,10 +17,20 @@ gulp.task("prep", ["install"], function (callback) { /* install gulp in root folder */ gulp.task("install", function (callback) { var modules = ["del", "gulp", "typescript", "ncp", "q"]; - for (var i in modules){ - exec("npm install " + modules[i], { cwd: ".." }); - } - callback(); + var asyncLoop = function(idx) { + if (idx < modules.length) { + exec("npm install" + modules[idx], { cwd: ".."}, function(error, stdout, stderr) { + if (!error) { + asyncLoop(idx + 1); + } else { + callback(error); + } + }) + } else { + callback(); + } + } + asyncLoop(0); }); diff --git a/src/gulpmain.ts b/src/gulpmain.ts index 6eec35a6..f2ea338d 100644 --- a/src/gulpmain.ts +++ b/src/gulpmain.ts @@ -55,15 +55,14 @@ gulp.task("copy", function (callback: Function): void { }); /* auto-generate taco-utils.d.ts*/ -gulp.task("generate-dts", function (cb: Function): void { +gulp.task("generate-dts", function (): Q.Promise { var tacoUtils: string = "taco-utils"; - dtsUtil.DefinitionServices.generateTSExportDefinition( + return dtsUtil.DefinitionServices.generateTSExportDefinition( tacoUtils, path.join(buildConfig.src, tacoUtils), path.join(buildConfig.src, "typings"), "TacoUtility", tacoUtils); - cb(); }); /* Task to run tests */ diff --git a/src/taco-utils/taco-utils.ts b/src/taco-utils/taco-utils.ts index 25da100e..54a1dcd4 100644 --- a/src/taco-utils/taco-utils.ts +++ b/src/taco-utils/taco-utils.ts @@ -15,11 +15,7 @@ module TacoUtility { private static SupportedLanguages: string[] = null; private static DefaultLanguage: string = "en"; - public static init(language: string, resourcesDir?: string): void { - if (!resourcesDir) { - resourcesDir = path.join(__dirname, "..", "resources"); - } - + public static init(language: string, resourcesDir: string): void { ResourcesManager.Resources = {}; ResourcesManager.SupportedLanguages = []; fs.readdirSync(resourcesDir).forEach(function (filename: string): void { diff --git a/src/typings/taco-utils.d.ts b/src/typings/taco-utils.d.ts index 35ff932c..1b35dd54 100644 --- a/src/typings/taco-utils.d.ts +++ b/src/typings/taco-utils.d.ts @@ -1,12 +1,13 @@ /// /// /// -declare module TacoUtility { +declare module "taco-utils" { +module TacoUtility { class ResourcesManager { private static Resources; private static SupportedLanguages; private static DefaultLanguage; - static init(language: string, resourcesDir?: string): void; + static init(language: string, resourcesDir: string): void; static teardown(): void; /** ...optionalArgs is only there for typings, function rest params */ static getString(id: string, ...optionalArgs: any[]): string; @@ -99,6 +100,6 @@ declare module TacoUtility { localize(req: any): BuildInfo; } } -declare module "taco-utils"{ export = TacoUtility; + } diff --git a/tools/tsdefinition-util.ts b/tools/tsdefinition-util.ts index c2fd291a..e3797d4e 100644 --- a/tools/tsdefinition-util.ts +++ b/tools/tsdefinition-util.ts @@ -11,12 +11,11 @@ var ncp = require("ncp"); /*utility to generate .d.ts file*/ export module DefinitionServices { - export function generateTSExportDefinition(fileName: string, srcFolderPath: string, destFolderPath: string, moduleName: string, moduleString: string): void { + export function generateTSExportDefinition(fileName: string, srcFolderPath: string, destFolderPath: string, moduleName: string, moduleString: string): Q.Promise { var destDtsFile: string = path.join(destFolderPath, fileName + ".d.ts"); - Q(compileDeclarationFile(fileName, srcFolderPath)). + return Q(compileDeclarationFile(fileName, srcFolderPath)). then(function (): void { copyDTSTypings(fileName, srcFolderPath, destFolderPath); }). - then(function (): void { addExportsInTypings(destDtsFile, "TacoUtility", "taco-utils"); }). - done(); + then(function (): void { addExportsInTypings(destDtsFile, moduleName, moduleString); }); } /*call tsc --d, only option is to generate it in same folder as .ts*/ @@ -46,19 +45,18 @@ export module DefinitionServices { del([srcJSFilePath], { force: true }); } - /*add wrap "export = moduleName" with "declare module "moduleString"{}"*/ - function addExportsInTypings(dtsPath: string, moduleName: string, moduleString: string): Q.Promise { - var d = Q.defer(); + + /*add wrap everything except ///s with "declare module "moduleString"{}"*/ + function addExportsInTypings(dtsPath: string, moduleName: string, moduleString: string): void { console.log("---processing: " + dtsPath); - var buf: any = fs.readFileSync(dtsPath, "utf8"); - var regex: string = "export.*=.*" + moduleName + ".*;"; + var buf: string = fs.readFileSync(dtsPath, "utf8"); + var result: string= buf.replace("declare module " + moduleName, "module " + moduleName); + var regex: string = "(module " + moduleName + ")|(import)"; var match: string[] = buf.match(regex); if (match && match[0]) { var foundMatch = match[0]; - var result = buf.replace(foundMatch, "declare module \"" + moduleString + "\"{\n" + foundMatch + "\n}"); - fs.writeFileSync(dtsPath, result, "utf8"); + result = result.replace(foundMatch, "declare module \"" + moduleString + "\" {\n" + foundMatch) + "\n}\n"; } - - return d.promise; + fs.writeFileSync(dtsPath, result, "utf8"); } -} \ No newline at end of file +}