forked from hashicorp/otto
/
devdep.go
50 lines (42 loc) · 1.47 KB
/
devdep.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package vagrant
import (
"fmt"
"github.com/hashicorp/otto/app"
)
type DevDepOptions struct {
// Dir is the directory where Vagrant will be executed.
Dir string
// Script is the script to run to build the dev dependency.
Script string
// Files are the resulting files relative to the cache directory
// that are part of the dep. If these don't exist, an error will be
// generated.
Files []string
}
// DevDep builds a dev dependency using Vagrant.
//
// This function uses Build to build the dev dependency. Please see
// the documentation of that function for more details on how that works.
//
// This function implements app.App.DevDep.
func DevDep(dst *app.Context, src *app.Context, opts *DevDepOptions) (*app.DevDep, error) {
src.Ui.Header(fmt.Sprintf(
"Building the dev dependency: '%s'", src.Appfile.Application.Name))
src.Ui.Message(
"To ensure cross-platform compatibility, we'll use Vagrant to\n" +
"build this application. This is slow, and in a lot of cases we\n" +
"can do something faster. Future versions of Otto will detect and\n" +
"do this. As long as the application doesn't change, Otto will\n" +
"cache the results of this build.\n\n")
// Use the Build function to do so...
err := Build(src, &BuildOptions{
Dir: opts.Dir,
Script: opts.Script,
})
if err != nil {
return nil, err
}
// Return the dep with the configured files. Eventually we'll verify
// these files exist. For now, we don't.
return &app.DevDep{Files: opts.Files}, nil
}