Skip to content

Commit

Permalink
Merge pull request #475 from twhiston/change_asset_bundler
Browse files Browse the repository at this point in the history
Change asset bundler
  • Loading branch information
twhiston committed Mar 6, 2018
2 parents 7bb044f + 8e91611 commit 285bbd3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
gin-bin
util/bindata.go
build/
public/js/bundle.js
public/css/semaphore.css
Expand All @@ -9,4 +8,5 @@ node_modules

.idea/
caddyfile
cli/semaphore_*
cli/semaphore_*
*-packr.go
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ git clone --recursive git@github.com:ansible-semaphore/semaphore.git && cd semap
3) Install dev dependencies

```
go get ./... github.com/cespare/reflex github.com/jteeuwen/go-bindata/... github.com/mitchellh/gox
go get ./... github.com/cespare/reflex github.com/gobuffalo/packr/... github.com/mitchellh/gox
npm install async
npm install -g nodemon pug-cli less
```
Expand Down
11 changes: 7 additions & 4 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (
"github.com/ansible-semaphore/semaphore/api/tasks"
"github.com/ansible-semaphore/semaphore/util"
"github.com/castawaylabs/mulekick"
"github.com/gobuffalo/packr"
"github.com/gorilla/mux"
"github.com/russross/blackfriday"
)

var publicAssets = packr.NewBox("../public")

// Declare all routes
func Route() mulekick.Router {
r := mulekick.New(mux.NewRouter(), mulekick.CorsMiddleware)
Expand Down Expand Up @@ -123,21 +126,21 @@ func servePublic(w http.ResponseWriter, r *http.Request) {
return
}

path = "/public/html/index.html"
path = "/html/index.html"
}

path = strings.Replace(path, "/", "", 1)
path = strings.Replace(path, "/public/", "", 1)
split := strings.Split(path, ".")
suffix := split[len(split)-1]

res, err := util.Asset(path)
res, err := publicAssets.MustBytes(path)
if err != nil {
mulekick.NotFoundHandler(w, r)
return
}

// replace base path
if util.WebHostURL != nil && path == "public/html/index.html" {
if util.WebHostURL != nil && path == "html/index.html" {
res = []byte(strings.Replace(string(res),
"<base href=\"/\">",
"<base href=\""+util.WebHostURL.String()+"\">",
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- git submodule update --init --recursive
- npm i -g less pug-cli
- npm i async
- go get github.com/jteeuwen/go-bindata/...
- go get github.com/gobuffalo/packr/...
- go get github.com/mitchellh/gox

override:
Expand Down
7 changes: 5 additions & 2 deletions db/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"fmt"
"time"

"github.com/ansible-semaphore/semaphore/util"
"github.com/go-sql-driver/mysql"
"github.com/gobuffalo/packr"
)

var dbAssets = packr.NewBox("./migrations")

func (version *DBVersion) CheckExists() (bool, error) {
exists, err := Mysql.SelectInt("select count(1) as ex from migrations where version=?", version.VersionString())

Expand Down Expand Up @@ -69,7 +71,8 @@ func (version *DBVersion) Run() error {
func (version *DBVersion) TryRollback() {
fmt.Printf("Rolling back %s (time: %v)...\n", version.HumanoidVersion(), time.Now())

if _, err := util.Asset(version.GetErrPath()); err != nil {
data := dbAssets.Bytes(version.GetErrPath())
if len(data) == 0 {
fmt.Println("Rollback SQL does not exist.")
fmt.Println()
return
Expand Down
13 changes: 7 additions & 6 deletions db/versionHistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"strings"
"time"

"github.com/ansible-semaphore/semaphore/util"
)

type DBVersion struct {
Expand Down Expand Up @@ -41,15 +39,18 @@ func (version *DBVersion) HumanoidVersion() string {
}

func (version *DBVersion) GetPath() string {
return "db/migrations/v" + version.VersionString() + ".sql"
return "v" + version.VersionString() + ".sql"
}
func (version *DBVersion) GetErrPath() string {
return "db/migrations/v" + version.VersionString() + ".err.sql"
return "v" + version.VersionString() + ".err.sql"
}

func (version *DBVersion) GetSQL(path string) []string {
sql := util.MustAsset(path)
return strings.Split(string(sql), ";\n")
sql, err := dbAssets.MustString(path)
if err != nil {
panic(err)
}
return strings.Split(sql, ";\n")
}

func init() {
Expand Down
11 changes: 1 addition & 10 deletions make.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#!/bin/bash
set -e

BINDATA_ARGS="-o util/bindata.go -pkg util"

if [ "$1" == "watch" ]; then
BINDATA_ARGS="-debug ${BINDATA_ARGS}"
echo "Creating util/bindata.go with file proxy"
else
echo "Creating util/bindata.go"
fi

if [ "$1" == "ci_test" ]; then
echo "Creating CI Test config.json"

Expand Down Expand Up @@ -63,7 +54,7 @@ HEREDOC
github-release release --draft -u ansible-semaphore -r semaphore -t "v$VERSION" -d "## Special thanks to\n\n## Installation\n\nFollow [wiki/Installation](https://github.com/ansible-semaphore/semaphore/wiki/Installation)\n\n## Changelog"
fi

go-bindata $BINDATA_ARGS db/migrations/ $(find public/* -type d -print)
packr

if [ "$1" == "ci_test" ]; then
exit 0
Expand Down

0 comments on commit 285bbd3

Please sign in to comment.