/// <summary> /// Compiles the given TypeScript source into pure JavaScript. /// </summary> /// <param name="source">The typescript source code to be compiled.</param> /// <param name="fileName">The filename that represents this source code.</param> /// <param name="options">The options to use when compiling.</param> /// <returns>The results of the compilation.</returns> public virtual CompiledModule Compile(string source, string fileName, CompileOptions options) { // // Generate the compilation request. // var request = new CompileRequest { SourceCode = source, FileName = fileName, Options = options }; // // Make sure the queue is running and submit the new request to the queue. // EnsureWorkerThreadRunning(); _sharedQueue.Enqueue(request); _sharedQueueEvent.Set(); // // Wait for up to 30 seconds for the compilation to complete. // if (!request.WaitHandle.WaitOne(30000)) { return(new CompiledModule { FileName = fileName, Success = false, Messages = new[] { "Timeout waiting for compilation to complete." } }); } return(request.CompiledModule); }
/// <summary> /// Compiles the TypeScript file into a JavaScript module. /// </summary> /// <param name="filePath">The file path that contains the TypeScript code.</param> /// <param name="options">The options to use when compiling.</param> /// <returns>The results of the compilation.</returns> public virtual CompiledModule CompileFile(string filePath, CompileOptions options) { string tsSource = File.ReadAllText(filePath); var filename = Path.GetFileName(filePath); return(Compile(tsSource, filename, options)); }
/// <summary> /// Compiles the given TypeScript source into pure JavaScript. /// </summary> /// <param name="source">The typescript source code to be compiled.</param> /// <param name="options">The options to use when compiling.</param> /// <returns>The results of the compilation.</returns> public virtual CompiledModule Compile(string source, CompileOptions options) { return(Compile(source, "module.ts", options)); }