Compare commits
No commits in common. "2e2a95d7d6d8e70b1aeb81779370628770ae99bc" and "03c521f237395b9f08a03bf06c7b3a84fa7a9e24" have entirely different histories.
2e2a95d7d6
...
03c521f237
5 changed files with 33 additions and 132 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -31,8 +31,3 @@ Thumbs.db
|
||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.claude
|
.claude
|
||||||
|
|
||||||
# Ignore all files in testdata except plugin.json
|
|
||||||
testdata/**/*
|
|
||||||
!testdata/**/
|
|
||||||
!testdata/**/plugin.json
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ linters-settings:
|
||||||
gofmt:
|
gofmt:
|
||||||
simplify: true
|
simplify: true
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes: {{.GoModule}}
|
local-prefixes: github.com/mattermost/mattermost-starter-template
|
||||||
govet:
|
govet:
|
||||||
check-shadowing: true
|
check-shadowing: true
|
||||||
enable-all: true
|
enable-all: true
|
||||||
|
|
|
@ -33,7 +33,7 @@ endif
|
||||||
mock:
|
mock:
|
||||||
ifneq ($(HAS_SERVER),)
|
ifneq ($(HAS_SERVER),)
|
||||||
go install github.com/golang/mock/mockgen@v1.6.0
|
go install github.com/golang/mock/mockgen@v1.6.0
|
||||||
mockgen -destination=server/command/mocks/mock_commands.go -package=mocks {{.GoModule}}/server/command Command
|
mockgen -destination=server/command/mocks/mock_commands.go -package=mocks github.com/mattermost/mattermost-plugin-starter-template/server/command Command
|
||||||
endif
|
endif
|
||||||
|
|
||||||
## Show help documentation.
|
## Show help documentation.
|
||||||
|
|
41
info.go
41
info.go
|
@ -28,28 +28,28 @@ func PrintPluginInfo(manifest *model.Manifest) error {
|
||||||
|
|
||||||
// printBasicInfo prints basic plugin information.
|
// printBasicInfo prints basic plugin information.
|
||||||
func printBasicInfo(manifest *model.Manifest) {
|
func printBasicInfo(manifest *model.Manifest) {
|
||||||
fmt.Println("Plugin Information:")
|
Logger.Info("Plugin Information:")
|
||||||
fmt.Println("==================")
|
Logger.Info("==================")
|
||||||
|
|
||||||
fmt.Printf("ID: %s\n", manifest.Id)
|
Logger.Info("ID:", "value", manifest.Id)
|
||||||
fmt.Printf("Name: %s\n", manifest.Name)
|
Logger.Info("Name:", "value", manifest.Name)
|
||||||
fmt.Printf("Version: %s\n", manifest.Version)
|
Logger.Info("Version:", "value", manifest.Version)
|
||||||
|
|
||||||
minVersion := manifest.MinServerVersion
|
minVersion := manifest.MinServerVersion
|
||||||
if minVersion == "" {
|
if minVersion == "" {
|
||||||
minVersion = "Not specified"
|
minVersion = "Not specified"
|
||||||
}
|
}
|
||||||
fmt.Printf("Min MM Version: %s\n", minVersion)
|
Logger.Info("Min MM Version:", "value", minVersion)
|
||||||
|
|
||||||
if manifest.Description != "" {
|
if manifest.Description != "" {
|
||||||
fmt.Printf("Description: %s\n", manifest.Description)
|
Logger.Info("Description:", "value", manifest.Description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// printCodeComponents prints information about server and webapp code.
|
// printCodeComponents prints information about server and webapp code.
|
||||||
func printCodeComponents(manifest *model.Manifest) {
|
func printCodeComponents(manifest *model.Manifest) {
|
||||||
fmt.Println("Code Components:")
|
Logger.Info("Code Components:")
|
||||||
fmt.Println("================")
|
Logger.Info("================")
|
||||||
|
|
||||||
printServerCodeInfo(manifest)
|
printServerCodeInfo(manifest)
|
||||||
printWebappCodeInfo(manifest)
|
printWebappCodeInfo(manifest)
|
||||||
|
@ -58,33 +58,28 @@ func printCodeComponents(manifest *model.Manifest) {
|
||||||
// printServerCodeInfo prints server code information.
|
// printServerCodeInfo prints server code information.
|
||||||
func printServerCodeInfo(manifest *model.Manifest) {
|
func printServerCodeInfo(manifest *model.Manifest) {
|
||||||
if HasServerCode(manifest) {
|
if HasServerCode(manifest) {
|
||||||
fmt.Println("Server Code: Yes")
|
Logger.Info("Server Code:", "value", "Yes")
|
||||||
if manifest.Server != nil && len(manifest.Server.Executables) > 0 {
|
if manifest.Server != nil && len(manifest.Server.Executables) > 0 {
|
||||||
fmt.Print("Executables: ")
|
var executables []string
|
||||||
first := true
|
|
||||||
for platform := range manifest.Server.Executables {
|
for platform := range manifest.Server.Executables {
|
||||||
if !first {
|
executables = append(executables, platform)
|
||||||
fmt.Print(", ")
|
|
||||||
}
|
|
||||||
fmt.Print(platform)
|
|
||||||
first = false
|
|
||||||
}
|
}
|
||||||
fmt.Println()
|
Logger.Info("Executables:", "platforms", executables)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Server Code: No")
|
Logger.Info("Server Code:", "value", "No")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// printWebappCodeInfo prints webapp code information.
|
// printWebappCodeInfo prints webapp code information.
|
||||||
func printWebappCodeInfo(manifest *model.Manifest) {
|
func printWebappCodeInfo(manifest *model.Manifest) {
|
||||||
if HasWebappCode(manifest) {
|
if HasWebappCode(manifest) {
|
||||||
fmt.Println("Webapp Code: Yes")
|
Logger.Info("Webapp Code:", "value", "Yes")
|
||||||
if manifest.Webapp != nil && manifest.Webapp.BundlePath != "" {
|
if manifest.Webapp != nil && manifest.Webapp.BundlePath != "" {
|
||||||
fmt.Printf("Bundle Path: %s\n", manifest.Webapp.BundlePath)
|
Logger.Info("Bundle Path:", "value", manifest.Webapp.BundlePath)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Webapp Code: No")
|
Logger.Info("Webapp Code:", "value", "No")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +89,7 @@ func printSettingsSchema(manifest *model.Manifest) {
|
||||||
if manifest.SettingsSchema != nil {
|
if manifest.SettingsSchema != nil {
|
||||||
value = "Yes"
|
value = "Yes"
|
||||||
}
|
}
|
||||||
fmt.Printf("Settings Schema: %s\n", value)
|
Logger.Info("Settings Schema:", "value", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InfoCommandWithPath implements the 'info' command with a custom path.
|
// InfoCommandWithPath implements the 'info' command with a custom path.
|
||||||
|
|
115
updateassets.go
115
updateassets.go
|
@ -8,9 +8,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/mattermost/mattermost/server/public/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed assets/*
|
//go:embed assets/*
|
||||||
|
@ -48,7 +45,6 @@ func RunUpdateAssetsCommand(args []string, pluginPath string) error {
|
||||||
hasWebapp: hasWebapp,
|
hasWebapp: hasWebapp,
|
||||||
updatedCount: &updatedCount,
|
updatedCount: &updatedCount,
|
||||||
pluginCtlConfig: pluginCtlConfig,
|
pluginCtlConfig: pluginCtlConfig,
|
||||||
manifest: manifest,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = fs.WalkDir(assetsFS, "assets", func(path string, d fs.DirEntry, err error) error {
|
err = fs.WalkDir(assetsFS, "assets", func(path string, d fs.DirEntry, err error) error {
|
||||||
|
@ -125,19 +121,6 @@ type AssetProcessorConfig struct {
|
||||||
hasWebapp bool
|
hasWebapp bool
|
||||||
updatedCount *int
|
updatedCount *int
|
||||||
pluginCtlConfig *PluginCtlConfig
|
pluginCtlConfig *PluginCtlConfig
|
||||||
manifest *model.Manifest
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoModule represents information from go.mod file.
|
|
||||||
type GoModule struct {
|
|
||||||
Module string
|
|
||||||
Version string
|
|
||||||
}
|
|
||||||
|
|
||||||
// TemplateContext holds the data available to templates.
|
|
||||||
type TemplateContext struct {
|
|
||||||
Manifest *model.Manifest
|
|
||||||
GoModule *GoModule
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func processAssetEntry(path string, d fs.DirEntry, err error, config AssetProcessorConfig) error {
|
func processAssetEntry(path string, d fs.DirEntry, err error, config AssetProcessorConfig) error {
|
||||||
|
@ -168,21 +151,21 @@ func processAssetEntry(path string, d fs.DirEntry, err error, config AssetProces
|
||||||
return createDirectory(targetPath)
|
return createDirectory(targetPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return processAssetFile(path, targetPath, relativePath, config)
|
return processAssetFile(path, targetPath, relativePath, config.updatedCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func processAssetFile(embeddedPath, targetPath, relativePath string, config AssetProcessorConfig) error {
|
func processAssetFile(embeddedPath, targetPath, relativePath string, updatedCount *int) error {
|
||||||
shouldUpdate, err := shouldUpdateFile(embeddedPath, targetPath, config)
|
shouldUpdate, err := shouldUpdateFile(embeddedPath, targetPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if shouldUpdate {
|
if shouldUpdate {
|
||||||
err = updateFile(embeddedPath, targetPath, relativePath, config)
|
err = updateFile(embeddedPath, targetPath, relativePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
(*config.updatedCount)++
|
(*updatedCount)++
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -196,11 +179,10 @@ func createDirectory(targetPath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldUpdateFile(embeddedPath, targetPath string, config AssetProcessorConfig) (bool, error) {
|
func shouldUpdateFile(embeddedPath, targetPath string) (bool, error) {
|
||||||
// Process the template to get the final content
|
content, err := assetsFS.ReadFile(embeddedPath)
|
||||||
processedContent, err := processTemplate(embeddedPath, config.manifest, config.pluginPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("failed to process template %s: %w", embeddedPath, err)
|
return false, fmt.Errorf("failed to read embedded file %s: %w", embeddedPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
existingContent, err := os.ReadFile(targetPath)
|
existingContent, err := os.ReadFile(targetPath)
|
||||||
|
@ -209,14 +191,13 @@ func shouldUpdateFile(embeddedPath, targetPath string, config AssetProcessorConf
|
||||||
return true, nil //nolint:nilerr
|
return true, nil //nolint:nilerr
|
||||||
}
|
}
|
||||||
|
|
||||||
return !bytes.Equal(existingContent, processedContent), nil
|
return !bytes.Equal(existingContent, content), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateFile(embeddedPath, targetPath, relativePath string, config AssetProcessorConfig) error {
|
func updateFile(embeddedPath, targetPath, relativePath string) error {
|
||||||
// Process the template to get the final content
|
content, err := assetsFS.ReadFile(embeddedPath)
|
||||||
processedContent, err := processTemplate(embeddedPath, config.manifest, config.pluginPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to process template %s: %w", embeddedPath, err)
|
return fmt.Errorf("failed to read embedded file %s: %w", embeddedPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parentDir := filepath.Dir(targetPath)
|
parentDir := filepath.Dir(targetPath)
|
||||||
|
@ -224,7 +205,7 @@ func updateFile(embeddedPath, targetPath, relativePath string, config AssetProce
|
||||||
return fmt.Errorf("failed to create parent directory %s: %w", parentDir, err)
|
return fmt.Errorf("failed to create parent directory %s: %w", parentDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.WriteFile(targetPath, processedContent, filePermissions); err != nil {
|
if err := os.WriteFile(targetPath, content, filePermissions); err != nil {
|
||||||
return fmt.Errorf("failed to write file %s: %w", targetPath, err)
|
return fmt.Errorf("failed to write file %s: %w", targetPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,73 +213,3 @@ func updateFile(embeddedPath, targetPath, relativePath string, config AssetProce
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// processTemplate processes a template file with the manifest context.
|
|
||||||
func processTemplate(embeddedPath string, manifest *model.Manifest, pluginPath string) ([]byte, error) {
|
|
||||||
// Read the template content
|
|
||||||
templateContent, err := assetsFS.ReadFile(embeddedPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read embedded file %s: %w", embeddedPath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse go.mod file to get module information
|
|
||||||
goMod, err := parseGoModule(pluginPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to parse go.mod file: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create template context
|
|
||||||
context := TemplateContext{
|
|
||||||
Manifest: manifest,
|
|
||||||
GoModule: goMod,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and parse the template
|
|
||||||
tmpl, err := template.New(embeddedPath).Parse(string(templateContent))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to parse template %s: %w", embeddedPath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the template
|
|
||||||
var buf bytes.Buffer
|
|
||||||
err = tmpl.Execute(&buf, context)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to execute template %s: %w", embeddedPath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseGoModule parses the go.mod file to extract module information.
|
|
||||||
func parseGoModule(pluginPath string) (*GoModule, error) {
|
|
||||||
goModPath := filepath.Join(pluginPath, "go.mod")
|
|
||||||
|
|
||||||
content, err := os.ReadFile(goModPath)
|
|
||||||
if err != nil {
|
|
||||||
// If go.mod doesn't exist, return nil without error
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("failed to read go.mod file: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
goMod := &GoModule{}
|
|
||||||
lines := strings.Split(string(content), "\n")
|
|
||||||
|
|
||||||
for _, line := range lines {
|
|
||||||
line = strings.TrimSpace(line)
|
|
||||||
|
|
||||||
// Parse module line
|
|
||||||
if strings.HasPrefix(line, "module ") {
|
|
||||||
goMod.Module = strings.TrimSpace(strings.TrimPrefix(line, "module "))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse go version line
|
|
||||||
if strings.HasPrefix(line, "go ") {
|
|
||||||
goMod.Version = strings.TrimSpace(strings.TrimPrefix(line, "go "))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return goMod, nil
|
|
||||||
}
|
|
||||||
|
|
Reference in a new issue