Skip to content

Commit

Permalink
cmd init + icons
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 14, 2022
1 parent 8daba92 commit fce77e1
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 51 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ plugin-mac:


# make pack
.PHONY: pack
pack:
.PHONY: pack
pack: bindata vet

.PHONY: bindata
bindata:
mkdir -p .tmp/data
cp -r ui .tmp/data/
cp -r yao .tmp/data/
go-bindata -fs -pkg data -o data/bindata.go -prefix ".tmp/data/" .tmp/data/...
rm -rf .tmp/data


# make artifacts-linux
.PHONY: artifacts-linux
artifacts-linux: clean
Expand Down
9 changes: 1 addition & 8 deletions chart/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ func init() {
// 查询数据分析图表中定义的数据
func ProcessData(process *gou.Process) interface{} {

process.ValidateArgNums(3)
process.ValidateArgNums(2)
name := process.ArgsString(0)
params := process.ArgsMap(1)
chart := Select(name)
api := chart.APIs["data"]
if process.NumOfArgsIs(4) && api.IsAllow(process.Args[3]) {
return nil
}

if len(api.Default) > 0 {
if defaults, ok := api.Default[0].(map[string]interface{}); ok {
Expand All @@ -47,10 +44,6 @@ func ProcessSetting(process *gou.Process) interface{} {
name := process.ArgsString(0)
field := process.ArgsString(1)
chart := Select(name)
api := chart.APIs["setting"]
if process.NumOfArgsIs(2) && api.IsAllow(process.Args[1]) {
return nil
}

fields := strings.Split(field, ",")
setting := maps.Map{
Expand Down
32 changes: 30 additions & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/data"
"github.com/yaoapp/yao/share"
)

Expand All @@ -23,13 +24,14 @@ var initCmd = &cobra.Command{
makeAppJSON()
makeEnv()
defaultApps()
defaultIcons()
fmt.Println(color.GreenString(L("✨DONE✨")))
fmt.Println(color.WhiteString(L("NEXT:")), color.GreenString("%s migrate && %s run flows.setmenu", share.BUILDNAME, share.BUILDNAME))
},
}

func makeDirs() {
dirs := []string{"db", "data", "apis", "models", "flows", "scripts", "tables", "libs", "ui"}
dirs := []string{"db", "data", filepath.Join("yao", "icons"), "apis", "models", "flows", "scripts", "tables", "libs", "ui"}
for _, name := range dirs {
dirname := filepath.Join(config.Conf.Root, name)
if _, err := os.Stat(dirname); errors.Is(err, os.ErrNotExist) {
Expand All @@ -41,6 +43,29 @@ func makeDirs() {
}
}

func defaultIcons() {
png, err := data.Asset("yao/data/icons/icon.png")
if err != nil {
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
os.Exit(1)
}
makeFileContent(filepath.Join("yao", "icons", "icon.png"), png)

ico, err := data.Asset("yao/data/icons/icon.ico")
if err != nil {
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
os.Exit(1)
}
makeFileContent(filepath.Join("yao", "icons", "icon.ico"), ico)

icns, err := data.Asset("yao/data/icons/icon.icns")
if err != nil {
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
os.Exit(1)
}
makeFileContent(filepath.Join("yao", "icons", "icon.icns"), icns)
}

func defaultApps() {
makeFile(filepath.Join("models", "pet.mod.json"), `{
"name": "Pet",
Expand Down Expand Up @@ -273,7 +298,10 @@ func makeFile(name string, source string) {
fmt.Println(color.RedString(L("Fatal: %s"), filename+" already existed"))
os.Exit(1)
}
content := []byte(source)
makeFileContent(name, []byte(source))
}

func makeFileContent(filename string, content []byte) {
err := os.WriteFile(filename, content, 0644)
if err != nil {
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
Expand Down
Loading

0 comments on commit fce77e1

Please sign in to comment.