public static async Task UpdateFigmaFilesAsync(this Project sender, IEnumerable <ProjectFile> projectFiles, FigmaBundle figmaBundle, FigmaFileVersion version, bool translateStrings) { var includeImages = true; var fileProvider = new FigmaRemoteFileProvider() { Version = version }; await fileProvider.LoadAsync(figmaBundle.FileId); Console.WriteLine($"[Done] Loaded Remote File provider for Version {version?.id ?? "Current"}"); var codeRendererService = new NativeViewCodeService(fileProvider); await Task.Run(() => { figmaBundle.Update(version, includeImages: includeImages); }); await sender.IncludeBundleAsync(figmaBundle, includeImages : includeImages); foreach (var designerFile in projectFiles) { if (designerFile.TryGetFigmaNode(fileProvider, out var figmaNode)) { var fileView = figmaBundle.GetFigmaFileView(figmaNode); fileView.GeneratePartialDesignerClass(codeRendererService, designerFile.FilePath.ParentDirectory, figmaBundle.Namespace, translateStrings); } } }
async Task GenerateBundle(string fileId, FigmaFileVersion version, string namesSpace, bool includeImages, bool translateLabels) { IdeApp.Workbench.StatusBar.AutoPulse = true; IdeApp.Workbench.StatusBar.BeginProgress($"Adding package ‘{fileId}’…"); //we need to ask to figma server to get nodes as demmand var fileProvider = new FigmaRemoteFileProvider(); await fileProvider.LoadAsync(fileId); //bundle generation var currentBundle = await Task.Run(() => { var bundle = currentProject.CreateBundle(fileId, version, fileProvider, namesSpace); bundle.SaveAll(includeImages); return(bundle); }); //now we need to add to Monodevelop all the stuff await currentProject.IncludeBundleAsync(currentBundle, includeImages, savesInProject : false); //to generate all layers we need a code renderer var codeRendererService = new NativeViewCodeService(fileProvider); var mainFigmaNodes = fileProvider.GetMainGeneratedLayers(); foreach (var figmaNode in mainFigmaNodes) { if (!(figmaNode is FigmaFrame) || (figmaNode is FigmaGroup)) { continue; } var figmaBundleView = currentBundle.GetFigmaFileView(figmaNode); figmaBundleView.Generate(codeRendererService, writePublicClassIfExists: false, namesSpace: currentBundle.Namespace, translateLabels); await currentProject.AddFigmaBundleViewAsync(figmaBundleView, savesInProject : false); } await IdeApp.ProjectOperations.SaveAsync(currentProject); IdeApp.Workbench.StatusBar.EndProgress(); IdeApp.Workbench.StatusBar.AutoPulse = false; }