github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/buildtools/bower/config.go (about)

     1  package bower
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/fossas/fossa-cli/files"
     7  )
     8  
     9  type Config struct {
    10  	CWD       string `json:"cwd"`
    11  	Directory string `json:"directory"`
    12  }
    13  
    14  // TODO: this is nowhere near complete -- there's all sorts of crazy cascading
    15  // mechanisms that configure Bower.
    16  func ReadConfig(dir string) (Config, error) {
    17  	ok, err := files.Exists(dir, ".bowerrc")
    18  	if ok {
    19  		return ReadConfigFile(filepath.Join(dir, ".bowerrc"))
    20  	}
    21  	return Config{
    22  		CWD:       dir,
    23  		Directory: filepath.Join(dir, "bower_components"),
    24  	}, err
    25  }
    26  
    27  func ReadConfigFile(filename string) (Config, error) {
    28  	var config Config
    29  	err := files.ReadJSON(&config, filename)
    30  	if err != nil {
    31  		return Config{}, err
    32  	}
    33  	if config.Directory == "" {
    34  		config.Directory = "bower_components"
    35  	}
    36  	return config, nil
    37  }