Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d2plugin: Sketch plugin #45

Closed
wants to merge 2 commits into from
Closed

d2plugin: Sketch plugin #45

wants to merge 2 commits into from

Conversation

alixander
Copy link
Collaborator

@alixander alixander commented Nov 4, 2022

Also implements being able to run D2 with multiple plugins, by adding a Options() on d2plugin interface that returns the list of operations the plugin supports.

Screen Shot 2022-11-03 at 5 41 47 PM

Co-authored-by: Anmol Sethi <hi@nhooyr.io>
Copy link
Contributor

@nhooyr nhooyr left a comment

Choose a reason for hiding this comment

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

💯 regex parsing

@@ -37,6 +37,7 @@ func run(ctx context.Context, ms *xmain.State) (err error) {
bundleFlag := ms.FlagSet.BoolP("bundle", "b", true, "bundle all assets and layers into the output svg")
versionFlag := ms.FlagSet.BoolP("version", "v", false, "get the version and check for updates")
debugFlag := ms.FlagSet.BoolP("debug", "d", false, "print debug logs")
sketchFlag := ms.FlagSet.BoolP("sketch", "s", false, "use the sketch plugin, making diagrams look sketched by hand")
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the value in this being a plugin? Why not just handle it directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm, I understand the v8 dependency is nice to be optional.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a $D2_RENDER to control which renderer plugin is used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i think it's different from layout, where you always need one to be present. i think a value-less flag is most appropriate here.

more broadly tho, i think we should either have equivalency of options across flag and env vars or go with only one. it's rly confusing remembering which are set as env vars and which are flags.

Copy link
Contributor

Choose a reason for hiding this comment

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

For sure, see #53

What if we add another type of renderer plugin though?

I think --renderer=sketch is reasonable? And for switching back, --renderer=default. Perhaps -s can be a shorthand for --renderer=sketch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure what you mean by second point? What are you referring to?

same thing as u said about it having order. okay, i think that's a strong case for grouping under 1 flag. should we call it render tho? then if other plugins do other things, we need separate flags. (e.g. idk, an xss plugin that escapes harmful labels). wdyt about just --plugins

Copy link
Contributor

Choose a reason for hiding this comment

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

I would consider an xss plugin to be a render plugin. Though that should be something that's builtin and not a plugin.

The problem with --plugins is that now you can pass layout plugins too. What should that mean? What if you have a layout plugin after a render plugin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah ur right. okay, --render=x,y,z it is

Copy link
Collaborator Author

@alixander alixander Dec 21, 2022

Choose a reason for hiding this comment

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

fyi @nhooyr, revisiting this, now that sketch is not a plugin (since we removed the v8go dep), it should be treated as a boolean flag because it's a replacement for the default render. Back when it was a plugin, we drew the default, and then targeted with regex to replace (which is like a pipeline). Now that it's not a plugin, we can just draw it as desired the first time.

The pipeline mechanism still makes sense to me for post-render steps, like the "high-contrast" or "colorblind" as discussed. But for sketch, I'm just going to make it a boolean flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sketch can still be made a plugin to avoid having to pull in an entire JS engine for builds only using TALA.

I think it's ok to make it a flag for now, makes it much easier to use.

Info(context.Context) (*PluginInfo, error)

// Options returns permitted operations for the plugin.
// "layout", "postProcess"
Copy link
Contributor

Choose a reason for hiding this comment

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

why not return a struct where each option is a bool?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah that'd be better

return nil, err
}
js := `const root = {
ownerDocument: {
Copy link
Contributor

Choose a reason for hiding this comment

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

bad indent

if _, err := v8ctx.RunScript(roughJS, "rough.js"); err != nil {
return nil, err
}
js := `const root = {
Copy link
Contributor

Choose a reason for hiding this comment

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

move const root onto its own line to see indent clearly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants