No description
This repository has been archived on 2024-11-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Find a file
happygaijin 0e863452cc MM-14575: Automatically serve static files for plugins (#33)
* MM-14575: Automatically serve static files for plugins
* Added sample public file
* Added HAS_PUBLIC to Makefile to test for public folder
* Added "static_files" config setting

* MM-14575: Removing static_files from plugin.json

* MM14575: Moving public folder to bundle root

* MM14575:Moving public directory to root
2019-04-02 13:22:01 -07:00
.circleci introducing circleci (#31) 2019-03-06 19:03:52 +01:00
assets Allow plugins to include assets in the bundle (#28) 2019-03-18 20:09:23 +01:00
build MM-14575: Automatically serve static files for plugins (#33) 2019-04-02 13:22:01 -07:00
public MM-14575: Automatically serve static files for plugins (#33) 2019-04-02 13:22:01 -07:00
server Update dependencies for 5.6 (#24) 2018-12-17 08:28:01 +01:00
webapp fix index.js import of plugin id 2018-09-20 14:21:10 -04:00
.editorconfig Add .editorconfig (#34) 2019-03-25 10:31:26 -04:00
.gitignore initial commit 2018-07-23 13:43:22 -04:00
CHANGELOG.md initial commit 2018-07-23 13:43:22 -04:00
LICENSE initial commit 2018-07-23 13:43:22 -04:00
Makefile MM-14575: Automatically serve static files for plugins (#33) 2019-04-02 13:22:01 -07:00
plugin.json strip out sample bits (moved to demo repository) 2018-07-24 16:02:46 -04:00
README.md Allow plugins to include assets in the bundle (#28) 2019-03-18 20:09:23 +01:00

Sample Plugin CircleCI branch

This plugin serves as a starting point for writing a Mattermost plugin. Feel free to base your own plugin off this repository.

Getting Started

Shallow clone the repository to a directory matching your plugin name:

git clone --depth 1 https://github.com/mattermost/mattermost-plugin-sample com.example.my-plugin

Edit plugin.json with your id, name, and description:

{
    "id": "com.example.my-plugin",
    "name": "My Plugin",
    "description": "A plugin to enhance Mattermost."
}

Build your plugin:

make

This will produce a single plugin file (with support for multiple architectures) for upload to your Mattermost server:

dist/com.example.my-plugin.tar.gz

There is a build target to automate deploying and enabling the plugin to your server, but it requires configuration and http to be installed:

export MM_SERVICESETTINGS_SITEURL=http://localhost:8065
export MM_ADMIN_USERNAME=admin
export MM_ADMIN_PASSWORD=password
make deploy

Alternatively, if you are running your mattermost-server out of a sibling directory by the same name, use the deploy target alone to unpack the files into the right directory. You will need to restart your server and manually enable your plugin.

In production, deploy and upload your plugin via the System Console.

Q&A

How do I make a server-only or web app-only plugin?

Simply delete the server or webapp folders and remove the corresponding sections from plugin.json. The build scripts will skip the missing portions automatically.

How do I include assets in the plugin bundle?

Place them into the assets directory. To use an asset at runtime, build the path to your asset and open as a regular file:

bundlePath, err := p.API.GetBundlePath()
if err != nil {
    return errors.Wrap(err, "failed to get bundle path")
}

profileImage, err := ioutil.ReadFile(filepath.Join(bundlePath, "assets", "profile_image.png"))
if err != nil {
    return errors.Wrap(err, "failed to read profile image")
}

if appErr := p.API.SetProfileImage(userID, profileImage); appErr != nil {
    return errors.Wrap(err, "failed to set profile image")
}