package.go 855 B

12345678910111213141516171819202122232425262728293031323334
  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. return
  13. }
  14. packager := packager.NewPackager(decoder)
  15. zipFile, err := packager.Pack()
  16. if err != nil {
  17. log.Error("failed to package plugin %v", err)
  18. return
  19. }
  20. err = os.WriteFile(outputPath, zipFile, 0644)
  21. if err != nil {
  22. log.Error("failed to write package file %v", err)
  23. return
  24. }
  25. log.Info("plugin packaged successfully, output path: %s", outputPath)
  26. }