예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        protected override void OnUpdate(CommandInfo info)
        {
            try {
                if (IdeApp.ProjectOperations.CurrentSelectedItem is ProjectFolder currentFolder &&
                    currentFolder.IsDocumentDirectoryBundle()
                    )
                {
                    var manifestFilePath = Path.Combine(currentFolder.Path.FullPath, FigmaBundle.ManifestFileName);

                    if (!File.Exists(manifestFilePath))
                    {
                        throw new FileNotFoundException(manifestFilePath);
                    }

                    var manifest = FigmaManifest.FromFilePath(manifestFilePath);
                    if (manifest.FileId != null)
                    {
                        info.Visible = info.Enabled = true;
                        return;
                    }
                }
                ;
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
            info.Visible = info.Enabled = false;
        }
예제 #3
0
 protected override void OnRun()
 {
     if (IdeApp.ProjectOperations.CurrentSelectedItem is ProjectFolder currentFolder)
     {
         try {
             var manifestFilePath = Path.Combine(currentFolder.Path.FullPath, FigmaBundle.ManifestFileName);
             var manifest         = FigmaManifest.FromFilePath(manifestFilePath);
             if (manifest.FileId != null)
             {
                 IdeServices.DesktopService.ShowUrl(string.Format(figmaUrl, manifest.FileId));
                 return;
             }
         } catch (Exception ex) {
             LoggingService.LogInternalError(ex);
         }
     }
 }
예제 #4
0
        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);
            }
        }