Skip to content

Plugins

sgohl edited this page Jan 26, 2024 · 14 revisions

The plug folder in your app provides a way to outsource sub-apps to a limited extent.

wishplugs have almost the same structure as the main app, besides some exceptions.

The following resources are supported:

  • pages
  • fragments
  • lib
  • static
  • bin
  • api.sh

For views, there was an ambiguity problem I couldn't solve so I decided to not support views directly, but if you really want to use a plug view, you could either create a main view and use the Render function to yield the plug view or directly use the routes (app/index.sh) to Render your plug's view file.

External Plugs vs Bundled Plugs

If you choose to bundle plugs with your application, consider the following:

  • you want all external plugs also locally for development
  • but if your prod app will be built using a pipeline and your plugs are installed via Dockerfile, this will fail because the folder already exists from your local development, since it got git-pushed (more below)
  • you can install external wish plugs via app/docker-entrypoint.sh for local dev like this, for example:
if [[ ! $APPENV == 'prod' ]]
then

    if [[ -d /www/app/plug/admin ]]
    then
        git --work-tree /www/app/plug/admin/ --git-dir /www/app/plug/admin/.git pull        
    else
        wish plug admin https://github.com/sgohl/wish-admin.git
    fi

fi

and then add this plug into .gitignore

admin/

That way, it does not cause collisions with a build pipeline (mentioned problem above).

static

You can load plug stylesheets on the <body> of your page(s) like this

<link href="/plug/your-awesome-plug/static/css/custom.css" rel="stylesheet" property="stylesheet" />

and javascript like this

<script src="/plug/your-awesome-plug/static/js/custom.js"></script>

wish-cli

The cli program wish (https://github.com/sgohl/wish/blob/main/docker-dist/bin/wish) available inside the container image currently only mimics the most simple function of a package manager: it installs a plugin.

Usage

wish plug NAME GIT-REPO

This will git clone the repository as /www/app/plug/NAME

FORCE

if run with FORCE=true, the destination folder will be removed completely before git clone

example:

FORCE=true wish plug admin https://github.com/sgohl/wish-admin.git

This can be used alternatively to the mentioned solution using a .gitignore file preventing collisions in a build pipeline

To clone a specific branch (different than default branch), preset following env var: BRANCH=main

You can also set custom git options by pre-setting the following env var, for example to shallow clone:

GITOPTS="--depth 1" BRANCH="main" wish plug your-awesome-plug https://github.com/yourname/your-awesome-plug

To delete the .git dir after clone, pre-set the env variable (with any content) for example

GITRM=true

It will execute rm -rf after git clone - estimate risk yourself. The more sophisticated way would be to use

GITOPTS="--separate-git-dir=$(mktemp -u)"

and have /tmp mounted as tmpfs at clone-time (i.e. in your build pipeline) or manually delete this path afterwards. For this, do not set GITRM

Clone this wiki locally