package.go 894 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package plugin
  2. import (
  3. "os"
  4. "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/decoder"
  5. "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/packager"
  6. "github.com/langgenius/dify-plugin-daemon/internal/utils/log"
  7. )
  8. func PackagePlugin(inputPath string, outputPath string) {
  9. decoder, err := decoder.NewFSPluginDecoder(inputPath)
  10. if err != nil {
  11. log.Error("failed to create plugin decoder , plugin path: %s, error: %v", inputPath, err)
  12. os.Exit(1)
  13. return
  14. }
  15. packager := packager.NewPackager(decoder)
  16. zipFile, err := packager.Pack()
  17. if err != nil {
  18. log.Error("failed to package plugin %v", err)
  19. os.Exit(1)
  20. return
  21. }
  22. err = os.WriteFile(outputPath, zipFile, 0644)
  23. if err != nil {
  24. log.Error("failed to write package file %v", err)
  25. os.Exit(1)
  26. return
  27. }
  28. log.Info("plugin packaged successfully, output path: %s", outputPath)
  29. }