Working on bee bale

This commit is contained in:
Unknown 2013-09-03 13:23:58 -04:00
parent b30217c1d3
commit e606b0045d
11 changed files with 198 additions and 13 deletions

View File

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

View File

@ -1,4 +1,4 @@
// Copyright 2013 Bee Authors
// 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

81
bale.go Normal file
View 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
View File

@ -1,4 +1,4 @@
// Copyright 2013 Bee Authors
// 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
@ -77,6 +77,7 @@ var commands = []*Command{
cmdApiapp,
cmdRouter,
cmdTest,
cmdBale,
//cmdReStart,
}

View File

@ -4,5 +4,14 @@
"controllers": "",
"models": "",
"others": []
},
"bale": {
"import": "github.com/astaxie/bee/bale",
"dirs": [
"views", "static", "conf"
],
"ignore_ext": [
".go"
]
}
}

14
new.go
View File

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

14
pack.go
View File

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

29
run.go
View File

@ -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
import (
@ -61,10 +75,11 @@ var conf struct {
Others []string // Other directories.
} `json:"dir_structure"`
MainFiles struct {
Main string `json:"main.go"`
Others []string // Others files of package main.
} `json:"main_files"`
Bale struct {
Import string
Dirs []string
IngExt []string `json:"ignore_ext"`
}
}
func runApp(cmd *Command, args []string) {
@ -79,7 +94,7 @@ func runApp(cmd *Command, args []string) {
err := loadConfig()
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
paths = append(paths,
@ -89,7 +104,6 @@ func runApp(cmd *Command, args []string) {
// Because monitor files has some issues, we watch current directory
// and ignore non-go files.
paths = append(paths, conf.DirStruct.Others...)
paths = append(paths, conf.MainFiles.Others...)
NewWatcher(paths)
appname = args[0]
@ -127,8 +141,5 @@ func loadConfig() error {
if len(conf.DirStruct.Models) == 0 {
conf.DirStruct.Models = "models"
}
if len(conf.MainFiles.Main) == 0 {
conf.MainFiles.Main = "main.go"
}
return nil
}

17
test.go
View File

@ -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
import (
@ -33,7 +47,7 @@ func testApp(cmd *Command, args []string) {
err := loadConfig()
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
paths = append(paths,
@ -43,7 +57,6 @@ func testApp(cmd *Command, args []string) {
// Because monitor files has some issues, we watch current directory
// and ignore non-go files.
paths = append(paths, conf.DirStruct.Others...)
paths = append(paths, conf.MainFiles.Others...)
NewWatcher(paths)
appname = args[0]

14
util.go
View File

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

View File

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