github.com/getgauge/gauge@v1.6.9/manifest/manifest.go (about)

     1  /*----------------------------------------------------------------
     2   *  Copyright (c) ThoughtWorks, Inc.
     3   *  Licensed under the Apache License, Version 2.0
     4   *  See LICENSE in the project root for license information.
     5   *----------------------------------------------------------------*/
     6  
     7  package manifest
     8  
     9  import (
    10  	"encoding/json"
    11  	"fmt"
    12  	"io"
    13  	"os"
    14  	"path/filepath"
    15  	"strings"
    16  
    17  	"github.com/getgauge/common"
    18  	"github.com/getgauge/gauge/config"
    19  )
    20  
    21  type Manifest struct {
    22  	Language       string
    23  	Plugins        []string
    24  	EnvironmentDir string
    25  }
    26  
    27  func ProjectManifest() (*Manifest, error) {
    28  	contents, err := common.ReadFileContents(filepath.Join(config.ProjectRoot, common.ManifestFile))
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  	dec := json.NewDecoder(strings.NewReader(contents))
    33  
    34  	var m Manifest
    35  	for {
    36  		if err := dec.Decode(&m); err == io.EOF {
    37  			break
    38  		} else if err != nil {
    39  			return nil, fmt.Errorf("Failed to read Manifest. %s\n", err.Error())
    40  		}
    41  	}
    42  
    43  	return &m, nil
    44  }
    45  
    46  func (m *Manifest) Save() error {
    47  	b, err := json.MarshalIndent(m, "", "  ")
    48  	if err != nil {
    49  		return err
    50  	}
    51  	return os.WriteFile(common.ManifestFile, b, common.NewFilePermissions)
    52  }