public override string ToString() { var renderer = new JsRenderer(); Accept(renderer); return(renderer.Output); }
public async Task<Tuple<string, Project>> CompileProject(string projectFile) { var projectFileInfo = new FileInfo(projectFile); var projectFolder = projectFileInfo.Directory.FullName; // These two lines are just a weird hack because you get no files back from compilation.SyntaxTrees // if the user file isn't modified. Not sure why that's happening. // var projectUserFile = projectFolder + "\\" + projectFileInfo.Name + ".user"; // if (File.Exists(projectUserFile)) // File.SetLastWriteTime(projectUserFile, DateTime.Now); var jsCompilationUnit = new JsCompilationUnit { UseStrict = true }; var workspace = MSBuildWorkspace.Create(); var project = await Profiler.Time("Loading Project", async () => { string mscorlib = this.mscorlib; if (mscorlib == null) { mscorlib = FileUtils.GetWootzJsTargetFile(projectFile); } Project result; if (mscorlib != null) { var mscorlibProject = await workspace.OpenProjectAsync(mscorlib); result = await workspace.OpenProjectAsync(projectFile); result = result.AddProjectReference(new ProjectReference(mscorlibProject.Id)); result = result.RemoveMetadataReference(result.MetadataReferences.Single(x => x.Display.Contains("mscorlib.dll"))); } else { result = await workspace.OpenProjectAsync(projectFile); } return result; }); var projectCompiler = new ProjectCompiler(project, jsCompilationUnit, defines); await projectCompiler.Compile(); // Write out the compiled Javascript file to the target location. var renderer = new JsRenderer(); // renderer.Builder.IsCompacting = true; Profiler.Time("Rendering javascript", () => jsCompilationUnit.Accept(renderer)); return Tuple.Create(renderer.Output, project); }
public async Task<Tuple<string, Solution>> CompileSolution(string solutionFile) { // var solution = await Profiler.Time("Loading Project", async () => await MSBuildWorkspace.Create().OpenSolutionAsync(solutionFile)); var jsCompilationUnit = new JsCompilationUnit { UseStrict = true }; // Since we have all the types required by the solution, we can keep track of which symbols are used and which // are not. This of course means depending on reflection where you don't reference the actual symbol in code // will result in unexpected behavior. RemoveUnusedSymbols = true; var projectFiles = FileUtils.GetProjectFiles(solutionFile); var workspace = MSBuildWorkspace.Create(); var solution = await Profiler.Time("Loading Solution", async () => { string mscorlib = this.mscorlib; if (mscorlib == null) { mscorlib = projectFiles.Select(x => FileUtils.GetWootzJsTargetFile(x)).First(); } Solution result = workspace.CurrentSolution; if (mscorlib != null) { var mscorlibProject = await workspace.OpenProjectAsync(mscorlib); // result = result.AddProject(mscorlibProject.Id, mscorlibProject.Name, mscorlibProject.AssemblyName, mscorlibProject.Language); foreach (var projectFile in projectFiles) { var project = result.Projects.SingleOrDefault(x => x.FilePath.Equals(projectFile, StringComparison.InvariantCultureIgnoreCase)); if (project == null) project = await workspace.OpenProjectAsync(projectFile); // result = result.AddProject(project.Id, project.Name, project.AssemblyName, project.Language); // project = result.GetProject(project.Id); project = project.AddProjectReference(new ProjectReference(mscorlibProject.Id)); project = project.RemoveMetadataReference(project.MetadataReferences.Single(x => x.Display.Contains("mscorlib.dll"))); result = project.Solution; } } else { result = await workspace.OpenSolutionAsync(solutionFile); } return result; }); var projectCompilers = SortProjectsByDependencies(solution).Select(x => new ProjectCompiler(x, jsCompilationUnit, defines)).ToArray(); foreach (var compiler in projectCompilers) { await compiler.Compile(); } // Write out the compiled Javascript file to the target location. var renderer = new JsRenderer(); Profiler.Time("Rendering javascript", () => jsCompilationUnit.Accept(renderer)); // solution.Projects return Tuple.Create(renderer.Output, solution); }