Browse Source

feat(plugins): mounts dist folder if exists in plugin

closes #4230
bergquist 9 years ago
parent
commit
eb79436ab7
2 changed files with 25 additions and 2 deletions
  1. 4 0
      pkg/plugins/plugins.go
  2. 21 2
      pkg/util/filepath.go

+ 4 - 0
pkg/plugins/plugins.go

@@ -90,6 +90,10 @@ func scan(pluginDir string) error {
 	}
 	}
 
 
 	log.Info("Plugins: Scaning dir %s", pluginDir)
 	log.Info("Plugins: Scaning dir %s", pluginDir)
+	if util.ContainsDistFolder(pluginDir) {
+		log.Info("Plugins: Found dist folder in %s", pluginDir)
+		pluginDir = filepath.Join(pluginDir, "dist")
+	}
 
 
 	if err := util.Walk(pluginDir, true, true, scanner.walker); err != nil {
 	if err := util.Walk(pluginDir, true, true, scanner.walker); err != nil {
 		if pluginDir != "data/plugins" {
 		if pluginDir != "data/plugins" {

+ 21 - 2
pkg/util/filepath.go

@@ -44,8 +44,7 @@ func Walk(path string, followSymlinks bool, detectSymlinkInfiniteLoop bool, walk
 //
 //
 //If resolvedPath is "", then we are not following symbolic links.
 //If resolvedPath is "", then we are not following symbolic links.
 //If symlinkPathsFollowed is not nil, then we need to detect infinite loop.
 //If symlinkPathsFollowed is not nil, then we need to detect infinite loop.
-func walk(path string, info os.FileInfo, resolvedPath string,
-	symlinkPathsFollowed map[string]bool, walkFn WalkFunc) error {
+func walk(path string, info os.FileInfo, resolvedPath string, symlinkPathsFollowed map[string]bool, walkFn WalkFunc) error {
 	if info == nil {
 	if info == nil {
 		return errors.New("Walk: Nil FileInfo passed")
 		return errors.New("Walk: Nil FileInfo passed")
 	}
 	}
@@ -96,3 +95,23 @@ func walk(path string, info os.FileInfo, resolvedPath string,
 	}
 	}
 	return nil
 	return nil
 }
 }
+
+func ContainsDistFolder(path string) bool  {
+	info, err := os.Lstat(path)
+	if err != nil {
+		return false
+	}
+
+	if !info.IsDir() {
+		return false
+	}
+
+	list, err := ioutil.ReadDir(path)
+	for _, fileInfo := range list {
+		if fileInfo.IsDir() && fileInfo.Name() == "dist" {
+			return true
+		}
+	}
+
+	return false
+}