1
0
forked from x/icebergs

add wx.ide autogen

This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-12-09 18:03:47 +08:00
parent ee1ef94a72
commit e5e6f37e3e
12 changed files with 80 additions and 53 deletions

View File

@ -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]) })
})
}

View File

@ -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(""))
}},
})
}

View File

@ -104,6 +104,7 @@ const (
UPLOAD = "upload"
DOWNLOAD = "download"
PREVIEW = "preview"
PAGES = "pages"
IMAGE = "image"
VIDEO = "video"

View File

@ -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)
}
}

View File

@ -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() {

View File

@ -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
}
}

View File

@ -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...)

View File

@ -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 IDE = "ide"
func init() {
const (
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() {
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) })

View File

@ -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, "")

View File

@ -124,4 +124,3 @@ Volcanos(chat.ONACTION, {list: ["刷新", "扫码", "清屏"],
},
})
Volcanos._init()

View File

@ -42,4 +42,3 @@
</view>
</view>
</view>

View File

@ -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() {