diff --git a/base/cli/forever.go b/base/cli/forever.go index 5af0c4bb..1b9f8c58 100644 --- a/base/cli/forever.go +++ b/base/cli/forever.go @@ -15,15 +15,15 @@ func _path_sep() string { return kit.Select(":", ";", strings.Contains(os.Getenv(PATH), ";")) } func BinPath(arg ...string) string { - var list = []string{} + list := []string{} push := func(p string) { kit.If(kit.IndexOf(list, p) == -1, func() { list = append(list, p) }) } - for _, p := range arg { + kit.For(arg, func(p string) { list = append(list, kit.Path(p, ice.BIN), kit.Path(p, ice.USR_PUBLISH), kit.Path(p, ice.USR_LOCAL_BIN), kit.Path(p, ice.USR_LOCAL_GO_BIN)) for _, l := range kit.Revert(strings.Split(ice.Pulse.Cmdx(nfs.CAT, kit.Path(p, ice.ETC_PATH)), ice.NL)) { kit.If(strings.TrimSpace(l) != "" && !strings.HasPrefix(strings.TrimSpace(l), "#"), func() { push(kit.Path(p, l)) }) } - } - kit.Fetch(strings.Split(kit.Env(PATH), _path_sep()), func(p string) { push(p) }) + }) + kit.For(strings.Split(kit.Env(PATH), _path_sep()), func(p string) { push(p) }) return kit.Join(list, _path_sep()) } @@ -34,11 +34,7 @@ func init() { FOREVER: {Name: "forever auto", Help: "启动", Actions: ice.Actions{ START: {Hand: func(m *ice.Message, arg ...string) { env := []string{PATH, BinPath(""), HOME, kit.Select(kit.Path(""), os.Getenv(HOME))} - for _, k := range ENV_LIST { - if kit.Env(k) != "" { - env = append(env, k, kit.Env(k)) - } - } + kit.For(ENV_LIST, func(k string) { kit.If(kit.Env(k) != "", func() { env = append(env, k, kit.Env(k)) }) }) for _, v := range os.Environ() { if ls := kit.Split(v, ice.EQ, ice.EQ); kit.IndexOf(env, ls[0]) == -1 && len(ls) > 1 { env = append(env, ls[0], ls[1]) diff --git a/core/code/autogen.go b/core/code/autogen.go index 3557ea9f..67b6a844 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -99,6 +99,9 @@ func _autogen_mod(m *ice.Message, file string) (mod string) { const AUTOGEN = "autogen" func init() { + const ( + VERSION = "version" + ) const ( USR_RELEASE_CONF_GO = "usr/release/conf.go" USR_RELEASE_BINPACK_GO = "usr/release/binpack.go" diff --git a/core/code/code.go b/core/code/code.go index 9b54728f..b0ce0ce7 100644 --- a/core/code/code.go +++ b/core/code/code.go @@ -2,28 +2,19 @@ package code import ( ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/ctx" - "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) const CODE = "code" -var Index = &ice.Context{Name: CODE, Help: "编程中心", Commands: ice.Commands{ - ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - m.Conf(TEMPLATE, kit.Keym(mdb.SHORT), mdb.TYPE) - m.Conf(COMPLETE, kit.Keym(mdb.SHORT), mdb.TYPE) - m.Conf(NAVIGATE, kit.Keym(mdb.SHORT), mdb.TYPE) - ctx.Load(m) - }}, -}} +var Index = &ice.Context{Name: CODE, Help: "编程中心"} func init() { web.Index.Register(Index, &web.Frame{}, INSTALL, UPGRADE, WEBPACK, BINPACK, AUTOGEN, COMPILE, PUBLISH, - VIMER, INNER, FAVOR, XTERM, PPROF, BENCH, - C, SH, SHY, GO, JS, + VIMER, INNER, XTERM, PPROF, BENCH, + C, SH, SHY, PY, GO, JS, CSS, HTML, ) } diff --git a/core/code/code.shy b/core/code/code.shy index 7e9eaf12..f6f36375 100644 --- a/core/code/code.shy +++ b/core/code/code.shy @@ -9,10 +9,9 @@ autogen.go compile.go publish.go -xterm.shy -xterm.go vimer.go inner.go +xterm.go favor.go oauth.go pprof.go @@ -20,10 +19,10 @@ bench.go case.go c.go -go.go sh.go shy.go py.go +go.go js.go css.go html.go \ No newline at end of file diff --git a/core/code/compile.go b/core/code/compile.go index 7c297895..d0b49b93 100644 --- a/core/code/compile.go +++ b/core/code/compile.go @@ -18,16 +18,12 @@ func _compile_target(m *ice.Message, arg ...string) (string, string, string, str main, file, goos, arch := ice.SRC_MAIN_GO, "", runtime.GOOS, runtime.GOARCH for _, k := range arg { switch k { - case cli.AMD64, cli.X86, cli.MIPSLE, cli.ARM, cli.ARM64: + case cli.AMD64, cli.X86, cli.ARM, cli.ARM64, cli.MIPSLE: arch = k case cli.LINUX, cli.DARWIN, cli.WINDOWS: goos = k default: - if kit.Ext(k) == GO { - main = k - } else { - file = k - } + kit.If(kit.Ext(k) == GO, func() { main = k }, func() { file = k }) } } if file == "" { @@ -36,13 +32,13 @@ func _compile_target(m *ice.Message, arg ...string) (string, string, string, str return main, file, goos, arch } -const ( - SERVICE = "service" - VERSION = "version" -) const COMPILE = "compile" func init() { + const ( + SERVICE = "service" + VERSION = "version" + ) Index.MergeCommands(ice.Commands{ COMPILE: {Name: "compile arch=amd64,386,arm,arm64,mipsle os=linux,darwin,windows src=src/main.go@key run binpack webpack devpack upgrade install", Help: "编译", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { cli.IsAlpine(m, GO, "go git") }}, @@ -51,7 +47,7 @@ func init() { case SERVICE: m.Push(arg[0], m.Cmd(web.SPIDE, ice.DEV).Append(web.CLIENT_ORIGIN)+"/publish/") case VERSION: - m.Push(arg[0], "1.15.15") + m.Push(arg[0], "1.15.5", "1.17.3") default: m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, kit.ExtReg(GO))) } @@ -60,22 +56,18 @@ func init() { WEBPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, WEBPACK) }}, DEVPACK: {Help: "开发", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, DEVPACK) }}, UPGRADE: {Help: "升级", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(UPGRADE, nfs.TARGET) }}, - INSTALL: {Name: "install service*='https://golang.google.cn/dl/' version*=1.15.15", Help: "安装", Hand: func(m *ice.Message, arg ...string) { + INSTALL: {Name: "install service*='https://golang.google.cn/dl/' version*=1.15.5", Help: "安装", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(INSTALL, web.DOWNLOAD, kit.Format("%s/go%s.%s-%s.%s", m.Option(SERVICE), m.Option(VERSION), runtime.GOOS, runtime.GOARCH, kit.Select("tar.gz", "zip", runtime.GOOS == cli.WINDOWS)), ice.USR_LOCAL) }}, }, ctx.ConfAction(cli.ENV, kit.Dict("GOPRIVATE", "shylinux.com,github.com", "GOPROXY", "https://goproxy.cn,direct", "CGO_ENABLED", "0"))), Hand: func(m *ice.Message, arg ...string) { defer web.ToastProcess(m)() main, file, goos, arch := _compile_target(m, arg...) - env := kit.Simple(cli.PATH, kit.Env(cli.PATH), cli.HOME, kit.Select(kit.Path(""), kit.Env(cli.HOME)), m.Configv(cli.ENV), m.Optionv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch) - if runtime.GOOS == cli.WINDOWS { - env = append(env, "GOPATH", kit.HomePath(GO), "GOCACHE", kit.HomePath("go/go-build")) - } + env := kit.Simple(cli.PATH, cli.BinPath(), cli.HOME, kit.Select(kit.Path(""), kit.Env(cli.HOME)), m.Configv(cli.ENV), m.Optionv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch) + kit.If(runtime.GOOS == cli.WINDOWS, func() { env = append(env, "GOPATH", kit.HomePath(GO), "GOCACHE", kit.HomePath("go/go-build")) }) m.Optionv(cli.CMD_ENV, env) - if !strings.Contains(m.Cmdx(nfs.CAT, ice.GO_MOD), "shylinux.com/x/ice") { - m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice") - } m.Cmd(AUTOGEN, VERSION) defer m.StatusTime(VERSION, strings.TrimPrefix(m.Cmdx(cli.SYSTEM, GO, VERSION), "go version")) + kit.If(!strings.Contains(m.Cmdx(nfs.CAT, ice.GO_MOD), "shylinux.com/x/ice"), func() { m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice") }) if msg := m.Cmd(cli.SYSTEM, GO, cli.BUILD, "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) { m.Copy(msg) return diff --git a/core/code/css.go b/core/code/css.go index 95c6ade6..21efecc6 100644 --- a/core/code/css.go +++ b/core/code/css.go @@ -13,11 +13,8 @@ import ( func _css_stat(m *ice.Message, zone string, stats map[string]int) { msg := m.Spawn() - for k, v := range stats { - msg.Push(mdb.NAME, k).Push(mdb.VALUE, v).Push(mdb.ZONE, zone) - } - msg.SortIntR(mdb.VALUE) - m.Copy(msg) + kit.For(stats, func(k string, v int) { msg.Push(mdb.NAME, k).Push(mdb.VALUE, v).Push(mdb.ZONE, zone) }) + m.Copy(msg.SortIntR(mdb.VALUE)) } func _css_show(m *ice.Message, arg ...string) { zone, stats_key, stats_value := "", map[string]int{}, map[string]int{} @@ -56,10 +53,13 @@ func _css_show(m *ice.Message, arg ...string) { m.StatusTimeCount() } func _css_exec(m *ice.Message, arg ...string) { - if arg[2] == ice.USR_VOLCANOS && strings.HasPrefix(arg[1], ice.PLUGIN_LOCAL) { - key := ctx.GetFileCmd("/require/shylinux.com/x/icebergs/core/" + strings.TrimPrefix(arg[1], ice.PLUGIN_LOCAL)) - ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, key), kit.Simple()) - return + if arg[2] == ice.USR_VOLCANOS { + if strings.HasPrefix(arg[1], ice.PLUGIN_LOCAL) { + ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(kit.TrimExt(strings.TrimPrefix(arg[1], ice.PLUGIN_LOCAL), JS), ice.PS, ice.PT, -1)), kit.Simple()) + } + } else { + ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))), kit.Simple()) + m.Push(ctx.STYLE, path.Join("/require", path.Join(arg[2], arg[1]))) } } @@ -69,18 +69,9 @@ func init() { Index.MergeCommands(ice.Commands{ CSS: {Name: "css path auto", Help: "样式表", Actions: ice.MergeActions(ice.Actions{ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _css_show(m, arg...) }}, - mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - if arg[2] == ice.USR_VOLCANOS { - if strings.HasPrefix(arg[1], "plugin/local/") { - ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(kit.TrimExt(strings.TrimPrefix(arg[1], "plugin/local/"), JS), ice.PS, ice.PT, -1)), kit.Simple()) - } - } else { - m.Push(ctx.STYLE, path.Join("/require", path.Join(arg[2], arg[1]))) - ctx.ProcessCommand(m, kit.Select("can._plugin", ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))), kit.Simple()) - } - }}, + mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _css_exec(m, arg...) }}, TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { - m.Echo(kit.Format(nfs.Template(m, "demo.css"), kit.Select("plugin", ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))))) + m.Echo(kit.Format(nfs.Template(m, "demo.css"), kit.Select(mdb.PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))))) }}, }, PlugAction())}, }) diff --git a/core/code/html.go b/core/code/html.go index e05dbe86..fdbd8484 100644 --- a/core/code/html.go +++ b/core/code/html.go @@ -7,7 +7,6 @@ import ( "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" - "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -17,11 +16,10 @@ func init() { Index.MergeCommands(ice.Commands{ HTML: {Name: "html path auto", Help: "网页", Actions: ice.MergeActions(ice.Actions{ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { - m.EchoIFrame(kit.MergeURL(path.Join(ice.PS, ice.REQUIRE, arg[2], arg[1]), "_v", kit.Hashs("uniq"))) + m.EchoIFrame(kit.MergeURL(path.Join(ice.PS, ice.REQUIRE, arg[2], arg[1]), "_v", kit.Hashs(mdb.UNIQ))) }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { - p := kit.MergeURL(path.Join(ice.PS, ice.REQUIRE, arg[2], arg[1]), "_v", kit.Hashs("uniq")) - m.EchoIFrame(p).StatusTime(web.LINK, p) + m.EchoIFrame(kit.MergeURL(path.Join(ice.PS, ice.REQUIRE, arg[2], arg[1]), "_v", kit.Hashs(mdb.UNIQ))) }}, TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(kit.Renders(nfs.TemplateText(m, "demo.html"), ice.Maps{ice.LIST: kit.Format(kit.List(kit.Dict(ctx.INDEX, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO)))))})).RenderResult() diff --git a/core/code/webpack.go b/core/code/webpack.go index c98e1c52..61bfaa6c 100644 --- a/core/code/webpack.go +++ b/core/code/webpack.go @@ -132,7 +132,7 @@ func init() { kit.If(!strings.Contains(m.Option(nfs.PATH), "/page/"), func() { nfs.Trash(m, m.Option(nfs.PATH)) }) }}, }, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path")), Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(nfs.DIR, ice.USR_PUBLISH, kit.Dict(nfs.DIR_REG, kit.ExtReg(HTML, CSS, JS))).Cmdy(nfs.DIR, _volcanos(m, PAGE)) + m.Cmdy(nfs.DIR, _volcanos(m, PAGE), kit.Dict(nfs.DIR_REG, kit.ExtReg(HTML, CSS, JS))).Cmdy(nfs.DIR, ice.USR_PUBLISH) }}, }) } diff --git a/meta.go b/meta.go index dbf4036f..3f6b3b3e 100644 --- a/meta.go +++ b/meta.go @@ -404,12 +404,12 @@ func (m *Message) Sort(key string, arg ...string) *Message { } return m } -func (m *Message) SortInt(key string) { m.Sort(key, INT) } -func (m *Message) SortStr(key string) { m.Sort(key, STR) } -func (m *Message) SortTime(key string) { m.Sort(key, TIME) } +func (m *Message) SortInt(key string) *Message { return m.Sort(key, INT) } +func (m *Message) SortStr(key string) *Message { return m.Sort(key, STR) } +func (m *Message) SortTime(key string) *Message { return m.Sort(key, TIME) } func (m *Message) SortTimeR(key string) *Message { return m.Sort(key, TIME_R) } -func (m *Message) SortStrR(key string) { m.Sort(key, STR_R) } -func (m *Message) SortIntR(key string) { m.Sort(key, INT_R) } +func (m *Message) SortStrR(key string) *Message { return m.Sort(key, STR_R) } +func (m *Message) SortIntR(key string) *Message { return m.Sort(key, INT_R) } func (m *Message) Detail(arg ...Any) string { return kit.Select("", m.meta[MSG_DETAIL], 0)