github.com/wawandco/oxpecker-plugins@v0.1.1/tools/yarn/builder.go (about)

     1  package yarn
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"os/exec"
     7  )
     8  
     9  // RunBeforeBuild attempts to run yarn install if it finds yarn.lock
    10  func (p *Plugin) RunBeforeBuild(ctx context.Context, root string, args []string) error {
    11  	cmd := p.buildCmd(ctx)
    12  	if p == nil {
    13  		return nil
    14  	}
    15  
    16  	return cmd.Run()
    17  }
    18  
    19  // build command will return the command if yarn.lock is found
    20  // otherwise returns nil
    21  func (p *Plugin) buildCmd(ctx context.Context) *exec.Cmd {
    22  	_, err := os.Stat("yarn.lock")
    23  	if os.IsNotExist(err) {
    24  		return nil
    25  	}
    26  
    27  	c := exec.CommandContext(ctx, "yarn", "install", "--no-progress")
    28  	c.Stdin = os.Stdin
    29  	c.Stderr = os.Stderr
    30  	c.Stdout = os.Stdout
    31  
    32  	return c
    33  }