From c959706ba42858f21752f890b71b9d2e7ba77e5d Mon Sep 17 00:00:00 2001 From: shy Date: Sat, 24 Feb 2024 18:18:50 +0800 Subject: [PATCH] add some --- base/nfs/cat.go | 4 ++ base/web/dream.go | 5 ++- base/web/html/html.go | 2 + base/web/matrix.go | 7 ++-- base/web/render.go | 1 + core/code/code.go | 3 +- core/code/version.go | 95 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 core/code/version.go diff --git a/base/nfs/cat.go b/base/nfs/cat.go index 95a6b9c9..6c3ecc6f 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -43,6 +43,10 @@ func _cat_list(m *ice.Message, p string) { list := []string{} kit.For(f, func(s string, i int) { list = append(list, cb(s, i)) }) m.Echo(strings.Join(list, ice.NL) + ice.NL) + case func([]string, string) string: + list := []string{} + kit.For(f, func(s string, i int) { list = append(list, cb(kit.Split(s), s)) }) + m.Echo(strings.Join(list, ice.NL) + ice.NL) case func(string, int): kit.For(f, cb) case func(string): diff --git a/base/web/dream.go b/base/web/dream.go index 010fbf3f..fc2308b8 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -339,6 +339,9 @@ func init() { }) }).ProcessHold() }}, + VERSION: {Hand: func(m *ice.Message, arg ...string) { + m.Cmdy("web.code.version") + }}, FOR_FLOW: {Name: "forFlow name cmd*='sh etc/miss.sh'", Help: "流程", Icon: "bi bi-terminal", Hand: func(m *ice.Message, arg ...string) { m.Options(ctx.DISPLAY, PLUGIN_XTERM, cli.CMD_OUTPUT, nfs.NewWriteCloser(func(buf []byte) (int, error) { PushNoticeGrow(m.Options(ice.MSG_COUNT, "0", ice.LOG_DEBUG, ice.FALSE), strings.ReplaceAll(string(buf), lex.NL, "\r\n")) @@ -438,7 +441,7 @@ func init() { if ice.Info.NodeType == WORKER || !aaa.IsTechOrRoot(m) || m.IsCliUA() { m.Action() } else if cli.SystemFindGo(m) { - m.Action(html.FILTER, mdb.CREATE, STARTALL, STOPALL, cli.BUILD, PUBLISH, nfs.FILE) + m.Action(html.FILTER, mdb.CREATE, STARTALL, STOPALL, cli.BUILD, PUBLISH, nfs.FILE, VERSION) } else { m.Action(html.FILTER, mdb.CREATE, STARTALL, STOPALL) } diff --git a/base/web/html/html.go b/base/web/html/html.go index 26c50b79..3bc54f07 100644 --- a/base/web/html/html.go +++ b/base/web/html/html.go @@ -78,6 +78,8 @@ const ( RESIZE = "resize" REFRESH = "refresh" FILTER = "filter" + + DANGER = "danger" ) const ( diff --git a/base/web/matrix.go b/base/web/matrix.go index c40df7f6..73611391 100644 --- a/base/web/matrix.go +++ b/base/web/matrix.go @@ -80,9 +80,7 @@ func init() { COMPILE: {Hand: func(m *ice.Message, arg ...string) { _matrix_cmd(m, "", cli.AMD64, cli.LINUX, ice.SRC_MAIN_GO).ProcessHold() }}, - UPGRADE: {Hand: func(m *ice.Message, arg ...string) { - _matrix_cmd(m, "").ProcessRefresh().Sleep3s() - }}, + UPGRADE: {Hand: func(m *ice.Message, arg ...string) { _matrix_cmd(m, "").ProcessRefresh().Sleep3s() }}, INSTALL: {Hand: func(m *ice.Message, arg ...string) { if kit.IsIn(m.Cmdv(Space(m, m.Option(DOMAIN)), SPIDE, ice.DEV_IP, CLIENT_HOSTNAME), m.Cmd(tcp.HOST).Appendv(aaa.IP)...) { m.Option(nfs.BINARY, S(m.Option(mdb.NAME))) @@ -91,7 +89,7 @@ func init() { } _matrix_dream(m, mdb.CREATE, kit.Simple(m.OptionSimple(mdb.ICONS, nfs.REPOS, nfs.BINARY))...) }}, - }, ctx.ConfAction(mdb.FIELD, "time,domain,status,type,name,text,icons,repos,binary,module,version")), Hand: func(m *ice.Message, arg ...string) { + }, ctx.ConfAction(mdb.FIELD, "time,domain,status,type,name,text,icons,repos,binary,module,version", ctx.TOOLS, kit.Simple(STATUS, VERSION))), Hand: func(m *ice.Message, arg ...string) { if kit.HasPrefixList(arg, ctx.ACTION) { _matrix_action(m, arg[1], arg[2:]...) return @@ -112,6 +110,7 @@ func init() { m.StatusTimeCountStats(mdb.TYPE, mdb.STATUS) return nil }).Action(html.FILTER, mdb.CREATE).Display("") + ctx.Toolkit(m) }}, }) } diff --git a/base/web/render.go b/base/web/render.go index 138dc2e2..d3b56d0d 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -160,6 +160,7 @@ const ( BINPACK = "binpack" COMPILE = "compile" PUBLISH = "publish" + VERSION = "version" UPGRADE = "upgrade" INSTALL = "install" diff --git a/core/code/code.go b/core/code/code.go index b93627b8..f476ea19 100644 --- a/core/code/code.go +++ b/core/code/code.go @@ -12,7 +12,8 @@ var Index = &ice.Context{Name: CODE, Help: "编程中心"} func init() { web.Index.Register(Index, &web.Frame{}, - WEBPACK, BINPACK, AUTOGEN, COMPILE, PUBLISH, UPGRADE, INSTALL, + WEBPACK, BINPACK, AUTOGEN, VERSION, + COMPILE, PUBLISH, UPGRADE, INSTALL, XTERM, INNER, VIMER, BENCH, PPROF, TEMPLATE, COMPLETE, NAVIGATE, ) diff --git a/core/code/version.go b/core/code/version.go new file mode 100644 index 00000000..d0d3384e --- /dev/null +++ b/core/code/version.go @@ -0,0 +1,95 @@ +package code + +import ( + "path" + "strings" + + ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/cli" + "shylinux.com/x/icebergs/base/lex" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/web" + "shylinux.com/x/icebergs/base/web/html" + kit "shylinux.com/x/toolkits" +) + +func init() { + Index.MergeCommands(ice.Commands{ + VERSION: {Name: "version refresh", Help: "版本", Actions: ice.MergeActions(ice.Actions{ + mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { + ls := kit.Split(kit.Split(strings.TrimPrefix(m.Option(VERSION), "v"), "-")[0], ".") + if len(ls) > 2 { + m.Push(arg[0], kit.Format("v%d.%d.%d", kit.Int(ls[0]), kit.Int(ls[1]), kit.Int(ls[2])+1)) + m.Push(arg[0], kit.Format("v%d.%d.%d", kit.Int(ls[0]), kit.Int(ls[1])+1, 0)) + m.Push(arg[0], kit.Format("v%d.%d.%d", kit.Int(ls[0])+1, 0, 0)) + } else { + m.Push(arg[0], "v0.0.1") + } + }}, + "sync": {Help: "同步", Hand: func(m *ice.Message, arg ...string) { + repos := map[string]string{} + m.Cmd("web.code.mod", mdb.RENDER, MOD, ice.GO_MOD, nfs.PWD).Table(func(value ice.Maps) { repos[value[REQUIRE]] = value[VERSION] }) + res := m.Cmdx(nfs.CAT, path.Join(nfs.USR_LOCAL_WORK, m.Option(SPACE), ice.GO_MOD), func(ls []string, text string) string { + if len(ls) == 2 { + if v, ok := repos[ls[0]]; ok { + text = lex.TB + ls[0] + lex.SP + v + } + } + return text + }) + m.Cmd(nfs.SAVE, path.Join(nfs.USR_LOCAL_WORK, m.Option(SPACE), ice.GO_MOD), res) + m.Cmd(SPACE, m.Option(SPACE), cli.SYSTEM, GO, MOD, "tidy") + }}, + "add": {Name: "add version", Hand: func(m *ice.Message, arg ...string) { + }}, + }), Hand: func(m *ice.Message, arg ...string) { + repos := map[string]string{} + list := map[string]map[string]string{} + list[ice.Info.Pathname] = map[string]string{} + m.Cmd("web.code.mod", mdb.RENDER, MOD, ice.GO_MOD, nfs.PWD).Table(func(value ice.Maps) { + list[ice.Info.Pathname][value[REQUIRE]] = value[VERSION] + if value[REPLACE] == nfs.PWD { + list[ice.Info.Pathname][MODULE] = value[REQUIRE] + list[ice.Info.Pathname][VERSION] = value[VERSION] + } else { + repos[value[REQUIRE]] = value[VERSION] + } + }) + web.DreamEach(m, m.Option(mdb.NAME), "", func(name string) { + list[name] = map[string]string{} + m.Cmd(web.SPACE, name, "web.code.mod", mdb.RENDER, MOD, ice.GO_MOD, nfs.PWD).Table(func(value ice.Maps) { + if value[REPLACE] == nfs.PWD { + list[name][MODULE] = value[REQUIRE] + list[name][VERSION] = value[VERSION] + } else { + list[name][value[REQUIRE]] = value[VERSION] + } + }) + list[name]["diff"] = kit.ReplaceAll(m.Cmdx(web.SPACE, name, cli.SYSTEM, "git", "diff", "--shortstat"), " changed", "", "tions", "") + }) + for space, v := range list { + diff := false + m.Push(web.SPACE, space) + m.Push(MODULE, list[space][MODULE]) + m.Push(VERSION, list[space][VERSION]) + kit.For(repos, func(k, _v string) { + m.Push(k, v[k]) + kit.If(v[k] != "" && v[k] != _v, func() { diff = true }) + }) + m.Push("diff", list[space]["diff"]) + if diff { + m.Push(mdb.STATUS, html.DANGER).PushButton("sync", "add") + } else { + if strings.Contains(m.Option(VERSION), "-") { + m.Push(mdb.STATUS, "").PushButton("add") + } else { + m.Push(mdb.STATUS, "").PushButton("") + } + } + } + m.Sort(web.SPACE, ice.STR_R) + }}, + }) + +}