hoodiehq / camp

:circus_tent: Welcome to Hoodie Camp!
https://hoodie.camp
Apache License 2.0
99 stars 55 forks source link

Enable 3rd party plugins #104

Closed gr2m closed 7 years ago

gr2m commented 7 years ago

This is something we have been working towards for the past year, and finally the pieces are all in place in order to allow to extend your Hoodie app easily with plugins provided by npm packages.

🤔 What you will need to know

We created a dummy plugin with extended information on how things should work. The two blockers we mention in there are now done.

:dart: The goal

The goal is to get the plugin example to work. When I add it to my app, set options.plugins = ["hoodie-plugin-example"] and start my app, I should have hoodie.send.email() method in the client which sends the POST /hoodie/email/api/send which then gets handled by the route handler defined in the plugin that actually sends an email.

I’m sure there are some things we didn’t think of yet, pleas reach out if you have any questions or run into any blocker. Enjoy :)

jicksy commented 7 years ago

Hi @gr2m , Facing some errors when I am trying to test locally.

I did npm install https://github.com/hoodiehq/hoodie-plugin-example.git --save, it saved the dependency to package.json file.

I did npm start, it opened in localhost:8090. Looks like I need to create a folder public> index.html and then test out the new plugin that I am adding in. Please confirm if this is the way to do the testing.

Also, I cloned hoodie-plugin-example. But, I'm getting the attached error. npm-debug.txt

For practice, I also cloned hoodie-app-tracker, and i was able to get it working in localhost.

Thanks, Jicksy

gr2m commented 7 years ago

The npm-debug.txt you linked looks like you tried to install https://registry.npmjs.org/plugin-example, but no such package exists: https://www.npmjs.com/package/plugin-example

The setup to install the current hoodie-plugin-example directly from github into an app would be like this

# create new folder
mkdir myapp
cd myapp
# create package.json
npm init -y
# install hoodie from npm
npm install --save hoodie
# install hoodie-plugin-example from github
npm install --save hoodiehq/hoodie-plugin-example

Now you can start the app with npm start and you should be able to see it at http://localhost:8080/

does that work for you?

jicksy commented 7 years ago

Thanks @gr2m . This is working. I am alble to get to localhost:8080.

I'm now seeing 'get going with hoodie' page. It tells me to create public/index.html. So to use the new plugin I'll create a public folder>index.html and give reference to the plugin. Hope that's the way to do it

screenshot from 2017-02-09 09-44-37

gr2m commented 7 years ago

you don’t have to. Open your web developer tools and you should have the hoodie API available. The goal is now that there should be the hoodie.send.email() method and it should actually send an email.

For that you have to implement the feature as described in https://github.com/hoodiehq/hoodie-plugin-example#implementation, and here for reference the message I sent in slack:

By adding a plugin I mean this:

  1. add hoodie-plugin-example to dependencies in your app’s package.json file
  2. set {..., "hoodie": {"plugins": ["hoodie-plugin-example"]}} in your package.json file

this is how a user would "install" a 3rd party plugin.

Now what you need to implement as part of this issue is in hoodie, where we register the hapi plugins (https://github.com/hoodiehq/hoodie/blob/cc80039f9685269dd3f0f0ebc5cdf89bcd2f2366/server/plugins/index.js#L27-L47), you know have to iterate trough the hoodie.plugins array and check if the npm packages have a hoodie/server path that you can require. Then you do the same with the client plugins (here we currently only check if your app has an internal plugin: https://github.com/hoodiehq/hoodie/blob/cc80039f9685269dd3f0f0ebc5cdf89bcd2f2366/server/plugins/client/bundle.js#L31-L33)

jicksy commented 7 years ago

https://github.com/hoodiehq/hoodie/pull/690 Hi @gr2m

My pull request.

I tried assigning the value of hoodie.plugins array to thirdPartyPlugins, is this the correct way to do it? It gives me error hoodie.plugins module is not present in my locale.

gr2m commented 7 years ago

Jicksy mentioned she’ll be gone for a week. @jicksy ping me when you’re back I’ll find you something else to work on :)

Meanwhile @labaikie took on working on this issue: https://github.com/hoodiehq/hoodie/pull/711

gr2m commented 7 years ago

Hey @labaikie, I’d like to get this feature released before next week as a few events are coming up where Hoodie will get some exposure. Do you think you can finish your PR? Sorry for being pushy, we try to avoid it as much as possible :(

labaikie commented 7 years ago

@gr2m I totally understand!! I apologize for holding it off so long... I've really had a lot going on but was planning to dedicate this weekend (starting tmr) on this!! Can we perhaps touch base on my progress Saturday? Then again, I don't want to be a bottleneck so please let me know if you have an alternative!

gr2m commented 7 years ago

Saturday is great :) Let’s check in then