Skip to content

Commit a1995fa

Browse files
committed
add back
1 parent cb341ea commit a1995fa

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

build/manifest/main.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
8+
"github.com/mattermost/mattermost-server/v6/model"
9+
"github.com/pkg/errors"
10+
)
11+
12+
func main() {
13+
if len(os.Args) <= 1 {
14+
panic("no cmd specified")
15+
}
16+
17+
manifest, err := findManifest()
18+
if err != nil {
19+
panic("failed to find manifest: " + err.Error())
20+
}
21+
22+
cmd := os.Args[1]
23+
switch cmd {
24+
case "id":
25+
dumpPluginID(manifest)
26+
27+
case "version":
28+
dumpPluginVersion(manifest)
29+
30+
case "has_server":
31+
if manifest.HasServer() {
32+
fmt.Printf("true")
33+
}
34+
35+
case "has_webapp":
36+
if manifest.HasWebapp() {
37+
fmt.Printf("true")
38+
}
39+
40+
default:
41+
panic("unrecognized command: " + cmd)
42+
}
43+
}
44+
45+
func findManifest() (*model.Manifest, error) {
46+
_, manifestFilePath, err := model.FindManifest(".")
47+
if err != nil {
48+
return nil, errors.Wrap(err, "failed to find manifest in current working directory")
49+
}
50+
manifestFile, err := os.Open(manifestFilePath)
51+
if err != nil {
52+
return nil, errors.Wrapf(err, "failed to open %s", manifestFilePath)
53+
}
54+
defer manifestFile.Close()
55+
56+
// Re-decode the manifest, disallowing unknown fields. When we write the manifest back out,
57+
// we don't want to accidentally clobber anything we won't preserve.
58+
var manifest model.Manifest
59+
decoder := json.NewDecoder(manifestFile)
60+
decoder.DisallowUnknownFields()
61+
if err = decoder.Decode(&manifest); err != nil {
62+
return nil, errors.Wrap(err, "failed to parse manifest")
63+
}
64+
65+
return &manifest, nil
66+
}
67+
68+
// dumpPluginId writes the plugin id from the given manifest to standard out
69+
func dumpPluginID(manifest *model.Manifest) {
70+
fmt.Printf("%s", manifest.Id)
71+
}
72+
73+
// dumpPluginVersion writes the plugin version from the given manifest to standard out
74+
func dumpPluginVersion(manifest *model.Manifest) {
75+
fmt.Printf("%s", manifest.Version)
76+
}

build/setup.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ ifeq ($(GO),)
44
$(error "go is not available: see https://golang.org/doc/install")
55
endif
66

7+
# Ensure that the build tools are compiled. Go's caching makes this quick.
8+
$(shell cd build/manifest && $(GO) build -o ../bin/manifest)
9+
710
# Ensure that the deployment tools are compiled. Go's caching makes this quick.
811
$(shell cd build/pluginctl && $(GO) build -o ../bin/pluginctl)
912

0 commit comments

Comments
 (0)