mirror of
https://github.com/beego/bee.git
synced 2024-11-21 23:50:54 +00:00
Working on bee bale
This commit is contained in:
parent
b30217c1d3
commit
e606b0045d
14
apiapp.go
14
apiapp.go
@ -1,3 +1,17 @@
|
|||||||
|
// Copyright 2013 bee authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
// a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
// License for the specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013 Bee Authors
|
// Copyright 2013 bee authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
// not use this file except in compliance with the License. You may obtain
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
81
bale.go
Normal file
81
bale.go
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// Copyright 2013 bee authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
// a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
// License for the specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Unknwon/com"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cmdBale = &Command{
|
||||||
|
UsageLine: "bale",
|
||||||
|
Short: "packs non-Go files to Go source files",
|
||||||
|
Long: `
|
||||||
|
bale packs non-Go files to Go source files and
|
||||||
|
|
||||||
|
auto-generate unpack function to main package then run it
|
||||||
|
|
||||||
|
during the runtime.
|
||||||
|
|
||||||
|
This is mainly used for zealots who are requiring 100% Go code.`,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cmdBale.Run = runBale
|
||||||
|
}
|
||||||
|
|
||||||
|
func runBale(cmd *Command, args []string) {
|
||||||
|
err := loadConfig()
|
||||||
|
if err != nil {
|
||||||
|
com.ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Mkdir("bale", os.ModePerm)
|
||||||
|
|
||||||
|
for _, p := range conf.Bale.Dirs {
|
||||||
|
filepath.Walk(p, walkFn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func walkFn(resPath string, info os.FileInfo, err error) error {
|
||||||
|
if info.IsDir() || filterSuffix(resPath) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
resPath = strings.Replace(resPath, "_", "__", -1)
|
||||||
|
resPath = strings.Replace(resPath, ".", "___", -1)
|
||||||
|
sep := "/"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
sep = "\\"
|
||||||
|
}
|
||||||
|
resPath = strings.Replace(resPath, sep, "_", -1)
|
||||||
|
os.MkdirAll(path.Dir(resPath), os.ModePerm)
|
||||||
|
os.Create("bale/" + resPath + ".go")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func filterSuffix(name string) bool {
|
||||||
|
for _, s := range conf.Bale.IngExt {
|
||||||
|
if strings.HasSuffix(name, s) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
3
bee.go
3
bee.go
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2013 Bee Authors
|
// Copyright 2013 bee authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
// not use this file except in compliance with the License. You may obtain
|
// not use this file except in compliance with the License. You may obtain
|
||||||
@ -77,6 +77,7 @@ var commands = []*Command{
|
|||||||
cmdApiapp,
|
cmdApiapp,
|
||||||
cmdRouter,
|
cmdRouter,
|
||||||
cmdTest,
|
cmdTest,
|
||||||
|
cmdBale,
|
||||||
//cmdReStart,
|
//cmdReStart,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
bee.json
9
bee.json
@ -4,5 +4,14 @@
|
|||||||
"controllers": "",
|
"controllers": "",
|
||||||
"models": "",
|
"models": "",
|
||||||
"others": []
|
"others": []
|
||||||
|
},
|
||||||
|
"bale": {
|
||||||
|
"import": "github.com/astaxie/bee/bale",
|
||||||
|
"dirs": [
|
||||||
|
"views", "static", "conf"
|
||||||
|
],
|
||||||
|
"ignore_ext": [
|
||||||
|
".go"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
14
new.go
14
new.go
@ -1,3 +1,17 @@
|
|||||||
|
// Copyright 2013 bee authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
// a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
// License for the specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
14
pack.go
14
pack.go
@ -1,3 +1,17 @@
|
|||||||
|
// Copyright 2013 bee authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
// a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
// License for the specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
29
run.go
29
run.go
@ -1,3 +1,17 @@
|
|||||||
|
// Copyright 2013 bee authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
// a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
// License for the specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -61,10 +75,11 @@ var conf struct {
|
|||||||
Others []string // Other directories.
|
Others []string // Other directories.
|
||||||
} `json:"dir_structure"`
|
} `json:"dir_structure"`
|
||||||
|
|
||||||
MainFiles struct {
|
Bale struct {
|
||||||
Main string `json:"main.go"`
|
Import string
|
||||||
Others []string // Others files of package main.
|
Dirs []string
|
||||||
} `json:"main_files"`
|
IngExt []string `json:"ignore_ext"`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runApp(cmd *Command, args []string) {
|
func runApp(cmd *Command, args []string) {
|
||||||
@ -79,7 +94,7 @@ func runApp(cmd *Command, args []string) {
|
|||||||
|
|
||||||
err := loadConfig()
|
err := loadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
com.ColorLog("[ERRO] Fail to parse bee.json[ %s ]", err)
|
com.ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err)
|
||||||
}
|
}
|
||||||
var paths []string
|
var paths []string
|
||||||
paths = append(paths,
|
paths = append(paths,
|
||||||
@ -89,7 +104,6 @@ func runApp(cmd *Command, args []string) {
|
|||||||
// Because monitor files has some issues, we watch current directory
|
// Because monitor files has some issues, we watch current directory
|
||||||
// and ignore non-go files.
|
// and ignore non-go files.
|
||||||
paths = append(paths, conf.DirStruct.Others...)
|
paths = append(paths, conf.DirStruct.Others...)
|
||||||
paths = append(paths, conf.MainFiles.Others...)
|
|
||||||
|
|
||||||
NewWatcher(paths)
|
NewWatcher(paths)
|
||||||
appname = args[0]
|
appname = args[0]
|
||||||
@ -127,8 +141,5 @@ func loadConfig() error {
|
|||||||
if len(conf.DirStruct.Models) == 0 {
|
if len(conf.DirStruct.Models) == 0 {
|
||||||
conf.DirStruct.Models = "models"
|
conf.DirStruct.Models = "models"
|
||||||
}
|
}
|
||||||
if len(conf.MainFiles.Main) == 0 {
|
|
||||||
conf.MainFiles.Main = "main.go"
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
17
test.go
17
test.go
@ -1,3 +1,17 @@
|
|||||||
|
// Copyright 2013 bee authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
// a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
// License for the specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -33,7 +47,7 @@ func testApp(cmd *Command, args []string) {
|
|||||||
|
|
||||||
err := loadConfig()
|
err := loadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
com.ColorLog("[ERRO] Fail to parse bee.json[ %s ]", err)
|
com.ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err)
|
||||||
}
|
}
|
||||||
var paths []string
|
var paths []string
|
||||||
paths = append(paths,
|
paths = append(paths,
|
||||||
@ -43,7 +57,6 @@ func testApp(cmd *Command, args []string) {
|
|||||||
// Because monitor files has some issues, we watch current directory
|
// Because monitor files has some issues, we watch current directory
|
||||||
// and ignore non-go files.
|
// and ignore non-go files.
|
||||||
paths = append(paths, conf.DirStruct.Others...)
|
paths = append(paths, conf.DirStruct.Others...)
|
||||||
paths = append(paths, conf.MainFiles.Others...)
|
|
||||||
|
|
||||||
NewWatcher(paths)
|
NewWatcher(paths)
|
||||||
appname = args[0]
|
appname = args[0]
|
||||||
|
14
util.go
14
util.go
@ -1,3 +1,17 @@
|
|||||||
|
// Copyright 2013 bee authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
// a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
// License for the specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
14
watch.go
14
watch.go
@ -1,3 +1,17 @@
|
|||||||
|
// Copyright 2013 bee authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||||
|
// not use this file except in compliance with the License. You may obtain
|
||||||
|
// a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
// License for the specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
Loading…
Reference in New Issue
Block a user