in dev/import-beats/icons.go [73:111]
func retrieveIconPathFromTutorials(kibanaDir string) (map[string]string, error) {
refs := map[string]string{}
tutorialsPath := filepath.Join(kibanaDir, tutorialsPath)
tutorialFilePaths, err := filepath.Glob(filepath.Join(tutorialsPath, "*_*", "index.ts"))
if err != nil {
return nil, errors.Wrapf(err, "globbing tutorial files failed (path: %s)", tutorialsPath)
}
for _, tutorialFilePath := range tutorialFilePaths {
log.Printf("Scan tutorial file: %s", tutorialFilePath)
tutorialFile, err := ioutil.ReadFile(tutorialFilePath)
if err != nil {
return nil, errors.Wrapf(err, "reading tutorial file failed (path: %s)", tutorialFile)
}
m := iconRe.Find(tutorialFile)
if m == nil {
log.Printf("\t%s: icon not found", tutorialFilePath)
continue
}
s := strings.Split(string(m), `'`)
val := s[1]
// Extracting module name from tutorials path
// e.g. ./src/plugins/home/server/tutorials//php_fpm_metrics/index.ts -> php_fpm
moduleName := filepath.Base(filepath.Dir(tutorialFilePath))
moduleName = moduleName[:strings.LastIndex(moduleName, "_")]
if filepath.IsAbs(val) {
iconFileName := filepath.Base(val)
val = path.Join(kibanaDir, kibanaLogosPath, iconFileName)
refs[moduleName] = val
}
}
return refs, nil
}