1
0
mirror of https://shylinux.com/x/icebergs synced 2025-06-26 18:37:29 +08:00

opt module

This commit is contained in:
harveyshao 2023-02-20 01:07:25 +08:00
parent 80df68adf5
commit 8d084c3c2d
9 changed files with 59 additions and 32 deletions

View File

@ -165,8 +165,14 @@ func FileURI(dir string) string {
} }
return path.Join(ice.PS, ice.REQUIRE, dir) return path.Join(ice.PS, ice.REQUIRE, dir)
} }
func FileCmd(dir string) string { return FileURI(kit.ExtChange(strings.Split(dir, ice.DF)[0], nfs.GO)) } func FileCmd(dir string) string { return FileURI(kit.ExtChange(strings.Split(dir, ice.DF)[0], nfs.GO)) }
func AddFileCmd(dir, key string) { ice.Info.File[FileCmd(dir)] = key } func AddFileCmd(dir, key string) {
ice.Info.File[FileCmd(dir)] = key
ls := strings.SplitN(path.Join(kit.Slice(strings.Split(FileCmd(dir), ice.PS), 2, 5)...), ice.AT, 2)
if len(ls) > 1 {
ice.Info.Gomod[ls[0]] = ls[1]
}
}
func IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' } func IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' }
func GetFileCmd(dir string) string { func GetFileCmd(dir string) string {
if strings.HasPrefix(dir, ice.REQUIRE+ice.PS) { if strings.HasPrefix(dir, ice.REQUIRE+ice.PS) {

View File

@ -11,7 +11,11 @@ import (
"shylinux.com/x/toolkits/logs" "shylinux.com/x/toolkits/logs"
) )
func Display(m *ice.Message, file string, arg ...ice.Any) *ice.Message { type Message interface {
Option(key string, arg ...ice.Any) string
}
func Display(m Message, file string, arg ...ice.Any) Message {
if file == "" { if file == "" {
file = kit.Keys(kit.FileName(2), nfs.JS) file = kit.Keys(kit.FileName(2), nfs.JS)
} }
@ -20,13 +24,13 @@ func Display(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
} }
return DisplayBase(m, file, arg...) return DisplayBase(m, file, arg...)
} }
func DisplayTable(m *ice.Message, arg ...ice.Any) *ice.Message { func DisplayTable(m Message, arg ...ice.Any) Message {
return DisplayBase(m, "/plugin/table.js", arg...) return DisplayBase(m, "/plugin/table.js", arg...)
} }
func DisplayTableCard(m *ice.Message, arg ...ice.Any) *ice.Message { func DisplayTableCard(m Message, arg ...ice.Any) Message {
return DisplayTable(m, "style", "card") return DisplayTable(m, "style", "card")
} }
func DisplayStory(m *ice.Message, file string, arg ...ice.Any) *ice.Message { func DisplayStory(m Message, file string, arg ...ice.Any) Message {
if file == "" { if file == "" {
file = kit.ExtChange(kit.FileName(2), nfs.JS) file = kit.ExtChange(kit.FileName(2), nfs.JS)
} }
@ -35,13 +39,13 @@ func DisplayStory(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
} }
return DisplayBase(m, file, arg...) return DisplayBase(m, file, arg...)
} }
func DisplayStoryJSON(m *ice.Message, arg ...ice.Any) *ice.Message { func DisplayStoryJSON(m Message, arg ...ice.Any) Message {
return DisplayStory(m, "json", arg...) return DisplayStory(m, "json", arg...)
} }
func DisplayStorySpide(m *ice.Message, arg ...ice.Any) *ice.Message { func DisplayStorySpide(m Message, arg ...ice.Any) Message {
return DisplayStory(m, "spide", arg...).StatusTimeCount() return DisplayStory(m, "spide", arg...)
} }
func DisplayLocal(m *ice.Message, file string, arg ...ice.Any) *ice.Message { func DisplayLocal(m Message, file string, arg ...ice.Any) Message {
if file == "" { if file == "" {
file = path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), ice.JS)) file = path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), ice.JS))
} }
@ -50,7 +54,7 @@ func DisplayLocal(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
} }
return DisplayBase(m, file, arg...) return DisplayBase(m, file, arg...)
} }
func DisplayBase(m *ice.Message, file string, arg ...ice.Any) *ice.Message { func DisplayBase(m Message, file string, arg ...ice.Any) Message {
m.Option(ice.MSG_DISPLAY, kit.MergeURL(kit.Select(kit.ExtChange(file, nfs.JS), file, strings.Contains(file, "?")), arg...)) m.Option(ice.MSG_DISPLAY, kit.MergeURL(kit.Select(kit.ExtChange(file, nfs.JS), file, strings.Contains(file, "?")), arg...))
return m return m
} }

View File

@ -112,7 +112,7 @@ func init() {
} }
}}, }},
mdb.CREATE: {Name: "create name*=hi repos template", Hand: func(m *ice.Message, arg ...string) { mdb.CREATE: {Name: "create name*=hi repos template", Hand: func(m *ice.Message, arg ...string) {
m.Option(nfs.REPOS, kit.Slice(kit.Split(m.Option(nfs.REPOS)), -1)[0]) m.Option(nfs.REPOS, kit.Select("", kit.Slice(kit.Split(m.Option(nfs.REPOS)), -1), 0))
_dream_show(m, m.OptionDefault(mdb.NAME, path.Base(m.Option(nfs.REPOS)))) _dream_show(m, m.OptionDefault(mdb.NAME, path.Base(m.Option(nfs.REPOS))))
}}, }},
cli.START: {Hand: func(m *ice.Message, arg ...string) { cli.START: {Hand: func(m *ice.Message, arg ...string) {

View File

@ -230,10 +230,19 @@ func init() {
_share_local(m, ice.USR_PUBLISH, path.Join(arg...)) _share_local(m, ice.USR_PUBLISH, path.Join(arg...))
}}, }},
PP(ice.REQUIRE): {Name: "/require/shylinux.com/x/volcanos/proto.js", Help: "代码库", Hand: func(m *ice.Message, arg ...string) { PP(ice.REQUIRE): {Name: "/require/shylinux.com/x/volcanos/proto.js", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
p := path.Join(ice.ISH_PLUGED, path.Join(arg...)) cache := kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, "go", "env", "GOMODCACHE"))
p := path.Join(cache, path.Join(arg...))
if !nfs.ExistsFile(m, p) { if !nfs.ExistsFile(m, p) {
m.Cmd(cli.SYSTEM, "git", "clone", "https://"+path.Join(arg[:3]...), path.Join(ice.ISH_PLUGED, path.Join(arg[:3]...))) if p = path.Join(ice.USR_REQUIRE, path.Join(arg...)); !nfs.ExistsFile(m, p) {
ls := strings.SplitN(path.Join(arg[:3]...), ice.AT, 2)
if v := kit.Select(ice.Info.Gomod[ls[0]], ls, 1); v == "" {
m.Cmd(cli.SYSTEM, "git", "clone", "https://"+ls[0], path.Join(ice.USR_REQUIRE, path.Join(arg[:3]...)))
} else {
m.Cmd(cli.SYSTEM, "git", "clone", "-b", v, "https://"+ls[0], path.Join(ice.USR_REQUIRE, path.Join(arg[:3]...)))
}
}
} }
m.Debug("what %v", p)
m.RenderDownload(p) m.RenderDownload(p)
}}, }},
PP(ice.REQUIRE, ice.NODE_MODULES): {Name: "/require/node_modules/", Help: "依赖库", Hand: func(m *ice.Message, arg ...string) { PP(ice.REQUIRE, ice.NODE_MODULES): {Name: "/require/node_modules/", Help: "依赖库", Hand: func(m *ice.Message, arg ...string) {

View File

@ -164,7 +164,7 @@ const SPACE = "space"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
SPACE: {Name: "space name cmd auto", Help: "空间站", Actions: ice.MergeActions(ice.Actions{ SPACE: {Name: "space name cmds auto", Help: "空间站", Actions: ice.MergeActions(ice.Actions{
tcp.DIAL: {Name: "dial dev=ops name", Hand: func(m *ice.Message, arg ...string) { tcp.DIAL: {Name: "dial dev=ops name", Hand: func(m *ice.Message, arg ...string) {
if strings.HasPrefix(m.Option(ice.DEV), ice.HTTP) { if strings.HasPrefix(m.Option(ice.DEV), ice.HTTP) {
m.Cmd(SPIDE, mdb.CREATE, ice.DEV, m.Option(ice.DEV)) m.Cmd(SPIDE, mdb.CREATE, ice.DEV, m.Option(ice.DEV))

View File

@ -108,6 +108,7 @@ const ( // DIR
USR_INSTALL = "usr/install/" USR_INSTALL = "usr/install/"
USR_PUBLISH = "usr/publish/" USR_PUBLISH = "usr/publish/"
USR_RELEASE = "usr/release/" USR_RELEASE = "usr/release/"
USR_REQUIRE = "usr/require/"
USR_LOCAL = "usr/local/" USR_LOCAL = "usr/local/"
USR_LOCAL_GO = "usr/local/go/" USR_LOCAL_GO = "usr/local/go/"

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
@ -55,26 +55,28 @@ func _binpack_all(m *ice.Message) {
_binpack_file(m, w, ice.README_MD) _binpack_file(m, w, ice.README_MD)
_binpack_file(m, w, ice.MAKEFILE) _binpack_file(m, w, ice.MAKEFILE)
_binpack_file(m, w, ice.LICENSE) _binpack_file(m, w, ice.LICENSE)
cache := kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, "go", "env", "GOMODCACHE"))
list := map[string]bool{} list := map[string]bool{}
ctx.TravelCmd(m, func(key, file, line string) { for k := range ice.Info.File {
dir := path.Dir(file) ls := strings.Split(k, ice.PS)
if strings.HasPrefix(dir, ice.SRC) { switch ls[2] {
return case ice.SRC:
case ice.USR:
list[path.Join(kit.Slice(ls, 2, -1)...)] = true
default:
list[path.Join(cache, path.Join(kit.Slice(ls, 2, -1)...))] = true
} }
if list[dir] { }
return for _, p := range kit.SortedKey(list) {
} m.Cmd(nfs.DIR, p, nfs.PATH, kit.Dict(nfs.DIR_ROOT, nfs.PWD, nfs.DIR_REG, kit.ExtReg("(sh|shy|js)"))).Tables(func(value ice.Maps) {
list[dir] = true if strings.Contains(value[nfs.PATH], "/go/pkg/mod/") {
m.Cmd(nfs.DIR, dir, nfs.PATH, kit.Dict(nfs.DIR_ROOT, nfs.PWD, nfs.DIR_REG, kit.ExtReg("(sh|shy|js)"))).Tables(func(value ice.Maps) { _binpack_file(m, w, value[nfs.PATH], ice.USR_REQUIRE+strings.Split(value[nfs.PATH], "/go/pkg/mod/")[1])
if list[value[nfs.PATH]] { } else {
return _binpack_file(m, w, value[nfs.PATH])
} }
if list[value[nfs.PATH]] = true; strings.Contains(value[nfs.PATH], "/go/pkg/mod/") {
value[nfs.PATH] = "/require/" + strings.Split(value[nfs.PATH], "/go/pkg/mod/")[1]
}
_binpack_file(m, w, value[nfs.PATH])
}) })
}) }
mdb.HashSelects(m).Sort(nfs.PATH).Tables(func(value ice.Maps) { mdb.HashSelects(m).Sort(nfs.PATH).Tables(func(value ice.Maps) {
if s, e := nfs.StatFile(m, value[nfs.PATH]); e == nil { if s, e := nfs.StatFile(m, value[nfs.PATH]); e == nil {
if s.IsDir() { if s.IsDir() {

View File

@ -61,6 +61,9 @@ func _publish_contexts(m *ice.Message, arg ...string) {
m.Option(web.DOMAIN, fmt.Sprintf("%s://%s:%s", u.Scheme, host, kit.Select(kit.Select("443", "80", u.Scheme == ice.HTTP), strings.Split(u.Host, ice.DF), 1))) m.Option(web.DOMAIN, fmt.Sprintf("%s://%s:%s", u.Scheme, host, kit.Select(kit.Select("443", "80", u.Scheme == ice.HTTP), strings.Split(u.Host, ice.DF), 1)))
for _, k := range kit.Default(arg, ice.MISC) { for _, k := range kit.Default(arg, ice.MISC) {
switch k { switch k {
case INSTALL:
m.Echo(kit.Renders(`export ctx_dev={{.Option "domain"}}{{.Option "ctx_env"}}; ctx_temp=$(mktemp); wget -O $ctx_temp -q $ctx_dev; source $ctx_temp app username {{.Option "user.name"}} usernick {{.Option "user.nick"}}`, m))
return
case ice.MISC: case ice.MISC:
_publish_file(m, ice.ICE_BIN) _publish_file(m, ice.ICE_BIN)
case ice.CORE: case ice.CORE:

View File

@ -31,6 +31,7 @@ var Info = struct {
Help string Help string
File Maps File Maps
Gomod Maps
Route Maps Route Maps
Index Map Index Map
@ -49,6 +50,7 @@ server: https://shylinux.com
source: https://shylinux.com/x/icebergs source: https://shylinux.com/x/icebergs
`, `,
File: Maps{}, File: Maps{},
Gomod: Maps{},
Route: Maps{}, Route: Maps{},
Index: Map{}, Index: Map{},