forked from x/icebergs
opt module
This commit is contained in:
parent
7c14a9735a
commit
be829ce488
@ -145,6 +145,9 @@ func _system_find(m Message, bin string, dir ...string) string {
|
||||
return kit.Path(p, bin) + ".exe"
|
||||
}
|
||||
}
|
||||
if nfs.ExistsFile(m, bin) {
|
||||
return kit.Path(bin)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -143,6 +143,8 @@ const (
|
||||
TYPE_CAT = "cat"
|
||||
TYPE_DIR = "dir"
|
||||
TYPE_BOTH = "both"
|
||||
|
||||
SRC = "src/"
|
||||
)
|
||||
const (
|
||||
DIR_ROOT = "dir_root"
|
||||
|
@ -193,7 +193,7 @@ var _main_template = `<!DOCTYPE html>
|
||||
<meta charset="utf-8"><title>volcanos</title>
|
||||
<link href="/index.css{{.version}}" rel="stylesheet">
|
||||
<link href="/page/cache.css{{.version}}" rel="stylesheet">
|
||||
<link href="/page/favicon.ico" rel="shortcut icon" type="image/ico">
|
||||
<link href="/favicon.ico" rel="shortcut icon" type="image/ico">
|
||||
</head>
|
||||
<body>
|
||||
<script>_version = "{{.version}}"</script>
|
||||
@ -209,7 +209,7 @@ var _cmd_template = `<!DOCTYPE html>
|
||||
<meta charset="utf-8"><title>volcanos</title>
|
||||
<link href="/index.css{{.version}}" rel="stylesheet">
|
||||
<link href="/page/cache.css{{.version}}" rel="stylesheet">
|
||||
<link href="/page/favicon.ico" rel="shortcut icon" type="image/ico">
|
||||
<link href="/favicon.ico" rel="shortcut icon" type="image/ico">
|
||||
</head>
|
||||
<body>
|
||||
<script>_version = "{{.version}}"</script>
|
||||
|
@ -287,7 +287,7 @@ func init() {
|
||||
PP(ice.REQUIRE, ice.USR): {Name: "/require/usr/", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_local(m, ice.USR, path.Join(arg...))
|
||||
}},
|
||||
PP(ice.REQUIRE, ice.SRC): {Name: "/require/src/", Help: "源代码", Hand: func(m *ice.Message, arg ...string) {
|
||||
PP(ice.REQUIRE, ice.SRC): {Name: "/require/src/", Help: "源代码", Actions: ice.MergeActions(ice.Actions{}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_local(m, ice.SRC, path.Join(arg...))
|
||||
}},
|
||||
PP(ice.HELP): {Name: "/help/", Help: "帮助", Actions: ice.MergeActions(ctx.CmdAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
|
14
conf.go
14
conf.go
@ -92,13 +92,13 @@ const ( // DIR
|
||||
INDEX_JS = "index.js"
|
||||
INDEX_SH = "index.sh"
|
||||
|
||||
PAGE_FAVICON_ICO = "page/favicon.ico"
|
||||
PLUGIN_INPUT = "/plugin/input/"
|
||||
PLUGIN_STORY = "/plugin/story/"
|
||||
PLUGIN_LOCAL = "/plugin/local/"
|
||||
NODE_MODULES = "node_modules/"
|
||||
ISH_PLUGED = ".ish/pluged/"
|
||||
CAN_PLUGIN = "can._plugin"
|
||||
FAVICON_ICO = "/favicon.ico"
|
||||
PLUGIN_INPUT = "/plugin/input/"
|
||||
PLUGIN_STORY = "/plugin/story/"
|
||||
PLUGIN_LOCAL = "/plugin/local/"
|
||||
NODE_MODULES = "node_modules/"
|
||||
ISH_PLUGED = ".ish/pluged/"
|
||||
CAN_PLUGIN = "can._plugin"
|
||||
|
||||
USR_VOLCANOS = "usr/volcanos/"
|
||||
USR_LEARNING = "usr/learning/"
|
||||
|
@ -83,7 +83,7 @@ var _div_template = `<!DOCTYPE html>
|
||||
<title>volcanos</title>
|
||||
<link rel="stylesheet" type="text/css" href="/index.css">
|
||||
<link rel="stylesheet" type="text/css" href="/page/cache.css">
|
||||
<link rel="shortcut icon" type="image/ico" href="/page/favicon.ico">
|
||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
|
||||
<style type="text/css">%s</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -99,7 +99,7 @@ var _div_template2 = `<!DOCTYPE html>
|
||||
<title>volcanos</title>
|
||||
<link rel="stylesheet" type="text/css" href="/index.css">
|
||||
<link rel="stylesheet" type="text/css" href="/page/cache.css">
|
||||
<link rel="shortcut icon" type="image/ico" href="/page/favicon.ico">
|
||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/proto.js"></script>
|
||||
|
@ -226,7 +226,7 @@ var _website_template = `<!DOCTYPE html>
|
||||
<title>volcanos</title>
|
||||
<link rel="stylesheet" type="text/css" href="/index.css">
|
||||
<link rel="stylesheet" type="text/css" href="/page/cache.css">
|
||||
<link rel="shortcut icon" type="image/ico" href="/page/favicon.ico">
|
||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/proto.js"></script>
|
||||
@ -241,7 +241,7 @@ var _website_template2 = `<!DOCTYPE html>
|
||||
<title>volcanos</title>
|
||||
<link rel="stylesheet" type="text/css" href="/index.css">
|
||||
<link rel="stylesheet" type="text/css" href="/page/cache.css">
|
||||
<link rel="shortcut icon" type="image/ico" href="/page/favicon.ico">
|
||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/proto.js"></script>
|
||||
|
@ -136,6 +136,10 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, ice.GO_MOD)
|
||||
m.Cmdy(nfs.DIR, ice.GO_SUM)
|
||||
}},
|
||||
WEBPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(WEBPACK, mdb.CREATE)
|
||||
m.Cmdy(nfs.DIR, ice.USR_PUBLISH, kit.Dict(nfs.DIR_REG, "can.*"))
|
||||
}},
|
||||
BINPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Cmd(BINPACK, mdb.CREATE); nfs.ExistsFile(m, ice.USR_RELEASE) && m.Option(ice.MSG_USERPOD) == "" {
|
||||
const (
|
||||
|
@ -16,6 +16,10 @@ import (
|
||||
)
|
||||
|
||||
func _binpack_file(m *ice.Message, w io.Writer, arg ...string) {
|
||||
if strings.HasPrefix(arg[0], "usr/volcanos/page/") && !strings.Contains(arg[0], "/cache.") {
|
||||
fmt.Fprintf(w, " \"%s\": \"%s\",\n", kit.Select(arg[0], arg, 1), "")
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(arg[0], "usr/volcanos/publish/") && !strings.HasSuffix(arg[0], "/proto.js") {
|
||||
return
|
||||
}
|
||||
|
@ -10,7 +10,14 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _c_show(m *ice.Message, arg ...string) { TagsList(m) }
|
||||
func _c_show(m *ice.Message, arg ...string) {
|
||||
target := path.Join(ice.BIN, kit.TrimExt(arg[1], arg[0]))
|
||||
if msg := m.Cmd(cli.SYSTEM, "gcc", "-o", target, path.Join(arg[2], arg[1])); cli.IsSuccess(msg) {
|
||||
_xterm_show(m, nfs.SH, target, path.Join(arg[2], arg[1]))
|
||||
} else {
|
||||
_vimer_make(m, arg[2], msg)
|
||||
}
|
||||
}
|
||||
func _c_exec(m *ice.Message, arg ...string) {
|
||||
target := path.Join(ice.BIN, kit.TrimExt(arg[1], arg[0]))
|
||||
if msg := m.Cmd(cli.SYSTEM, "gcc", "-o", target, path.Join(arg[2], arg[1])); cli.IsSuccess(msg) {
|
||||
@ -34,18 +41,14 @@ const C = "c"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
MAN: {Name: MAN, Help: "系统手册", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(cli.SYSTEM, cli.MAN, kit.TrimExt(arg[1], arg[0])) }},
|
||||
}, PlugAction())},
|
||||
H: {Name: "h path auto", Help: "系统编程", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _c_show(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction())},
|
||||
C: {Name: "c path auto", Help: "系统编程", Actions: ice.MergeActions(ice.Actions{
|
||||
C: {Name: "c path auto", Help: "编程", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _c_show(m, arg...) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _c_exec(m, arg...) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_c_template) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { kit.If(arg[0] == C, func() { m.Echo(_c_template) }) }},
|
||||
}, PlugAction())},
|
||||
H: {Name: "h path auto", Help: "编程", Actions: ice.MergeActions(ice.Actions{
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -1,27 +1,30 @@
|
||||
code.go
|
||||
code.shy
|
||||
|
||||
install.go
|
||||
upgrade.go
|
||||
autogen.go
|
||||
webpack.go
|
||||
binpack.go
|
||||
autogen.go
|
||||
compile.go
|
||||
publish.go
|
||||
|
||||
favor.go
|
||||
xterm.go
|
||||
xterm.shy
|
||||
inner.go
|
||||
xterm.go
|
||||
vimer.go
|
||||
inner.go
|
||||
favor.go
|
||||
oauth.go
|
||||
pprof.go
|
||||
bench.go
|
||||
oauth.go
|
||||
case.go
|
||||
|
||||
c.go
|
||||
sh.go
|
||||
py.go
|
||||
shy.go
|
||||
zml.go
|
||||
go.go
|
||||
sh.go
|
||||
shy.go
|
||||
py.go
|
||||
js.go
|
||||
css.go
|
||||
html.go
|
||||
zml.go
|
||||
|
@ -39,7 +39,7 @@ const COMPILE = "compile"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
COMPILE: {Name: "compile arch=amd64,386,arm,arm64,mipsle os=linux,darwin,windows src=src/main.go@key run binpack", Help: "编译", Actions: ice.MergeActions(ice.Actions{
|
||||
COMPILE: {Name: "compile arch=amd64,386,arm,arm64,mipsle os=linux,darwin,windows src=src/main.go@key run binpack webpack", Help: "编译", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.Fetch([]string{"curl", "make", "gcc", "vim", "tmux"}, func(cmd string) { cli.IsSystem(m, cmd) })
|
||||
if cli.IsAlpine(m, "git"); !cli.IsAlpine(m, "go", "go git") {
|
||||
@ -50,6 +50,7 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, kit.ExtReg(GO)))
|
||||
}},
|
||||
BINPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, BINPACK) }},
|
||||
WEBPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, WEBPACK) }},
|
||||
}, 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) {
|
||||
_autogen_version(m.Spawn())
|
||||
main, file, goos, arch := _compile_target(m, arg...)
|
||||
|
@ -20,8 +20,7 @@ func _css_stat(m *ice.Message, zone string, stats map[string]int) {
|
||||
m.Copy(msg)
|
||||
}
|
||||
func _css_show(m *ice.Message, arg ...string) {
|
||||
zone := ""
|
||||
stats_key, stats_value := map[string]int{}, map[string]int{}
|
||||
zone, stats_key, stats_value := "", map[string]int{}, map[string]int{}
|
||||
m.Cmd(nfs.CAT, path.Join(arg[2], arg[1]), func(line string) {
|
||||
if line = strings.TrimSpace(line); line == "" || strings.HasPrefix(line, "//") || strings.HasPrefix(line, "/*") {
|
||||
return
|
||||
@ -48,7 +47,7 @@ func _css_show(m *ice.Message, arg ...string) {
|
||||
default:
|
||||
list := kit.Split(line, "", ":;")
|
||||
m.Push(mdb.NAME, list[0])
|
||||
m.Push(mdb.VALUE, list[1])
|
||||
m.Push(mdb.VALUE, list[2])
|
||||
m.Push(mdb.ZONE, zone)
|
||||
}
|
||||
})
|
||||
@ -70,7 +69,25 @@ 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) { _css_exec(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())
|
||||
}
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.Format(_css_template, kit.Select("plugin", ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO)))))
|
||||
}},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
||||
var _css_template = `
|
||||
body fieldset.%s div.output {
|
||||
background-color:red;
|
||||
}
|
||||
`
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -55,16 +56,6 @@ func _go_complete(m *ice.Message, arg ...string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func _go_exec(m *ice.Message, arg ...string) {
|
||||
if cmd := ctx.GetFileCmd(path.Join(arg[2], arg[1])); cmd != "" {
|
||||
ctx.ProcessCommand(m, cmd, kit.Simple())
|
||||
}
|
||||
}
|
||||
func _go_show(m *ice.Message, arg ...string) {
|
||||
// TagsList(m, "gotags", path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)))
|
||||
// TagsList(m, "gotags", path.Join(arg[2], arg[1]))
|
||||
_go_exec(m, arg...)
|
||||
}
|
||||
func _mod_show(m *ice.Message, file string) {
|
||||
const (
|
||||
MODULE = "module"
|
||||
@ -101,19 +92,45 @@ func _sum_show(m *ice.Message, file string) {
|
||||
}).StatusTimeCount()
|
||||
}
|
||||
|
||||
const GODOC = "godoc"
|
||||
const SUM = "sum"
|
||||
const MOD = "mod"
|
||||
const GODOC = "godoc"
|
||||
const GO = "go"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SUM: {Help: "版本", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _sum_show(m, path.Join(arg[2], arg[1])) }},
|
||||
GO: {Name: "go path auto", Help: "后端编程", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(NAVIGATE, mdb.CREATE, GODOC, m.PrefixKey()) }},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cmds, text := "ice.bin source stdio", ctx.GetFileCmd(path.Join(arg[2], arg[1]))
|
||||
if text != "" {
|
||||
ls := strings.Split(text, ice.PT)
|
||||
text = "~" + kit.Join(kit.Slice(ls, 0, -1), ice.PT) + ice.NL + kit.Slice(ls, -1)[0]
|
||||
} else {
|
||||
text = "cli.system go run " + path.Join(arg[2], arg[1])
|
||||
}
|
||||
_xterm_show(m, cmds, text)
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if cmd := ctx.GetFileCmd(path.Join(arg[2], arg[1])); cmd != "" {
|
||||
ctx.ProcessCommand(m, cmd, kit.Simple())
|
||||
} else {
|
||||
cmds := []string{GO, ice.RUN, path.Join(arg[2], arg[1])}
|
||||
m.Cmdy(cli.SYSTEM, cmds).StatusTime(ssh.SHELL, strings.Join(cmds, ice.SP))
|
||||
}
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_go_template, path.Base(path.Dir(path.Join(arg[2], arg[1]))))
|
||||
}},
|
||||
COMPLETE: {Hand: func(m *ice.Message, arg ...string) { _go_complete(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, GODOC, "gotags", "-f", nfs.TAGS, "-R", nfs.PWD) }},
|
||||
}, PlugAction())},
|
||||
MOD: {Help: "模块", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _mod_show(m, path.Join(arg[2], arg[1])) }},
|
||||
}, PlugAction())},
|
||||
SUM: {Help: "版本", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _sum_show(m, path.Join(arg[2], arg[1])) }},
|
||||
}, PlugAction())},
|
||||
GODOC: {Help: "文档", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
arg[1] = strings.Replace(arg[1], "kit.", "shylinux.com/x/toolkits.", 1)
|
||||
@ -121,25 +138,6 @@ func init() {
|
||||
m.Cmdy(cli.SYSTEM, GO, "doc", kit.TrimExt(arg[1], GODOC), kit.Dict(cli.CMD_DIR, arg[2]))
|
||||
}},
|
||||
}, PlugAction())},
|
||||
GO: {Name: "go path auto", Help: "后端编程", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(NAVIGATE, mdb.CREATE, GODOC, m.PrefixKey()) }},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cmds, text := "ice.bin source stdio", ctx.GetFileCmd(path.Join(arg[2], arg[1]))
|
||||
ls := strings.Split(text, ice.PT)
|
||||
text = "~" + kit.Join(kit.Slice(ls, 0, -1), ice.PT) + ice.NL + kit.Slice(ls, -1)[0]
|
||||
_xterm_show(m, cmds, text)
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_go_exec(m, arg...)
|
||||
}},
|
||||
COMPLETE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) == 0 || arg[0] != mdb.FOREACH, func() { _go_complete(m, arg...) })
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(arg[0] == GO, func() { m.Echo(_go_template, path.Base(path.Dir(path.Join(arg[2], arg[1])))) })
|
||||
}},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, GODOC, "gotags", "-f", nfs.TAGS, "-R", nfs.PWD) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -4,18 +4,36 @@ import (
|
||||
"path"
|
||||
|
||||
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 HTML = "html"
|
||||
|
||||
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) {
|
||||
p := kit.MergeURL(path.Join("/require/", arg[2], arg[1]), "_", kit.Hashs("uniq"))
|
||||
m.Push(mdb.LINK, p).Echo(`<iframe src="%s"></iframe>`, p).StatusTime(web.LINK, p)
|
||||
m.EchoIFrame(kit.MergeURL(path.Join("/require/", arg[2], arg[1]), "_v", kit.Hashs("uniq")))
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoIFrame(kit.MergeURL(path.Join("/require/", arg[2], arg[1]), "_v", kit.Hashs("uniq")))
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.Renders(_html_template, ice.Maps{ice.LIST: kit.Format(kit.List(kit.Dict(ctx.INDEX, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO)))))})).RenderResult()
|
||||
}},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
||||
var _html_template = `<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8"><title>volcanos</title>
|
||||
<link href="/publish/can.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/publish/can.js"></script>
|
||||
<script>Volcanos({{.list}})</script>
|
||||
</body>
|
||||
`
|
||||
|
113
core/code/js.go
113
core/code/js.go
@ -1,100 +1,16 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"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"
|
||||
)
|
||||
|
||||
func _js_main_script(m *ice.Message, arg ...string) (res []string) {
|
||||
res = append(res, kit.Format(`global.plugin = "%s"`, kit.Path(arg[2], arg[1])))
|
||||
if _, e := nfs.DiskFile.StatFile("usr/volcanos/proto.js"); e == nil {
|
||||
res = append(res, kit.Format(`require("%s")`, kit.Path("usr/volcanos/proto.js")))
|
||||
res = append(res, kit.Format(`require("%s")`, kit.Path("usr/volcanos/publish/client/nodejs/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 = "`+kit.Path(ice.USR_VOLCANOS, file)+`"`)
|
||||
if b, e := nfs.ReadFile(m, path.Join(ice.USR_VOLCANOS, file)); e == nil {
|
||||
res = append(res, string(b))
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, e := nfs.DiskFile.StatFile(path.Join(arg[2], arg[1])); os.IsNotExist(e) {
|
||||
res = append(res, `_can_name = "`+kit.Path(arg[2], arg[1])+`"`)
|
||||
if b, e := nfs.ReadFile(m, path.Join(arg[2], arg[1])); e == nil {
|
||||
res = append(res, string(b))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func _js_parse(m *ice.Message, arg ...string) {
|
||||
|
||||
}
|
||||
func _js_show(m *ice.Message, arg ...string) {
|
||||
kind := ""
|
||||
m.Cmd(nfs.CAT, path.Join(arg[2], arg[1]), func(text string, index int) {
|
||||
ls := kit.Split(text, "\t ", ":,()")
|
||||
if strings.HasPrefix(text, "Volcanos(") {
|
||||
if kind = ls[2]; strings.Contains(text, "_init: ") {
|
||||
m.Push("line", index+1)
|
||||
m.Push("kind", kind)
|
||||
m.Push("name", "_init")
|
||||
m.Push("type", "function")
|
||||
}
|
||||
return
|
||||
}
|
||||
indent := 0
|
||||
for _, c := range text {
|
||||
if c == '\t' {
|
||||
indent++
|
||||
} else if c == ' ' {
|
||||
indent++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(ls) > 2 && ls[1] == ":" {
|
||||
if indent > 1 {
|
||||
return
|
||||
}
|
||||
m.Push("line", index+1)
|
||||
m.Push("kind", kind)
|
||||
m.Push("name", ls[0])
|
||||
m.Push("type", ls[2])
|
||||
}
|
||||
})
|
||||
m.StatusTimeCount()
|
||||
}
|
||||
func _js_exec(m *ice.Message, arg ...string) {
|
||||
if arg[2] == ice.USR_VOLCANOS {
|
||||
if strings.HasPrefix(arg[1], "plugin/local/") {
|
||||
key := "web." + strings.Replace(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), ".js"), ice.PS, ice.PT, -1)
|
||||
ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, key), kit.Simple())
|
||||
} else {
|
||||
m.EchoIFrame(web.MergeURL2(m, "/chat/cmd/web.code.vimer", "debug", "true"))
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.DisplayBase(m, path.Join("/require", path.Join(arg[2], arg[1])))
|
||||
key := ctx.GetFileCmd(kit.Replace(path.Join(arg[2], arg[1]), ".js", ".go"))
|
||||
ctx.ProcessCommand(m, kit.Select("can._plugin", key), kit.Simple())
|
||||
return
|
||||
args := kit.Simple("node", "-e", kit.Join(_js_main_script(m, arg...), ice.NL))
|
||||
m.Cmdy(cli.SYSTEM, args).StatusTime(ctx.ARGS, kit.Join(append([]string{ice.ICE_BIN, m.PrefixKey(), m.ActionKey()}, arg...), ice.SP))
|
||||
}
|
||||
|
||||
const JS = "js"
|
||||
const HTML = "html"
|
||||
const JSON = "json"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
@ -104,31 +20,16 @@ func init() {
|
||||
_xterm_show(m, cmds, text)
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_js_exec(m, arg...)
|
||||
}},
|
||||
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_js_template) }},
|
||||
COMPLETE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == mdb.FOREACH { // 文件
|
||||
switch m.Option(ctx.ACTION) {
|
||||
case nfs.SCRIPT:
|
||||
m.Push(nfs.PATH, strings.Replace(arg[1], ice.PT+kit.Ext(arg[1]), ice.PT+JS, -1))
|
||||
m.Option(nfs.DIR_REG, kit.FileReg(nfs.SH, nfs.PY, nfs.SHY, nfs.JS))
|
||||
nfs.DirDeepAll(m, ice.SRC, nfs.PWD, nil).Cut(nfs.PATH)
|
||||
}
|
||||
|
||||
} else if strings.HasSuffix(m.Option(mdb.TEXT), ice.PT) { // 方法
|
||||
key := kit.Slice(kit.Split(m.Option(mdb.TEXT), "\t ."), -1)[0]
|
||||
switch key {
|
||||
case "can":
|
||||
m.Cmdy("web.code.vim.tags").Cut(mdb.ZONE)
|
||||
case "msg":
|
||||
m.Cmdy("web.code.vim.tags", key).Cut("name,text")
|
||||
default:
|
||||
m.Cmdy("web.code.vim.tags", key).Cut("name,text")
|
||||
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 {
|
||||
ctx.DisplayBase(m, 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())
|
||||
}
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_js_template) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -9,11 +9,11 @@ import (
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
)
|
||||
|
||||
func _py_exec(m *ice.Message, arg ...string) {
|
||||
func _py_exec(m *ice.Message, p string) {
|
||||
const PYTHON2 = "python2"
|
||||
if _, e := nfs.DiskFile.StatFile(path.Join(arg[2], arg[1])); e == nil {
|
||||
m.Cmdy(cli.SYSTEM, PYTHON2, path.Join(arg[2], arg[1]))
|
||||
} else if b, e := nfs.ReadFile(m, path.Join(arg[2], arg[1])); e == nil {
|
||||
if _, e := nfs.DiskFile.StatFile(p); e == nil {
|
||||
m.Cmdy(cli.SYSTEM, PYTHON2, p)
|
||||
} else if b, e := nfs.ReadFile(m, p); e == nil {
|
||||
m.Cmdy(cli.SYSTEM, PYTHON2, "-c", string(b))
|
||||
}
|
||||
m.StatusTime()
|
||||
@ -33,8 +33,10 @@ func init() {
|
||||
cmds, text := "python -i "+path.Join(arg[2], arg[1]), ""
|
||||
_xterm_show(m, cmds, text)
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _py_exec(m, arg...) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(`print "hello world"`) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_py_exec(m, path.Join(arg[2], arg[1]))
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(`print "hello world"`) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _sh_cmds(m *ice.Message, arg ...string) (string, string) {
|
||||
cmds, text := kit.Select(SH, m.Config(ssh.SHELL)), kit.Format(strings.TrimSpace(_sh_cmd_template), m.Option(ice.MSG_USERHOST), m.Option(ice.MSG_USERPOD), path.Join(arg[2], arg[1]))
|
||||
if head := kit.Select("", strings.Split(m.Cmdx(nfs.CAT, path.Join(arg[2], arg[1])), ice.NL), 0); strings.HasPrefix(head, "#!") {
|
||||
func _sh_cmds(m *ice.Message, p string) (string, string) {
|
||||
cmds, text := kit.Select(SH, m.Config(ssh.SHELL)), kit.Format(strings.TrimSpace(_sh_cmd_template), m.Option(ice.MSG_USERHOST), m.Option(ice.MSG_USERPOD), p)
|
||||
if head := kit.Select("", strings.Split(m.Cmdx(nfs.CAT, p), ice.NL), 0); strings.HasPrefix(head, "#!") {
|
||||
cmds = strings.TrimSpace(strings.TrimPrefix(head, "#!"))
|
||||
}
|
||||
return cmds, text
|
||||
@ -26,11 +26,11 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SH: {Name: "sh path auto", Help: "命令", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cmds, text := _sh_cmds(m, arg...)
|
||||
cmds, text := _sh_cmds(m, path.Join(arg[2], arg[1]))
|
||||
_xterm_show(m, cmds, text, path.Join(arg[2], arg[1]))
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cmds, text := _sh_cmds(m, arg...)
|
||||
cmds, text := _sh_cmds(m, path.Join(arg[2], arg[1]))
|
||||
m.Cmdy(cli.SYSTEM, cmds, "-c", text).Status(ssh.SHELL, strings.ReplaceAll(text, ice.NL, "; "))
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_sh_template) }},
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"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"
|
||||
)
|
||||
@ -15,21 +16,24 @@ const SHY = "shy"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SHY: {Name: "shy path auto", Help: "脚本", Actions: ice.MergeActions(ice.Actions{
|
||||
SHY: {Name: "shy path auto", Help: "笔记", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessCommand(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessCommand(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
// m.Cmdy(ssh.SOURCE, path.Join(arg[2], arg[1]))
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(`chapter "hi"`) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_shy_template, path.Base(path.Dir(path.Join(arg[2], arg[1]))))
|
||||
}},
|
||||
}, PlugAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && kit.Ext(arg[0]) == m.CommandKey() {
|
||||
m.Cmdy(web.WIKI_WORD, path.Join(ice.SRC, strings.TrimPrefix(arg[0], "src/")))
|
||||
m.Cmdy(web.WIKI_WORD, path.Join(ice.SRC, strings.TrimPrefix(arg[0], nfs.SRC)))
|
||||
} else {
|
||||
m.Cmdy(web.WIKI_WORD, arg)
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
var _shy_template = `chapter "%s"`
|
||||
|
@ -61,11 +61,11 @@ func init() {
|
||||
case nfs.SCRIPT:
|
||||
// p := path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE))
|
||||
p := path.Join(m.Option(nfs.FILE))
|
||||
for _, ext := range []string{"sh", "shy", "py", "js"} {
|
||||
for _, ext := range []string{SH, SHY, PY, JS, CSS, HTML} {
|
||||
m.Push(nfs.PATH, kit.ExtChange(p, ext))
|
||||
}
|
||||
m.Option(nfs.DIR_REG, kit.FileReg("(sh|shy|py|js)"))
|
||||
nfs.DirDeepAll(m, "src/", "./", nil, nfs.PATH)
|
||||
m.Option(nfs.DIR_REG, kit.FileReg("(sh|shy|py|js|css|html)"))
|
||||
nfs.DirDeepAll(m, nfs.SRC, "./", nil, nfs.PATH)
|
||||
case web.WEBSITE:
|
||||
m.Cmdy(COMPLETE, mdb.FOREACH, kit.Select("", arg, 1), m.Option(ctx.ACTION))
|
||||
case "extension":
|
||||
|
@ -23,13 +23,13 @@ func _publish(m *ice.Message, file ...string) string {
|
||||
}
|
||||
func _webpack_can(m *ice.Message) {
|
||||
m.Option(nfs.DIR_ROOT, "")
|
||||
m.Cmd(nfs.COPY, _volcanos(m, PAGE_CAN_CSS), _volcanos(m, ice.INDEX_CSS), _volcanos(m, PAGE_CACHE_CSS))
|
||||
m.Cmd(nfs.COPY, _volcanos(m, PAGE_CAN_JS), _volcanos(m, ice.PROTO_JS), _volcanos(m, PAGE_CACHE_JS))
|
||||
m.Cmd(nfs.COPY, USR_PUBLISH_CAN_CSS, _volcanos(m, ice.INDEX_CSS), _volcanos(m, PAGE_CACHE_CSS))
|
||||
m.Cmd(nfs.COPY, USR_PUBLISH_CAN_JS, _volcanos(m, ice.PROTO_JS), _volcanos(m, PAGE_CACHE_JS))
|
||||
m.Cmdy(nfs.DIR, _volcanos(m, PAGE))
|
||||
}
|
||||
func _webpack_css(m *ice.Message, css, js io.Writer, p string) {
|
||||
fmt.Fprintln(css, kit.Format("/* %s */", path.Join(ice.PS, p)))
|
||||
fmt.Fprintln(css, m.Cmdx(nfs.CAT, strings.Replace(p, "require/node_modules/", "src/node_modules/", 1)))
|
||||
fmt.Fprintln(css, m.Cmdx(nfs.CAT, strings.Replace(p, "require/node_modules/", "usr/node_modules/", 1)))
|
||||
fmt.Fprintln(js, `Volcanos.meta.cache["`+path.Join(ice.PS, p)+`"] = []`)
|
||||
}
|
||||
func _webpack_js(m *ice.Message, js io.Writer, p string) {
|
||||
@ -38,7 +38,7 @@ func _webpack_js(m *ice.Message, js io.Writer, p string) {
|
||||
}
|
||||
func _webpack_node(m *ice.Message, js io.Writer, p string) {
|
||||
fmt.Fprintln(js, `_can_name = "`+path.Join(ice.PS, p)+`";`)
|
||||
fmt.Fprintln(js, m.Cmdx(nfs.CAT, strings.Replace(p, "require/node_modules/", "src/node_modules/", 1)))
|
||||
fmt.Fprintln(js, m.Cmdx(nfs.CAT, strings.Replace(p, "require/node_modules/", "usr/node_modules/", 1)))
|
||||
fmt.Fprintln(js, `Volcanos.meta.cache["`+path.Join(ice.PS, p)+`"] = []`)
|
||||
}
|
||||
func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
@ -118,11 +118,11 @@ const (
|
||||
PLUGIN = "plugin"
|
||||
)
|
||||
const (
|
||||
PAGE_CACHE_CSS = "page/cache.css"
|
||||
PAGE_INDEX_JS = "page/index.js"
|
||||
PAGE_CACHE_JS = "page/cache.js"
|
||||
PAGE_CAN_CSS = "page/can.css"
|
||||
PAGE_CAN_JS = "page/can.js"
|
||||
PAGE_CACHE_CSS = "page/cache.css"
|
||||
PAGE_INDEX_JS = "page/index.js"
|
||||
PAGE_CACHE_JS = "page/cache.js"
|
||||
USR_PUBLISH_CAN_CSS = "usr/publish/can.css"
|
||||
USR_PUBLISH_CAN_JS = "usr/publish/can.js"
|
||||
)
|
||||
|
||||
const DEVPACK = "devpack"
|
||||
|
2
info.go
2
info.go
@ -48,7 +48,7 @@ var Info = struct {
|
||||
|
||||
report: shylinuxc@gmail.com
|
||||
server: https://shylinux.com
|
||||
source: https://shylinux.com/x/icebergs
|
||||
source: https://shylinux.com/x/contexts
|
||||
`,
|
||||
File: Maps{},
|
||||
Gomod: Maps{},
|
||||
|
Loading…
x
Reference in New Issue
Block a user