1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2022-02-20 22:59:45 +08:00
parent 7a65f0b4ef
commit 81bc8309a9
15 changed files with 116 additions and 41 deletions

View File

@ -152,3 +152,21 @@ func init() {
}},
}})
}
type buffer struct {
m *ice.Message
n string
}
func (b *buffer) Write(buf []byte) (int, error) {
if b.m.IsCliUA() {
print(string(buf))
} else {
b.m.PushNoticeGrow(string(buf))
}
return len(buf), nil
}
func (b *buffer) Close() error { return nil }
func PushStream(m *ice.Message) {
m.Option(CMD_OUTPUT, &buffer{m: m, n: m.Option(ice.MSG_DAEMON)})
}

View File

@ -9,7 +9,6 @@ import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/tcp"
kit "shylinux.com/x/toolkits"
)
@ -112,25 +111,6 @@ func RenderDownload(msg *ice.Message, arg ...interface{}) {
Render(msg, ice.RENDER_DOWNLOAD, arg...)
}
type Buffer struct {
m *ice.Message
n string
}
func (b *Buffer) Write(buf []byte) (int, error) {
if b.m.IsCliUA() {
print(string(buf))
} else {
b.m.PushNoticeGrow(string(buf))
}
return len(buf), nil
}
func (b *Buffer) Close() error { return nil }
func PushStream(m *ice.Message) {
m.Option(cli.CMD_OUTPUT, &Buffer{m: m, n: m.Option(ice.MSG_DAEMON)})
}
func Format(tag string, arg ...interface{}) string {
return kit.Format("<%s>%s</%s>", tag, strings.Join(kit.Simple(arg), ""), tag)
}

View File

@ -54,7 +54,7 @@ func _binpack_can(m *ice.Message, f *os.File, dir string) {
for _, k := range []string{ice.FAVICON, ice.PROTO_JS, ice.FRAME_JS} {
fmt.Fprintln(f, _binpack_file(m, path.Join(dir, k), ice.PS+k))
}
for _, k := range []string{LIB, PAGE, PANEL, PLUGIN} {
for _, k := range []string{LIB, PAGE, PANEL, PLUGIN, "publish/client/nodejs/"} {
m.Cmd(nfs.DIR, k).Sort(nfs.PATH).Tables(func(value map[string]string) {
fmt.Fprintln(f, _binpack_file(m, path.Join(dir, value[nfs.PATH]), ice.PS+value[nfs.PATH]))
})
@ -72,6 +72,9 @@ func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
BINPACK: {Name: "binpack path auto create remove export", Help: "打包", Action: map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
if kit.FileExists(path.Join(ice.USR_VOLCANOS, ice.PROTO_JS)) {
m.Cmd(BINPACK, mdb.REMOVE)
}
web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
if len(ice.Info.Pack) == 0 {
return false

View File

@ -54,7 +54,7 @@ func init() {
}},
INSTALL: {Name: "compile", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
if strings.Contains(m.Cmdx(cli.RUNTIME, kit.Keys(tcp.HOST, cli.OSID)), cli.ALPINE) {
web.PushStream(m)
cli.PushStream(m)
m.Cmd(cli.SYSTEM, "apk", "add", GIT, GO)
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
return
@ -81,6 +81,8 @@ func init() {
_autogen_version(m.Spawn())
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
cli.PushStream(m)
// 执行编译
main, file, goos, arch := _compile_target(m, arg...)
m.Optionv(cli.CMD_ENV, kit.Simple(m.Configv(cli.ENV), cli.HOME, kit.Env(cli.HOME), cli.PATH, kit.Env(cli.PATH), cli.GOOS, goos, cli.GOARCH, arch))

View File

@ -192,7 +192,7 @@ func init() {
}},
}, Configs: map[string]*ice.Config{
INNER: {Name: "inner", Help: "源代码", Value: kit.Data(
EXEC, kit.Dict("js", []string{"node"}, "py", []string{"python"}),
EXEC, kit.Dict("py", []string{"python"}),
PLUG, kit.Dict(
"S", kit.Dict(PREFIX, kit.Dict("//", COMMENT)),
"s", kit.Dict(PREFIX, kit.Dict("//", COMMENT), KEYWORD, kit.Dict("TEXT", KEYWORD, "RET", KEYWORD)),

View File

@ -52,7 +52,7 @@ func _install_build(m *ice.Message, arg ...string) string {
pp := kit.Path(path.Join(p, "_install"))
// 推流
web.PushStream(m)
cli.PushStream(m)
defer m.ProcessHold()
// 配置
@ -177,6 +177,19 @@ func init() {
}})
}
func InstallSoftware(m *ice.Message, bin string, list interface{}) (ok bool) {
if cli.SystemFind(m, bin) != "" {
return true
}
kit.Fetch(list, func(index int, value map[string]interface{}) {
if strings.Contains(m.Cmdx(cli.RUNTIME, kit.Keys(tcp.HOST, cli.OSID)), kit.Format(value[cli.OSID])) {
cli.PushStream(m)
m.Cmd(cli.SYSTEM, value[ice.CMD])
ok = true
}
})
return ok
}
func InstallAction(args ...interface{}) map[string]*ice.Action {
return ice.SelectAction(map[string]*ice.Action{ice.CTX_INIT: mdb.AutoConfig(args...),
web.DOWNLOAD: {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {

View File

@ -12,6 +12,22 @@ import (
kit "shylinux.com/x/toolkits"
)
func _js_main_script(m *ice.Message, arg ...string) (res []string) {
if res = append(res, kit.Format(`global.plugin = "%s"`, kit.Path(arg[2], arg[1]))); len(ice.Info.Pack) == 0 {
res = append(res, kit.Format(`require("%s")`, kit.Path("usr/volcanos/proto.js")))
} else {
for _, file := range []string{"proto.js", "frame.js", "lib/base.js", "lib/core.js", "lib/misc.js", "lib/page.js", "publish/client/nodejs/proto.js"} {
res = append(res, `_can_name = "./`+file+`"`)
res = append(res, string(ice.Info.Pack[ice.PS+file]))
}
}
if b, ok := ice.Info.Pack[path.Join(arg[2], arg[1])]; ok && !kit.FileExists(kit.Path(arg[2], arg[1])) {
res = append(res, `_can_name = "`+kit.Path(arg[2], arg[1])+`"`)
res = append(res, string(b))
}
return
}
const TS = "ts"
const JS = "js"
const CSS = "css"
@ -45,8 +61,10 @@ func init() {
m.ProcessCommand(kit.Select("can.code.inner.plugin", key), kit.Simple())
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(cli.SYSTEM, NODE, "-e", kit.Format(`global.plugin = "%s", require("%s")`,
kit.Path(arg[2], arg[1]), kit.Path("usr/volcanos/proto.js"))).SetAppend()
if !InstallSoftware(m.Spawn(), NODE, m.Configv(INSTALL)) {
return
}
m.Cmdy(cli.SYSTEM, NODE, "-e", kit.Join(_js_main_script(m, arg...), ice.NL)).SetAppend()
m.Echo(ice.NL)
}},
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
@ -66,7 +84,9 @@ func init() {
NODE: {Name: NODE, Help: "前端", Value: kit.Data(
nfs.SOURCE, "https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz",
)},
JS: {Name: JS, Help: "js", Value: kit.Data(PLUG, kit.Dict(
JS: {Name: JS, Help: "js", Value: kit.Data(INSTALL, kit.List(kit.Dict(
cli.OSID, cli.ALPINE, ice.CMD, kit.List("apk", "add", "nodejs"),
)), PLUG, kit.Dict(
mdb.RENDER, kit.Dict(),
SPLIT, kit.Dict("space", " \t", "operator", "{[(&.,;!|<>)]}"),
PREFIX, kit.Dict("//", COMMENT, "/*", COMMENT, "*", COMMENT), PREPARE, kit.Dict(

View File

@ -13,7 +13,6 @@ import (
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
)
@ -122,7 +121,7 @@ func init() {
list = append(list, text)
})
web.PushStream(m)
cli.PushStream(m)
defer m.ProcessHold()
defer m.ToastSuccess()
defer m.StatusTimeCount()

33
core/code/py.go Normal file
View File

@ -0,0 +1,33 @@
package code
import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb"
kit "shylinux.com/x/toolkits"
)
const PY = "py"
func init() {
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
PY: {Name: "py", Help: "脚本", Value: kit.Data(INSTALL, kit.List(kit.Dict(
cli.OSID, cli.ALPINE, ice.CMD, kit.List("apk", "add", "python2"),
)))},
}, Commands: map[string]*ice.Command{
PY: {Name: "py", Help: "脚本", Action: map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.ENGINE, mdb.CREATE, PY, m.PrefixKey())
}},
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
if !InstallSoftware(m.Spawn(), "python", m.Configv(INSTALL)) {
return
}
m.Cmdy(cli.SYSTEM, "python", kit.Path(arg[2], arg[1]))
m.Echo(ice.NL)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
}})
}

View File

@ -28,6 +28,9 @@ func init() {
m.Cmd(UPGRADE, cli.RESTART)
}
}},
"unpack": {Name: "unpack", Help: "导出文件", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(BINPACK, mdb.EXPORT)
}},
BINPACK: {Name: "binpack", Help: "打包模式", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(nfs.COPY, ice.GO_MOD, path.Join(ice.SRC_RELEASE, ice.GO_MOD))
m.Cmd(nfs.COPY, ice.GO_SUM, path.Join(ice.SRC_RELEASE, ice.GO_SUM))

2
go.mod
View File

@ -4,6 +4,6 @@ go 1.11
require (
shylinux.com/x/go-qrcode v0.0.1
shylinux.com/x/toolkits v0.5.0
shylinux.com/x/toolkits v0.5.1
shylinux.com/x/websocket v0.0.1
)

6
go.sum
View File

@ -1,6 +1,4 @@
shylinux.com/x/go-qrcode v0.0.1 h1:/eOGqMj1qtgs9Ymd12zTUa1gcJZs9S92kj2lb0QzKsE=
shylinux.com/x/go-qrcode v0.0.1/go.mod h1:KAbtU+KwiiABMZ/CJ0zh9PI2AX82Uf9rRYcQ4ODm4po=
shylinux.com/x/toolkits v0.5.0 h1:dUgMiBIrlQWkZoB2vXdf5g/RqsImoh3d5D0Us2++yHQ=
shylinux.com/x/toolkits v0.5.0/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA=
shylinux.com/x/websocket v0.0.1 h1:OBc21DxqsGlQ2+Pz76xqLyDNo1LV+PUUqfWi+1PZPDE=
shylinux.com/x/toolkits v0.5.1 h1:0o3ELWcjA+aJ1eBH2p1Y4EZd1oJdxXxGRP4sxFkMl/g=
shylinux.com/x/toolkits v0.5.1/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA=
shylinux.com/x/websocket v0.0.1/go.mod h1:AaSpMToOxbMULKQytzczeHPuqb708vK1vrAzCxLo/XE=

View File

@ -18,7 +18,7 @@ var Index = &ice.Context{Name: GIT, Help: "代码库", Configs: map[string]*ice.
}, Commands: map[string]*ice.Command{
GIT: {Name: "git path auto install order build download", Help: "代码库", Action: ice.MergeAction(map[string]*ice.Action{
code.INSTALL: {Name: "install", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
web.PushStream(m)
cli.PushStream(m)
defer m.ProcessInner()
m.Cmdy(cli.SYSTEM, "yum", "install", "-y", "git")
}},

View File

@ -9,7 +9,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"
"shylinux.com/x/icebergs/core/code"
kit "shylinux.com/x/toolkits"
)
@ -25,7 +24,7 @@ func _status_tag(m *ice.Message, tags string) string {
}
return "v0.0.1"
}
func _status_tags(m *ice.Message) {
func _status_tags(m *ice.Message, repos string) {
vs := map[string]string{}
m.Cmd(STATUS).Table(func(index int, value map[string]string, head []string) {
if value[mdb.TYPE] == "##" {
@ -41,6 +40,9 @@ func _status_tags(m *ice.Message) {
toast(cli.BEGIN, count, total)
for k := range vs {
if k != repos && repos != "" {
continue
}
count++
toast(k, count, total)
@ -79,7 +81,8 @@ func _status_tags(m *ice.Message) {
m.Cmd(cli.SYSTEM, cli.MAKE)
}
}
toast(ice.SUCCESS, count, total)
toast(ice.SUCCESS, count, count)
m.PushRefresh()
})
}
func _status_each(m *ice.Message, title string, cmds ...string) {
@ -220,7 +223,7 @@ func init() {
m.ProcessHold()
}},
MAKE: {Name: "make", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
web.PushStream(m)
cli.PushStream(m)
m.Cmdy(cli.SYSTEM, MAKE)
m.ToastSuccess()
m.ProcessHold()
@ -236,7 +239,7 @@ func init() {
_repos_cmd(m, m.Option(REPOS), PUSH, "--tags")
}},
TAGS: {Name: "tags", Help: "标签", Hand: func(m *ice.Message, arg ...string) {
_status_tags(m)
_status_tags(m, kit.Select("", arg, 0))
m.ProcessHold()
}},
STASH: {Name: "stash", Help: "缓存", Hand: func(m *ice.Message, arg ...string) {
@ -285,7 +288,7 @@ func init() {
m.Option(cli.CMD_DIR, _repos_path(arg[0]))
m.Echo(m.Cmdx(cli.SYSTEM, GIT, DIFF))
m.Action(COMMIT)
m.Action(COMMIT, TAGS)
files, adds, dels := _status_stat(m, 0, 0, 0)
m.Status("files", files, "adds", adds, "dels", dels)

View File

@ -166,6 +166,9 @@ func (m *Message) PushNoticeGrow(arg ...interface{}) {
func (m *Message) PushNoticeToast(arg ...interface{}) {
m.PushNotice(kit.List("toast", arg)...)
}
func (m *Message) PushRefresh(arg ...interface{}) {
m.PushNotice(kit.List("refresh")...)
}
func (m *Message) Toast3s(text string, arg ...interface{}) {
m.Toast(text, kit.List(kit.Select("", arg, 0), kit.Select("3s", arg, 1))...)
}