diff --git a/base/mdb/hash.go b/base/mdb/hash.go index 65d2e3fd..1a19d561 100644 --- a/base/mdb/hash.go +++ b/base/mdb/hash.go @@ -234,7 +234,14 @@ func HashSelect(m *ice.Message, arg ...string) *ice.Message { if m.FieldsIsDetail() { m.Table(func(value ice.Maps) { m.SetAppend().OptionFields(ice.FIELDS_DETAIL) - kit.For(kit.Split(HashField(m)), func(key string) { m.Push(key, value[key]); delete(value, key) }) + kit.For(kit.Split(HashField(m)), func(key string) { + if key == HASH { + m.Push(key, arg[0]) + } else { + m.Push(key, value[key]) + } + delete(value, key) + }) kit.For(kit.SortedKey(value), func(k string) { m.Push(k, value[k]) }) }) } diff --git a/base/web/admin.go b/base/web/admin.go index cec32d44..7efdd250 100644 --- a/base/web/admin.go +++ b/base/web/admin.go @@ -14,7 +14,7 @@ func init() { Index.MergeCommands(ice.Commands{ ADMIN: {Name: "admin index list", Help: "管理", Hand: func(m *ice.Message, arg ...string) { kit.If(len(arg) == 0, func() { arg = append(arg, SPACE, DOMAIN) }) - m.Cmdy(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, CHAT_CMD+path.Join(arg...)) + m.Cmdy(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, CHAT_CMD+path.Join(arg...), "pwd", kit.Path("")) }}, }) } diff --git a/base/web/cache.go b/base/web/cache.go index 68e2837f..fb3fdb65 100644 --- a/base/web/cache.go +++ b/base/web/cache.go @@ -104,6 +104,7 @@ const ( UPLOAD = "upload" DOWNLOAD = "download" PREVIEW = "preview" + PAGES = "pages" IMAGE = "image" VIDEO = "video" diff --git a/base/web/spide.go b/base/web/spide.go index def2de4c..aa263415 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -276,6 +276,7 @@ func init() { if p := path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...)); nfs.Exists(m, p) { return p + kit.Select("", nfs.PS, len(arg) == 0) } else { + m.Debug("what %v", p) return path.Join(path.Dir(ctx.GetCmdFile(m, m.PrefixKey())), path.Join(arg...)) + kit.Select("", nfs.PS, len(arg) == 0) } } diff --git a/core/chat/favor.go b/core/chat/favor.go index a3c277c4..c32dfd3f 100644 --- a/core/chat/favor.go +++ b/core/chat/favor.go @@ -76,6 +76,7 @@ func init() { }}, web.PREVIEW: {Hand: FavorPreview}, cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, m.Option(mdb.TEXT)) }}, + web.PAGES: {Name: "favor.js"}, }, FavorAction(), mdb.ExportHashAction(mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,hash,type,name,text")), Hand: func(m *ice.Message, arg ...string) { if len(arg) > 0 && arg[0] == ctx.ACTION { if m.Option(ice.MSG_INDEX) == m.PrefixKey() { diff --git a/lock.go b/lock.go index ed528704..a5477d67 100644 --- a/lock.go +++ b/lock.go @@ -61,8 +61,8 @@ func (m *Message) setDetail(key string, arg ...string) *Message { m._meta[KEY][i] = m._meta[KEY][i+1] m._meta[VALUE][i] = m._meta[VALUE][i+1] } - m._meta[KEY] = kit.Slice(m._meta[KEY], 0, -1) - m._meta[VALUE] = kit.Slice(m._meta[VALUE], 0, -1) + m._meta[KEY] = m._meta[KEY][0:len(m._meta[KEY])] + m._meta[VALUE] = m._meta[VALUE][0:len(m._meta[VALUE])] return m } } diff --git a/misc/ssh/relay/relay.go b/misc/ssh/relay/relay.go index 0f14995e..f7319e76 100644 --- a/misc/ssh/relay/relay.go +++ b/misc/ssh/relay/relay.go @@ -229,7 +229,7 @@ func (s relay) Install(m *ice.Message, arg ...string) { } func (s relay) Upgrade(m *ice.Message, arg ...string) { if len(arg) == 0 && m.Option(MACHINE) == "" { - m.Options(ice.CMD, m.Template(UPGRADE_SH), cli.DELAY, "0", "interval", "10s") + m.Options(ice.CMD, m.Template(UPGRADE_SH), cli.DELAY, "0", "interval", "15s") s.ForFlow(m) } else { s.shell(m, m.Template(UPGRADE_SH), arg...) diff --git a/misc/wx/ide.go b/misc/wx/ide.go index 265cdf38..e2d72442 100644 --- a/misc/wx/ide.go +++ b/misc/wx/ide.go @@ -33,6 +33,44 @@ func _ide_args_cli(m *ice.Message) []string { func _ide_args_qrcode(m *ice.Message, p string) []string { return []string{"--qr-format", nfs.IMAGE, "--qr-output", kit.Path(p)} } +func _ide_autogen_utils(m *ice.Message) { + p, mp := ice.USR_PROGRAM, ice.USR_VOLCANOS+PUBLISH_CLIENT_MP + nfs.DirDeepAll(m, mp, "", func(value ice.Maps) { + if !kit.IsIn(value[nfs.PATH], PROJECT_CONFIG_JSON, PROJECT_PRIVATE_CONFIG_JSON, CONF_JS) { + m.Cmd(nfs.COPY, p+value[nfs.PATH], path.Join(mp, value[nfs.PATH]), ice.Maps{nfs.DIR_ROOT: ""}) + } + }) +} +func _ide_autogen_pages(m *ice.Message) { + p := ice.USR_PROGRAM + list := []string{} + head_wxml, foot_wxml := nfs.TemplateText(m, "pages_head.wxml"), nfs.TemplateText(m, "pages_foot.wxml") + head, foot := nfs.TemplateText(m, "pages_head.js"), nfs.TemplateText(m, "pages_foot.js") + wxml := nfs.TemplateText(m, "pages.wxml") + m.Travel(func(_ *ice.Context, s *ice.Context, key string, cmd *ice.Command) { + if h, ok := cmd.Actions[PAGES]; ok { + file := path.Join(path.Dir(strings.TrimPrefix(m.Resource(ctx.FileURI(cmd.FileLine())), nfs.REQUIRE)), kit.Select(key+".js", h.Name)) + if !nfs.Exists(m, file) { + return + } + prefix := strings.ReplaceAll(s.Prefix(), nfs.PT, "-") + list = append(list, path.Join(PAGES, prefix, kit.TrimExt(path.Base(file), nfs.JS))) + kit.For([]string{WXML, WXSS, nfs.JS, nfs.JSON}, func(ext string) { + file = kit.ExtChange(file, ext) + if kit.Ext(file) == nfs.JS { + m.Cmd(nfs.SAVE, path.Join(p, PAGES, prefix, path.Base(file)), head, lex.NL, m.Cmdx(nfs.CAT, file), lex.NL, foot) + } else if kit.Ext(file) == WXML { + m.Cmd(nfs.SAVE, path.Join(p, PAGES, prefix, path.Base(file)), head_wxml, lex.NL, kit.Select(wxml, m.Cmdx(nfs.CAT, file)), lex.NL, foot_wxml) + } else { + m.Cmd(nfs.COPY, path.Join(p, PAGES, prefix, path.Base(file)), file) + } + }) + } + }) + app := kit.UnMarshal(m.Cmdx(nfs.CAT, p+APP_JSON)) + kit.Value(app, PAGES, kit.AddUniq(kit.Simple(kit.Value(app, PAGES)), list...)) + m.Cmd(nfs.SAVE, p+APP_JSON, kit.Formats(app)) +} const ( PAGES_RIVER = "pages/river/river" @@ -45,55 +83,33 @@ const ( PAGES = "pages" ENV = "env" ) +const ( + AUTO_PREVIEW = "auto-preview" + PREVIEW = "preview" + PUSH = "push" + DOC = "doc" + + APP_JSON = "app.json" + CONF_JS = "conf.js" + CURRENT = "current" + ISLOGIN = "islogin" +) +const ( + PROJECT_CONFIG_JSON = "project.config.json" + PROJECT_PRIVATE_CONFIG_JSON = "project.private.config.json" +) const IDE = "ide" func init() { - const ( - AUTO_PREVIEW = "auto-preview" - PREVIEW = "preview" - PUSH = "push" - DOC = "doc" - - APP_JSON = "app.json" - CURRENT = "current" - ISLOGIN = "islogin" - ) Index.MergeCommands(ice.Commands{ IDE: {Name: "ide hash auto", Help: "集成开发环境", Meta: Meta(), Actions: ice.MergeActions(ice.Actions{ code.AUTOGEN: {Name: "autogen projectname*='终端工具链' appid*='wxf4e5104d83476ed6' serve*='https://2021.shylinux.com'", Help: "生成", Hand: func(m *ice.Message, arg ...string) { - const ( - CONF_JS = "conf.js" - APP_JSON = "app.json" - PROJECT_CONFIG_JSON = "project.config.json" - PROJECT_PRIVATE_CONFIG_JSON = "project.private.config.json" - ) - p, mp := ice.USR_PROGRAM, ice.USR_VOLCANOS+PUBLISH_CLIENT_MP - nfs.DirDeepAll(m, mp, "", func(value ice.Maps) { - if !kit.IsIn(value[nfs.PATH], PROJECT_CONFIG_JSON, PROJECT_PRIVATE_CONFIG_JSON) { - m.Cmd(nfs.COPY, p+value[nfs.PATH], path.Join(mp, value[nfs.PATH]), ice.Maps{nfs.DIR_ROOT: ""}) - } - }) - m.Cmd(nfs.SAVE, p+CONF_JS, `module.exports = `+kit.Formats(kit.Dict( - m.OptionSimple(APPID, web.SERVE), nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions(), - ))) + _ide_autogen_utils(m) + _ide_autogen_pages(m) + p := ice.USR_PROGRAM + m.Cmd(nfs.SAVE, p+CONF_JS, `module.exports = `+kit.Formats(kit.Dict(m.OptionSimple(APPID, web.SERVE), nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions()))) m.Cmd(nfs.DEFS, p+PROJECT_CONFIG_JSON, kit.Formats(kit.Dict(m.OptionSimple(APPID, "projectname")))) - list := []string{} - m.Travel(func(_ *ice.Context, s *ice.Context, key string, cmd *ice.Command) { - if h, ok := cmd.Actions[PAGES]; ok { - prefix := strings.ReplaceAll(s.Prefix(), nfs.PT, "-") - file := strings.TrimPrefix(m.Resource(kit.Select(key+".js", h.Name)), nfs.REQUIRE) - list = append(list, path.Join(PAGES, prefix, kit.TrimExt(path.Base(file), nfs.JS))) - kit.For([]string{WXML, WXSS, nfs.JS}, func(ext string) { - file = kit.ExtChange(file, ext) - m.Cmd(nfs.COPY, path.Join(p, PAGES, prefix, path.Base(file)), file) - }) - } - }) - app := kit.UnMarshal(m.Cmdx(nfs.CAT, p+APP_JSON)) - kit.Value(app, PAGES, kit.AddUniq(kit.Simple(kit.Value(app, PAGES)), list...)) - m.Cmd(nfs.SAVE, p+APP_JSON, kit.Formats(app)) - IdeCli(m.Sleep3s(), cli.OPEN, "--project", kit.Path(mdb.Config(m, PROJECT, p))) - m.ProcessInner() + IdeCli(m.Sleep3s(), cli.OPEN, "--project", kit.Path(mdb.Config(m, PROJECT, p))).ProcessInner() }}, aaa.LOGIN: {Help: "登录", Hand: func(m *ice.Message, arg ...string) { p := nfs.TempName(m) @@ -125,8 +141,11 @@ func init() { }}, cli.MAKE: {Help: "构建", Hand: func(m *ice.Message, arg ...string) { kit.If(m.Option(mdb.HASH), func(p string) { mdb.Config(m, CURRENT, p) }) - msg := m.Cmd("", kit.Select(mdb.Config(m, CURRENT), arg, 0)) - m.Options(msg.AppendSimple()).Cmd("", AUTO_PREVIEW) + m.Options(m.Cmd("", kit.Select(mdb.Config(m, CURRENT), arg, 0)).AppendSimple()) + kit.If(m.Option(cli.PWD), func(p string) { + kit.If(p == kit.Path(ice.USR_VOLCANOS+PUBLISH_CLIENT_MP), func() { _ide_autogen_utils(m); _ide_autogen_pages(m) }) + }) + m.Cmd("", AUTO_PREVIEW) }}, AUTO_PREVIEW: {Help: "预览", Hand: func(m *ice.Message, arg ...string) { kit.If(m.Option(mdb.HASH), func(p string) { mdb.Config(m, CURRENT, p) }) diff --git a/misc/wx/scan.go b/misc/wx/scan.go index 84526009..50de7f5d 100644 --- a/misc/wx/scan.go +++ b/misc/wx/scan.go @@ -71,7 +71,6 @@ func init() { m.Echo(msg.Result()) } }}, - PAGES: {Name: "scan.js"}, }, mdb.ExportHashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,name,text,icons,space,index,args,type,image,link")), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { m.Cmdy(ACCESS).PushAction("").Option(ice.MSG_ACTION, "") diff --git a/misc/wx/scan.js b/misc/wx/scan.js index fbe773e4..649ee970 100644 --- a/misc/wx/scan.js +++ b/misc/wx/scan.js @@ -124,4 +124,3 @@ Volcanos(chat.ONACTION, {list: ["刷新", "扫码", "清屏"], }, }) Volcanos._init() - diff --git a/misc/wx/scan.wxml b/misc/wx/scan.wxml index 408f7210..8813c7f9 100644 --- a/misc/wx/scan.wxml +++ b/misc/wx/scan.wxml @@ -42,4 +42,3 @@ - diff --git a/render.go b/render.go index f067f3f0..8ed6e1b0 100644 --- a/render.go +++ b/render.go @@ -149,7 +149,8 @@ func (m *Message) PushAction(arg ...Any) *Message { if len(m.value(MSG_APPEND)) == 0 { return m } - return m.Set(MSG_APPEND, ACTION).Table(func(value Maps) { m.PushButton(arg...) }) + m.Set(MSG_APPEND, ACTION) + return m.Table(func(value Maps) { m.PushButton(arg...) }) } func (m *Message) PushButton(arg ...Any) *Message { if !m.IsCliUA() {