Merge pull request #475 from twhiston/change_asset_bundler

Change asset bundler
This commit is contained in:
Tom Whiston 2018-03-06 09:35:43 +01:00 committed by GitHub
commit 285bbd3ac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 26 deletions

4
.gitignore vendored
View File

@ -1,5 +1,4 @@
gin-bin
util/bindata.go
build/
public/js/bundle.js
public/css/semaphore.css
@ -9,4 +8,5 @@ node_modules
.idea/
caddyfile
cli/semaphore_*
cli/semaphore_*
*-packr.go

View File

@ -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
```

View File

@ -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)
@ -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()+"\">",

View File

@ -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:

View File

@ -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())
@ -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

View File

@ -4,8 +4,6 @@ import (
"fmt"
"strings"
"time"
"github.com/ansible-semaphore/semaphore/util"
)
type DBVersion struct {
@ -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() {

11
make.sh
View File

@ -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"
@ -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