This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
90 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package meta | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"strings" | ||
) | ||
|
||
// BuildTags are tags used for building apps | ||
type BuildTags []string | ||
|
||
// String returns the tags in the form of: | ||
// "foo bar baz" (with the quotes!) | ||
func (t BuildTags) String() string { | ||
return `"` + strings.Join(t, " ") + `"` | ||
} | ||
|
||
// BuildTags combines the passed in env, and any additional tags, | ||
// with tags that Buffalo decides the build process requires. | ||
// An example would be adding the "sqlite" build tag if using | ||
// SQLite3. | ||
func (a App) BuildTags(env string, tags ...string) BuildTags { | ||
tags = append(tags, env) | ||
if b, err := ioutil.ReadFile("database.yml"); err == nil { | ||
if bytes.Contains(b, []byte("sqlite")) { | ||
tags = append(tags, "sqlite") | ||
} | ||
} | ||
return BuildTags(tags) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package meta | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_BuildTags(t *testing.T) { | ||
defer os.Remove("database.yml") | ||
app := New(".") | ||
t.Run("without database.yml", func(st *testing.T) { | ||
r := require.New(st) | ||
tags := app.BuildTags("dev") | ||
r.Len(tags, 1) | ||
r.Equal("dev", tags[0]) | ||
r.Equal(`"dev"`, tags.String()) | ||
}) | ||
t.Run("with database.yml", func(st *testing.T) { | ||
t.Run("with sqlite", func(st *testing.T) { | ||
r := require.New(st) | ||
f, err := os.Create("database.yml") | ||
r.NoError(err) | ||
_, err = f.WriteString("sqlite") | ||
r.NoError(err) | ||
|
||
tags := app.BuildTags("dev") | ||
r.Len(tags, 2) | ||
r.Equal("dev", tags[0]) | ||
r.Equal("sqlite", tags[1]) | ||
r.Equal(`"dev sqlite"`, tags.String()) | ||
}) | ||
t.Run("without sqlite", func(st *testing.T) { | ||
r := require.New(st) | ||
f, err := os.Create("database.yml") | ||
r.NoError(err) | ||
_, err = f.WriteString("mysql") | ||
r.NoError(err) | ||
|
||
tags := app.BuildTags("dev") | ||
r.Len(tags, 1) | ||
r.Equal("dev", tags[0]) | ||
r.Equal(`"dev"`, tags.String()) | ||
}) | ||
}) | ||
} |