Skip to content

Add mermaid-to-image extension#17621

Merged
raycastbot merged 17 commits intoraycast:mainfrom
chihkang:ext/mermaid-to-image
Mar 14, 2025
Merged

Add mermaid-to-image extension#17621
raycastbot merged 17 commits intoraycast:mainfrom
chihkang:ext/mermaid-to-image

Conversation

@chihkang
Copy link
Contributor

@chihkang chihkang commented Mar 7, 2025

Description

A Raycast extension that instantly converts Mermaid diagram code from your clipboard into beautiful images.

Screencast

mermaid-to-image-1
mermaid-to-image-2
mermaid-to-image-3

Checklist

- Update images in metadata
- Refactor error handling in mermaid-to-image.tsx
- Update package.json and improve temporary file cleanup
- Update dependencies and fix license year
- Refactor diagram generation logic by simplifying possiblePaths declaration and removing unused stdout and stderr handling
- Add metadata images
- Update README and package files to clarify Mermaid CLI installation and update type definitions
- Refactor image handling and cleanup in Mermaid diagram generation
- Update dependencies and clean up package-lock.json
- Refactor Mermaid diagram generation by removing redundant Node.js path checks and updating command execution logic
- Update dependencies and modify extension icon
- Update documentation and remove unused files
- init
@raycastbot raycastbot added the new extension Label for PRs with new extensions label Mar 7, 2025
@raycastbot
Copy link
Collaborator

Congratulations on your new Raycast extension! 🚀

Due to our current reduced availability, the initial review may take up to 10-15 business days

Once the PR is approved and merged, the extension will be available on our Store.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds a new Mermaid to Image extension that converts Mermaid diagram code from clipboard into PNG/SVG images with multiple theme options and file handling capabilities.

  • Since this is a new extension with view commands in package.json, a metadata folder with screenshots should be added as per extension store guidelines
  • The launchCommand in mermaid-to-image.tsx should be wrapped in try-catch blocks for better error handling
  • Consider adding subtitle with "Mermaid" to the command in package.json to better identify the service
  • The showToast error handling in mermaid-to-image.tsx could be simplified using showFailureToast from @raycast/utils in several places
  • Chinese comments in mermaid-to-image.tsx should be translated to English as Raycast doesn't support localization

💡 (2/5) Greptile learns from your feedback when you react with 👍/👎!

9 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile

@chihkang
Copy link
Contributor Author

chihkang commented Mar 7, 2025

@greptileai check it out now

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds a new Mermaid to Image extension with several updates since the last review.

  • The List component in mermaid-to-image.tsx should use isLoading prop to avoid empty state flicker as per store guidelines
  • The getSelectedText() function should include error handling for cases where text selection fails
  • The title in CHANGELOG.md ("Mermaid-to-image") should match package.json's title ("Mermaid to Image") for consistency
  • Consider adding isLoading state to the Detail component to improve the loading experience

Note: This review focuses on new points not covered in previous reviews, particularly around loading states and error handling improvements.

9 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

@chihkang
Copy link
Contributor Author

chihkang commented Mar 7, 2025

@greptileai check it out now

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

This PR updates the Mermaid to Image extension with improved error handling and loading states.

  • The getSelectedText() function in mermaid-to-image.tsx now includes proper error handling with try-catch blocks and showFailureToast
  • Loading states have been added to both List and Detail components to prevent empty state flicker
  • The CHANGELOG.md title has been updated to match package.json's "Mermaid to Image" for consistency
  • The Detail component now properly handles loading states for better user experience

Note: This summary focuses on recent changes not mentioned in previous reviews, particularly around error handling and loading state improvements.

3 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

@chihkang
Copy link
Contributor Author

chihkang commented Mar 7, 2025

@greptileai check it out now~

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

Based on the latest changes to the Mermaid to Image extension, here's my review focusing on new points not previously covered:

The PR adds improvements to the Mermaid diagram code conversion extension with enhanced error handling and cleanup.

  • The launchCommand function in mermaid-to-image.tsx should handle cleanup of temporary files in both success and error cases to prevent file system clutter
  • Consider adding a check for mmdc command availability before attempting diagram generation to provide better user feedback
  • The execPromise timeout of 10000ms in launchCommand might be insufficient for complex diagrams, consider making this configurable via preferences
  • The clipboard restoration logic in getSelectedText() could be improved to handle edge cases where previousClipboard.text is undefined

Note: This review focuses on new aspects not mentioned in previous reviews, particularly around resource management and edge case handling.

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@chihkang
Copy link
Contributor Author

chihkang commented Mar 7, 2025

@greptileai check it out now~

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

Based on the latest changes to the Mermaid to Image extension, here's my review focusing on new points not previously covered:

This PR adds a configurable timeout and improved file handling to the Mermaid diagram conversion extension.

  • The Preferences and Arguments interfaces in mermaid-to-image.tsx are unnecessary since they are auto-generated in raycast-env.d.ts
  • The findMmdcPath() function should use showFailureToast instead of showToast with Style.Failure for consistency
  • The ImagePreview component could benefit from a loading state while reading image files
  • The savePath preference in package.json should include validation to ensure it's a valid directory path

Note: This review focuses on recent changes and aspects not mentioned in previous reviews, particularly around type definitions and preference validation.

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@chihkang
Copy link
Contributor Author

chihkang commented Mar 7, 2025

@greptileai check it out

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

Based on the latest changes to the Mermaid to Image extension, here's my review focusing on new points not previously covered:

The PR adds improved error handling and loading states to the Mermaid diagram conversion extension.

  • The ImagePreview component in mermaid-to-image.tsx now properly implements loading states with isLoading={true} to prevent UI flicker
  • The showFailureToast from @raycast/utils is now consistently used throughout the codebase for error handling
  • The Preferences interface has been removed as it's auto-generated in raycast-env.d.ts
  • The subtitle has been added to the command in package.json with "Generate Diagram Images from Mermaid Markup" for better service identification

Note: This review focuses on recent changes and aspects not mentioned in previous reviews, particularly around UI improvements and code cleanup.

2 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

@chihkang
Copy link
Contributor Author

chihkang commented Mar 7, 2025

@greptileai check it out

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

Based on the latest changes to the Mermaid to Image extension, here's my review focusing on new points not previously covered:

The PR adds improved error handling and cleanup functionality to the Mermaid diagram conversion extension.

  • The cleanupTempFile function in mermaid-to-image.tsx should be called in the component's cleanup effect to ensure temporary files are removed when unmounting
  • The generationTimeout preference in package.json has proper validation with ^[1-9]\\d*$ to ensure positive integers
  • The savePath preference validation pattern ^$|^/?(/[^/]+)+/?$ correctly ensures valid directory paths
  • The findMmdcPath function now properly checks multiple possible installation locations for better compatibility

Note: This review focuses on recent changes and aspects not mentioned in previous reviews, particularly around cleanup and validation improvements.

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@pernielsentikaer pernielsentikaer self-assigned this Mar 12, 2025
Copy link
Collaborator

@pernielsentikaer pernielsentikaer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a spin and got to this view

mermaid-to-image 2025-03-12 at 11 58 09

I installed with the npm command and it ended here: /Users/pernielsentikaer/.nvm/versions/node/v22.12.0/bin/mmdc which is not found, should we consider adding a custom path too in preferences?

- Introduced a new preference for specifying a custom mmdc path in package.json, allowing users to define their own executable location for better flexibility.

- Enhanced the findMmdcPath function in mermaid-to-image.tsx to first check for the custom path before falling back to default locations. This includes handling of glob patterns for NVM installations and improved error messaging for better user guidance.

- Updated error handling to provide clearer instructions if the mmdc command is not found, encouraging users to either install the mermaid-cli or set a custom path in preferences.
@chihkang
Copy link
Contributor Author

@pernielsentikaer Done🎉

Copy link
Collaborator

@pernielsentikaer pernielsentikaer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a new error now, but at least it found the mmdc 😊

mermaid-to-image 2025-03-13 at 10 12 58

Could you try to use enviroment.supportPath

…ility

This commit completely reorganizes the extension's codebase to improve
maintainability, readability, and separation of concerns:

- Split monolithic index.tsx into modular components and utilities
- Create dedicated directories for components, utils, and types
- Extract ImagePreview into a separate component
- Organize utility functions by domain (clipboard, files, executables, diagram)
- Improve type safety with dedicated types file
- Maintain all existing functionality while improving code organization
- Ensure consistent error handling patterns throughout the codebase
- Reduce code duplication by extracting common functionality
Copy link
Collaborator

@pernielsentikaer pernielsentikaer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to get it to work this time, but when an error occurs, should we maybe skip the part of showing so much about it, like here? It feels overwhelming. What do you think?

Raycast 2025-03-13 at 13 12 20

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

Based on the latest changes to the Mermaid to Image extension, here's my review focusing on new points not previously covered:

The PR improves error handling and resource management in the diagram generation functionality.

  • The generateDiagramWithExplicitNode in diagram.ts should consolidate error message parsing into a separate helper function for better maintainability
  • The cleanupResources helper function in diagram.ts should be moved outside to be reusable across different functions
  • The findMmdcPath in executables.ts should consolidate success toasts to avoid multiple notifications when checking different paths
  • The error handling in diagram.ts should use more specific error types for better error differentiation

Note: This review focuses on code organization and error handling improvements not mentioned in previous reviews.

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +78 to +81
await showFailureToast({
title: "Diagram Generation Failed",
message: userMessage,
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're inside a catch you can do like this

Suggested change
await showFailureToast({
title: "Diagram Generation Failed",
message: userMessage,
});
await showFailureToast(error, {
title: "Diagram Generation Failed",
message: userMessage,
});

if not inside a catch it's better to use the regular toast (since this uses error)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pernielsentikaer
Thank you for your valuable suggestions 😊

chihkang and others added 2 commits March 14, 2025 19:03
ImagePreview and diagram generation by including error details in showFailureToast calls for improved debugging 🛠️✨
@raycastbot raycastbot merged commit 92ff351 into raycast:main Mar 14, 2025
2 checks passed
@github-actions
Copy link
Contributor

Published to the Raycast Store:
https://raycast.com/chihkang/mermaid-to-image

@raycastbot
Copy link
Collaborator

🎉 🎉 🎉

We've rewarded your Raycast account with some credits. You will soon be able to exchange them for some swag.

@chihkang chihkang deleted the ext/mermaid-to-image branch March 17, 2025 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new extension Label for PRs with new extensions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants