protected async override void OnRun() { if (IdeApp.ProjectOperations.CurrentSelectedItem is ProjectFolder currentFolder) { try { var manifestFilePath = Path.Combine(currentFolder.Path.FullPath, FigmaBundle.ManifestFileName); if (!File.Exists(manifestFilePath)) { var project = currentFolder.Project; var manifest = new FigmaManifest() { Namespace = project.GetDefaultFigmaNamespace(), DocumentVersion = "0", ApiVersion = FigmaSharp.AppContext.Current.Version, RemoteApiVersion = FigmaSharp.AppContext.Api.Version.ToString(), Date = DateTime.Now }; manifest.Save(manifestFilePath); project.AddFile(manifestFilePath); project.NeedsReload = true; await IdeApp.ProjectOperations.SaveAsync(project); } } catch (Exception ex) { LoggingService.LogInternalError(ex); } } }
public void ManifestTest() { var DocumentUrl = "https://www.figma.com/file/fKugSkFGdwOF4vDsPGnJee/"; var RemoteApiVersion = "1.1"; var DocumentVersion = "0.3"; var dateNow = DateTime.Now; var manifest = new FigmaManifest() { Date = dateNow, FileId = DocumentUrl, DocumentVersion = DocumentVersion, RemoteApiVersion = RemoteApiVersion, }; var builder = new StringBuilder(); manifest.ToComment(builder); Assert.IsNotEmpty(builder.ToString()); var tempDirectory = Path.GetTempPath(); var file = Path.Combine(tempDirectory, "manifest"); if (File.Exists(file)) { File.Delete(file); } manifest.Save(file); var copy = FigmaManifest.FromFilePath(file); Assert.AreEqual(copy.DocumentVersion, manifest.DocumentVersion); Assert.AreEqual(copy.Date, manifest.Date); Assert.AreEqual(copy.FileId, manifest.FileId); Assert.AreEqual(copy.RemoteApiVersion, manifest.RemoteApiVersion); if (File.Exists(file)) { File.Delete(file); } }