Closed kulmann closed 5 months ago
@kulmann is it worth including this in the docs? Having this information on an issue I feel is not the most optimal solution
@LukasHirt wanted to created documentation from it, together with Felix. This issue was just meant as a brain dump as input for them. Can be closed after the docs for extension development have been finished. @LukasHirt do we have an issue for the extension development docs, so that we can keep track of closing this one here?
do we have an issue for the extension development docs, so that we can keep track of closing this one here?
Nope. Only the old outdated PR https://github.com/owncloud/ocis/pull/294
Not sure when I'll get to finishing it though.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.
outdated
Prerequisites: You have an ocis-extension defining at least one service with rpc requests in a .proto file. Goal: Your ocis-extension is now supposed to have a web UI, which can be hooked into
ocis-web
as a frontend extension and is able to communicate with the service(s) in your ocis-extension.Note: All files referenced below can be copied over from ocis-hello:
Set up an empty Vue app as extension for ocis-web
hello
to your extension name.yarn install
ui/components/App.vue
in your project. This is where your web ui lives - it will be rendered within the content area ofocis-web
(just having the left sidebar and the topbar) when navigating to your extension. Looking at the same file in ocis-hello or other extensions will give you an idea of what you can do here.ui/app.js
to your project. Again, you can just go through it and replacehello
with your extension name. This file will be loaded byocis-web
and contains all the required information to make your extension available with it's own menu item and properly recognized in theocis-web
extension system. You can export a vuex-store module here if your extension works with it, but it's not required to do so.yarn build
. This will build your app and copy it to theassets
folder of your extension.TODO: store is mandatory for ocis-web extension system! needs to have a
loadConfig
action. TODO: includefrontend
drone steps for building JS assetsResult: You have an (empty)
ocis-web
extension that fulfils the requirements ofocis-web
to be loaded as an external extension. Next step is to enable your ocis-extension to deliver the built assets.Enable your ocis-extension to deliver the built assets
fileb0x
to generate embeddable go assets from your .js bundle.pkg/assets/
, copy assets.go, option.go and embed.yml. Adapt import paths in assets.go and option.go to point to your extension instead of ocis-hello. Don't worry about the unresolvedFS
andCTX
vars, they will be part of generated code later on.GENERATE
target in your Makefile fromGENERATE ?= $(PACKAGES)
toGENERATE ?= $(PACKAGES) $(IMPORT)/pkg/assets
make generate
. This will create thepkg/assets/embed.go
file (which then also definesFS
andCTX
from step 1).pkg/server/http
to your ocis-extension. The important part is, that the http server serves the assets with aStatic
middleware.make build
and then./bin/<extension-name> server
)"external_apps": []
variable inside your config.json, add a new entry:Result: Your extension for
ocis-web
can be loaded inocis-web
(see configuration - insert docs link here). It is delivered by your ocis-extension.More comfort with
make watch
Note: this has not proven to be good DX. Needs a better solution, maybe with a webpack dev server.
yarn build
for an updated javascript bundle, b) runmake clean generate build
for having a new version of your ocis-extension available, including new compiled assets, c) start your ocis-extension, d) reload the page. In order to make this a little bit easier, we have amake watch
target available for you. In order to set this up, follow these steps:reflex.conf
file from ocis-hello and adapt it to your extension namewatch
target from the Makefile of ocis-hello into your Makefilemake watch
Result: Each time you save a file, your javascript app and go binary get recompiled and the new binary gets started. Note: Especially when saving files in your Vue code, this first builds your javascript app bundle and then recompiles the go binary, so it takes a few seconds until you can reload the page in ocis-web. Please wait with the page reload until you see the
Starting server xyz
log line.Generate a javascript client for your API:
third_party
folder. Depending on usages in .proto there are some .proto files that might need to be included and copied into your projectmake protobuf
- this will generate the files defined in step 1mkdir -p ui/client/<your-extension-name>
6: runyarn generate-api
- this will use the swagger.json file from step 1 to generate a javascript client (stored in ui/client/Register<service-name>ServiceWeb
in ocis-hello for how to do this)Result: You will have a JavaScript client available at
ui/client/<your-extension-name>/index.js
. It is generated from your .proto file and provides functions for each endpoint you defined. Internally it uses AXIOS to make the respective requests. You can now start using it in your extension for ocis-web.General advice for building your extension for ocis-web:
loadConfig
action in the vuex-store of your extension. Since this provides you with theconfig.server
variable, which is required for all API calls, you will have to wait for that, thus loading all your extension data after the config was provided.