From 96df24975da7b8d6dde215cc227d206a8138a7af Mon Sep 17 00:00:00 2001 From: shylinux Date: Tue, 7 Mar 2023 03:44:27 +0800 Subject: [PATCH] opt code --- base/nfs/cat.go | 5 ++ base/web/render.go | 38 +------------ conf.go | 1 + core/code/autogen.go | 121 ++++++++++++---------------------------- core/code/binpack.go | 60 ++++++-------------- core/code/c.go | 9 +-- core/code/code.shy | 2 +- core/code/compile.go | 38 +++++++------ core/code/css.go | 8 +-- core/code/go.go | 9 +-- core/code/html.go | 14 +---- core/code/js.go | 9 +-- core/code/publish.go | 95 +++++++++++-------------------- core/code/sh.go | 14 +---- core/code/shy.go | 4 +- core/code/webpack.go | 23 ++------ misc/bash/sess.go | 3 +- misc/webview/webview.go | 21 +------ 18 files changed, 133 insertions(+), 341 deletions(-) diff --git a/base/nfs/cat.go b/base/nfs/cat.go index 7dfa7f2d..e127ad70 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -165,3 +165,8 @@ func OptionLoad(m *ice.Message, file string) *ice.Message { } return m } + +func Template(m *ice.Message, file string) string { return kit.Renders(TemplateText(m, file), m) } +func TemplateText(m *ice.Message, file string) string { + return m.Cmdx(CAT, path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Base(file))) +} diff --git a/base/web/render.go b/base/web/render.go index e94b8621..7b5e9de1 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -162,7 +162,7 @@ func RenderIndex(m *ice.Message, repos string, file ...string) *ice.Message { } func RenderMain(m *ice.Message, pod, index string, arg ...ice.Any) *ice.Message { if script := m.Cmdx(Space(m, pod), nfs.CAT, kit.Select(ice.SRC_MAIN_JS, index)); script != "" { - return m.Echo(kit.Renders(_main_template, ice.Maps{"version": renderVersion(m), "script": script})).RenderResult() + return m.Echo(kit.Renders(m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, "web/main.html")), ice.Maps{nfs.VERSION: renderVersion(m), nfs.SCRIPT: script})).RenderResult() } return RenderIndex(m, ice.VOLCANOS) } @@ -170,7 +170,7 @@ func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) { RenderPodCmd(m, "", cmd, arg...) } func RenderCmds(m *ice.Message, list ...ice.Any) { - m.Echo(kit.Renders(_cmd_template, ice.Maps{"version": renderVersion(m), "list": kit.Format(list)})).RenderResult() + m.Echo(kit.Renders(m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, "web/cmd.html")), ice.Maps{nfs.VERSION: renderVersion(m), ice.LIST: kit.Format(list)})).RenderResult() } func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) { msg := m.Cmd(Space(m, pod), ctx.COMMAND, kit.Select("web.wiki.word", cmd)) @@ -178,7 +178,7 @@ func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) { ctx.INDEX, cmd, ctx.ARGS, kit.Simple(arg), ctx.DISPLAY, m.Option(ice.MSG_DISPLAY), mdb.LIST, kit.UnMarshal(msg.Append(mdb.LIST)), mdb.META, kit.UnMarshal(msg.Append(mdb.META)), ))) - m.Echo(kit.Renders(_cmd_template, ice.Maps{"version": renderVersion(m), "list": list})).RenderResult() + m.Echo(kit.Renders(m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, "web/cmd.html")), ice.Maps{nfs.VERSION: renderVersion(m), ice.LIST: list})).RenderResult() } func renderVersion(m *ice.Message) string { if strings.Contains(m.R.URL.RawQuery, "debug=true") { @@ -186,35 +186,3 @@ func renderVersion(m *ice.Message) string { } return "" } - -var _main_template = ` - - - volcanos - - - - - - - - - - -` - -var _cmd_template = ` - - - volcanos - - - - - - - - - - -` diff --git a/conf.go b/conf.go index 91249692..fd278f7e 100644 --- a/conf.go +++ b/conf.go @@ -140,6 +140,7 @@ const ( // DIR SRC_HELP = "src/help/" SRC_DEBUG = "src/debug/" SRC_RELEASE = "src/release/" + SRC_TEMPLATE = "src/template/" SRC_MAIN_SHY = "src/main.shy" SRC_MAIN_SH = "src/main.sh" SRC_MAIN_JS = "src/main.js" diff --git a/core/code/autogen.go b/core/code/autogen.go index 7f0ddf48..ccb97574 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -26,13 +26,13 @@ func _defs_list(m *ice.Message) string { } func _autogen_source(m *ice.Message, main, file string) { main = kit.ExtChange(main, SHY) - m.Cmd(nfs.DEFS, main, `title "{{.Option "name"}}"`+ice.NL) + m.Cmd(nfs.DEFS, main, nfs.Template(m, ice.SRC_MAIN_SHY)) m.Cmd(nfs.PUSH, main, ssh.SOURCE+ice.SP+strings.TrimPrefix(file, ice.SRC+ice.PS)+ice.NL) } -func _autogen_script(m *ice.Message, file string) { m.Cmd(nfs.DEFS, file, _script_template) } -func _autogen_module(m *ice.Message, file string) { m.Cmd(nfs.DEFS, file, _module_template) } +func _autogen_script(m *ice.Message, file string) { m.Cmd(nfs.DEFS, file, nfs.Template(m, "demo.shy")) } +func _autogen_module(m *ice.Message, file string) { m.Cmd(nfs.DEFS, file, nfs.Template(m, "demo.go")) } func _autogen_import(m *ice.Message, main string, ctx string, mod string) { - m.Cmd(nfs.DEFS, main, _main_template) + m.Cmd(nfs.DEFS, main, nfs.Template(m, ice.SRC_MAIN_GO)) begin, done, list := false, false, []string{} m.Cmd(nfs.CAT, main, func(line string, index int) { if begin && !done && strings.HasPrefix(line, ")") { @@ -50,20 +50,21 @@ func _autogen_import(m *ice.Message, main string, ctx string, mod string) { m.Cmd(nfs.SAVE, main, kit.Join(list, ice.NL)) m.Cmd(cli.SYSTEM, "goimports", "-w", main) } -func _autogen_version(m *ice.Message) { +func _autogen_version(m *ice.Message) string { if mod := _autogen_mod(m, ice.GO_MOD); !nfs.ExistsFile(m, ".git") { m.Cmdy(cli.SYSTEM, GIT, ice.INIT) - m.Cmd(cli.SYSTEM, GIT, "remote", "add", "origin", "https://"+mod) + m.Cmd(cli.SYSTEM, GIT, nfs.REMOTE, "add", nfs.ORIGIN, "https://"+mod) m.Cmd(cli.SYSTEM, GIT, "add", ice.GO_MOD, ice.SRC, ice.ETC_MISS_SH) m.Cmd("web.code.git.repos", mdb.CREATE, nfs.ORIGIN, "https://"+mod, mdb.NAME, path.Base(mod), nfs.PATH, nfs.PWD) } - m.Cmd(nfs.DEFS, ".gitignore", _git_ignore) - m.Cmd(nfs.DEFS, ice.SRC_BINPACK_GO, `package main`+ice.NL) - m.Cmd(nfs.SAVE, ice.SRC_VERSION_GO, kit.Format(_version_template, _autogen_gits(m, nfs.MODULE, _autogen_mod(m, ice.GO_MOD), tcp.HOSTNAME, ice.Info.Hostname))) + m.Cmd(nfs.DEFS, ".gitignore", nfs.Template(m, "gitignore")) + m.Cmd(nfs.DEFS, ice.SRC_BINPACK_GO, nfs.Template(m, ice.SRC_BINPACK_GO)) + m.Cmd(nfs.SAVE, ice.SRC_VERSION_GO, kit.Format(nfs.Template(m, ice.SRC_VERSION_GO), _autogen_gits(m, nfs.MODULE, _autogen_mod(m, ice.GO_MOD), tcp.HOSTNAME, ice.Info.Hostname))) m.Cmd(cli.SYSTEM, "gofmt", "-w", ice.SRC_VERSION_GO) m.Cmdy(nfs.DIR, ice.SRC_BINPACK_GO) m.Cmdy(nfs.DIR, ice.SRC_VERSION_GO) m.Cmdy(nfs.DIR, ice.SRC_MAIN_GO) + return ice.SRC_VERSION_GO } func _autogen_gits(m *ice.Message, arg ...string) string { res := []string{} @@ -90,54 +91,63 @@ func _autogen_mod(m *ice.Message, file string) (mod string) { } else { host = path.Join(host, "x", path.Base(kit.Path(""))) } - m.Cmd(nfs.DEFS, file, kit.Format(`module %s - -go 1.11 -`, host)) + m.Cmd(nfs.DEFS, file, kit.Format(nfs.Template(m, ice.GO_MOD), host)) m.Cmd(nfs.CAT, file, func(line string) { - if strings.HasPrefix(line, "module") { + if strings.HasPrefix(line, nfs.MODULE) { mod = kit.Split(line, ice.SP)[1] } }) return } +const ( + GIT = "git" +) const AUTOGEN = "autogen" func init() { Index.MergeCommands(ice.Commands{ - AUTOGEN: {Name: "autogen path auto module binpack script", Help: "生成", Actions: ice.Actions{ + AUTOGEN: {Name: "autogen path auto version module script", Help: "生成", Actions: ice.Actions{ mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { switch arg[0] { case cli.MAIN: - m.Cmdy(nfs.DIR, nfs.PWD, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH), nfs.DIR_REG, `.*\.go$`)).RenameAppend(nfs.PATH, arg[0]) + m.Cmdy(nfs.DIR, nfs.PWD, nfs.PATH, kit.Dict(nfs.DIR_ROOT, ice.SRC, nfs.DIR_REG, kit.ExtReg(GO))) + case mdb.ZONE, mdb.NAME: + m.Cmdy(nfs.DIR, nfs.PWD, mdb.NAME, kit.Dict(nfs.DIR_ROOT, ice.SRC, nfs.DIR_TYPE, nfs.DIR)) + case mdb.KEY: + m.Push(arg[0], Prefix(m.Option(mdb.ZONE), m.Option(mdb.NAME))) } }}, nfs.MODULE: {Name: "module name*=hi help type*=Zone,Hash,Data,Code,Lang main*=main.go@key zone key", Help: "模块", Hand: func(m *ice.Message, arg ...string) { m.OptionDefault(mdb.ZONE, m.Option(mdb.NAME), mdb.HELP, m.Option(mdb.NAME)) m.OptionDefault(mdb.KEY, Prefix(m.Option(mdb.ZONE), m.Option(mdb.NAME))) + m.Option(nfs.FILE, path.Join(m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO))) m.Option(mdb.TEXT, kit.Format("`name:\"list %s\" help:\"%s\"`", _defs_list(m), m.Option(mdb.HELP))) nfs.OptionFiles(m, nfs.DiskFile) - if p := path.Join(ice.SRC, m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), SHY)); !nfs.ExistsFile(m, p) { + if p := path.Join(ice.SRC, kit.ExtChange(m.Option(nfs.FILE), SHY)); !nfs.ExistsFile(m, p) { _autogen_source(m, path.Join(ice.SRC, m.Option(cli.MAIN)), p) _autogen_script(m, p) } - if p := path.Join(ice.SRC, m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO)); !nfs.ExistsFile(m, p) { + if p := path.Join(ice.SRC, m.Option(nfs.FILE)); !nfs.ExistsFile(m, p) { + _autogen_import(m, path.Join(ice.SRC, m.Option(cli.MAIN)), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD)) _autogen_module(m, p) } - _autogen_import(m, path.Join(ice.SRC, m.Option(cli.MAIN)), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD)) - m.Option(nfs.FILE, path.Join(m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO))) _autogen_version(m.Spawn()) }}, nfs.SCRIPT: {Help: "脚本", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, _miss_template) + m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, nfs.Template(m, ice.ETC_MISS_SH)) defer m.Cmdy(nfs.CAT, ice.ETC_MISS_SH) m.Cmdy(nfs.DIR, ice.ETC_MISS_SH) m.Cmdy(nfs.DIR, ice.GO_MOD) m.Cmdy(nfs.DIR, ice.GO_SUM) }}, + DEVPACK: {Help: "开发", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(WEBPACK, mdb.REMOVE) + m.Cmdy(nfs.DIR, path.Join(ice.USR_VOLCANOS, PAGE)) + }}, WEBPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(WEBPACK, mdb.CREATE) + m.Cmdy(nfs.DIR, path.Join(ice.USR_VOLCANOS, PAGE)) m.Cmdy(nfs.DIR, ice.USR_PUBLISH, kit.Dict(nfs.DIR_REG, "can.*")) }}, BINPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { @@ -151,74 +161,13 @@ func init() { m.Cmdy(nfs.DIR, ice.USR_RELEASE+BINPACK_GO) m.Cmdy(nfs.DIR, ice.USR_RELEASE+CONF_GO) } - _autogen_version(m) - m.Cmdy(nfs.CAT, ice.SRC_VERSION_GO) + m.Cmdy(nfs.CAT, _autogen_version(m)) + }}, + VERSION: {Help: "版本", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(nfs.CAT, _autogen_version(m)) }}, }, Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, kit.Select(path.Base(ice.SRC_VERSION_GO), arg, 0), kit.Dict(nfs.DIR_ROOT, ice.SRC)) }}, }) } - -var _miss_template = `#! /bin/sh - -if [ -f $PWD/.ish/plug.sh ]; then source $PWD/.ish/plug.sh; elif [ -f $HOME/.ish/plug.sh ]; then source $HOME/.ish/plug.sh; else - ctx_temp=$(mktemp); if curl -h &>/dev/null; then curl -o $ctx_temp -fsSL https://shylinux.com; else wget -O $ctx_temp -q http://shylinux.com; fi; source $ctx_temp intshell -fi - -require miss.sh -ish_miss_prepare_compile -ish_miss_prepare_develop -ish_miss_prepare_project - -ish_miss_make; if [ -n "$*" ]; then ish_miss_serve "$@"; fi -` -var _main_template = `package main - -import ( - "shylinux.com/x/ice" -) - -func main() { print(ice.Run()) } -` -var _module_template = `package {{.Option "zone"}} - -import ( - "shylinux.com/x/ice" -) - -type {{.Option "name"}} struct { - ice.{{.Option "type"}} - - list string {{.Option "text"}} -} - -func (s {{.Option "name"}}) List(m *ice.Message, arg ...string) { - s.{{.Option "type"}}.List(m, arg...) -} - -func init() { ice.Cmd("{{.Option "key"}}", {{.Option "name"}}{}) } -` -var _version_template = `package main - -import ice "shylinux.com/x/icebergs" - -func init() { - ice.Info.Make = ice.MakeInfo{ -%s - } -} -` -var _script_template = `chapter "{{.Option "name"}}" - -field {{.Option "key"}} -` -var _git_ignore = ` -src/binpack.go -src/version.go -etc/ -bin/ -var/ -usr/ -.* -` diff --git a/core/code/binpack.go b/core/code/binpack.go index 2b4e42df..aef4df53 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -16,11 +16,11 @@ 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), "") + if strings.HasPrefix(arg[0], "usr/volcanos/publish/") && !strings.HasSuffix(arg[0], "/proto.js") { return } - if strings.HasPrefix(arg[0], "usr/volcanos/publish/") && !strings.HasSuffix(arg[0], "/proto.js") { + 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 } switch path.Base(arg[0]) { @@ -39,32 +39,24 @@ func _binpack_file(m *ice.Message, w io.Writer, arg ...string) { } } func _binpack_dir(m *ice.Message, w io.Writer, dir string) { - nfs.DirDeepAll(m, dir, nfs.PWD, func(value ice.Maps) { - _binpack_file(m, w, path.Join(dir, value[nfs.PATH])) - }) + nfs.DirDeepAll(m, dir, nfs.PWD, func(value ice.Maps) { _binpack_file(m, w, path.Join(dir, value[nfs.PATH])) }) } func _binpack_all(m *ice.Message) { nfs.OptionFiles(m, nfs.DiskFile) if w, p, e := nfs.CreateFile(m, ice.SRC_BINPACK_GO); m.Assert(e) { defer w.Close() defer m.Echo(p) - fmt.Fprintln(w, _binpack_template) - defer fmt.Fprintln(w, _binpack_template_end) - _binpack_dir(m, w, ice.USR_VOLCANOS) - _binpack_dir(m, w, ice.USR_INTSHELL) - _binpack_dir(m, w, ice.SRC) - _binpack_file(m, w, ice.ETC_MISS_SH) - _binpack_file(m, w, ice.ETC_INIT_SHY) - _binpack_file(m, w, ice.ETC_EXIT_SHY) - _binpack_file(m, w, ice.README_MD) - _binpack_file(m, w, ice.MAKEFILE) - _binpack_file(m, w, ice.LICENSE) - - cache := kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, "go", "env", "GOMODCACHE")) - list := map[string]bool{} + fmt.Fprintln(w, nfs.Template(m, ice.SRC_BINPACK_GO)) + defer fmt.Fprintln(w, nfs.Template(m, "binpack_end.go")) + for _, p := range []string{ice.USR_VOLCANOS, ice.USR_INTSHELL, ice.SRC} { + _binpack_dir(m, w, p) + } + for _, p := range []string{ice.ETC_MISS_SH, ice.ETC_INIT_SHY, ice.ETC_EXIT_SHY, ice.README_MD, ice.MAKEFILE, ice.LICENSE} { + _binpack_file(m, w, p) + } + list, cache := map[string]bool{}, kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, GO, "env", "GOMODCACHE")) for k := range ice.Info.File { - ls := strings.Split(k, ice.PS) - switch ls[2] { + switch ls := strings.Split(k, ice.PS); ls[2] { case ice.SRC: case ice.USR: list[path.Join(kit.Slice(ls, 2, -1)...)] = true @@ -73,7 +65,7 @@ func _binpack_all(m *ice.Message) { } } for _, p := range kit.SortedKey(list) { - m.Cmd(nfs.DIR, p, nfs.PATH, kit.Dict(nfs.DIR_ROOT, nfs.PWD, nfs.DIR_REG, kit.ExtReg("(sh|shy|js)"))).Tables(func(value ice.Maps) { + m.Cmd(nfs.DIR, p, nfs.PATH, kit.Dict(nfs.DIR_ROOT, nfs.PWD, nfs.DIR_REG, kit.ExtReg("(sh|shy|py|js|css|html)"))).Tables(func(value ice.Maps) { if strings.Contains(value[nfs.PATH], "/go/pkg/mod/") { _binpack_file(m, w, value[nfs.PATH], ice.USR_REQUIRE+strings.Split(value[nfs.PATH], "/go/pkg/mod/")[1]) } else { @@ -98,28 +90,8 @@ const BINPACK = "binpack" func init() { Index.MergeCommands(ice.Commands{ BINPACK: {Name: "binpack path auto create insert", Help: "打包", Actions: ice.MergeActions(ice.Actions{ - mdb.CREATE: {Name: "create", Hand: func(m *ice.Message, arg ...string) { _binpack_all(m) }}, + mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { _binpack_all(m) }}, mdb.INSERT: {Name: "insert path*", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m) }}, }, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path"))}, }) } - -var _binpack_template = `package main - -import ( - "encoding/base64" - - ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/nfs" -) - -func init() { - pack := ice.Maps{` -var _binpack_template_end = ` } - nfs.PackFile.RemoveAll(ice.SRC) - for k, v := range pack { - if b, e := base64.StdEncoding.DecodeString(v); e == nil { - nfs.PackFile.WriteFile(k, b) - } - } -}` diff --git a/core/code/c.go b/core/code/c.go index 16aa0bd2..cee4688f 100644 --- a/core/code/c.go +++ b/core/code/c.go @@ -44,7 +44,7 @@ func init() { 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) }}, + TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, "demo.c")) }}, NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }}, }, PlugAction())}, H: {Name: "h path auto", Help: "编程", Actions: ice.MergeActions(ice.Actions{ @@ -52,10 +52,3 @@ func init() { }, PlugAction())}, }) } - -var _c_template = `#include - -int main(int argc, char *argv[]) { - printf("hello world\n"); -} -` diff --git a/core/code/code.shy b/core/code/code.shy index cacba648..25b870f4 100644 --- a/core/code/code.shy +++ b/core/code/code.shy @@ -3,9 +3,9 @@ code.shy install.go upgrade.go -autogen.go webpack.go binpack.go +autogen.go compile.go publish.go diff --git a/core/code/compile.go b/core/code/compile.go index 010d5b7a..519598a5 100644 --- a/core/code/compile.go +++ b/core/code/compile.go @@ -10,6 +10,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/web" kit "shylinux.com/x/toolkits" ) @@ -35,44 +36,49 @@ func _compile_target(m *ice.Message, arg ...string) (string, string, string, str return main, file, goos, arch } +const ( + VERSION = "version" +) 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 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") { - m.Cmd(mdb.INSERT, cli.MIRRORS, "", mdb.ZONE, cli.CLI, "go", cli.CMD, kit.Format("install download https://golang.google.cn/dl/go1.15.5.%s-%s.tar.gz usr/local", runtime.GOOS, runtime.GOARCH)) + COMPILE: {Name: "compile arch=amd64,386,arm,arm64,mipsle os=linux,darwin,windows src=src/main.go@key run binpack webpack devpack", Help: "编译", Actions: ice.MergeActions(ice.Actions{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { cli.IsAlpine(m, GO, "go git") }}, + mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { + switch arg[0] { + case VERSION: + m.Push(arg[0], "1.15.15") + default: + m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, kit.ExtReg(GO))) } }}, - mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { - 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) }}, + 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) }}, + DEVPACK: {Help: "开发", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, DEVPACK) }}, + INSTALL: {Name: "install version=1.15.15", Help: "安装", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(INSTALL, web.DOWNLOAD, kit.Format("https://golang.google.cn/dl/go%s.%s-%s.%s", 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) { - _autogen_version(m.Spawn()) 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")) - env = append(env, "GOCACHE", kit.HomePath("go/go-build")) + 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 ")) 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 } - m.Logs(mdb.EXPORT, nfs.SOURCE, main, nfs.TARGET, file) - m.Cmdy(nfs.DIR, file, nfs.DIR_WEB_FIELDS).StatusTimeCount() - if strings.Contains(file, ice.ICE) { + m.Logs(COMPILE, nfs.SOURCE, main, nfs.TARGET, file) + if m.Cmdy(nfs.DIR, file, nfs.DIR_WEB_FIELDS); strings.Contains(file, ice.ICE) { m.Cmdy(PUBLISH, ice.CONTEXTS) } - m.StatusTime("version", strings.TrimPrefix(m.Cmdx(cli.SYSTEM, GO, "version"), "go version ")) }}, }) } diff --git a/core/code/css.go b/core/code/css.go index 6bbd1318..95c6ade6 100644 --- a/core/code/css.go +++ b/core/code/css.go @@ -80,14 +80,8 @@ func init() { } }}, 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))))) + m.Echo(kit.Format(nfs.Template(m, "demo.css"), 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; -} -` diff --git a/core/code/go.go b/core/code/go.go index 8d684c10..7f4d526d 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -120,7 +120,7 @@ func init() { } }}, TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { - m.Echo(_go_template, path.Base(path.Dir(path.Join(arg[2], arg[1])))) + m.Echo(nfs.Template(m, "demo.go"), 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) }}, @@ -140,10 +140,3 @@ func init() { }, PlugAction())}, }) } - -var _go_template = `package %s - -func init() { - -} -` diff --git a/core/code/html.go b/core/code/html.go index 054bf198..84cd4f4a 100644 --- a/core/code/html.go +++ b/core/code/html.go @@ -6,6 +6,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" kit "shylinux.com/x/toolkits" ) @@ -21,19 +22,8 @@ func init() { 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() + 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() }}, }, PlugAction())}, }) } - -var _html_template = ` - - volcanos - - - - - - -` diff --git a/core/code/js.go b/core/code/js.go index fa71be1b..e3106394 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -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" kit "shylinux.com/x/toolkits" ) @@ -29,13 +30,7 @@ func init() { 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) }}, + TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, "demo.js")) }}, }, PlugAction())}, }) } - -var _js_template = ` -Volcanos(chat.ONIMPORT, {_init: function(can, msg) { - msg.Echo("hello world").Dump(can) -}}) -` diff --git a/core/code/publish.go b/core/code/publish.go index f6678f0a..dbb344eb 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -1,7 +1,6 @@ package code import ( - "fmt" "os" "path" "runtime" @@ -13,28 +12,13 @@ import ( "shylinux.com/x/icebergs/base/ctx" "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" ) -func _publish_file(m *ice.Message, file string, arg ...string) string { - if strings.HasSuffix(file, ice.ICE_BIN) { - file, arg = cli.SystemFind(m, os.Args[0]), kit.Simple(kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH)) - } else if s, e := nfs.StatFile(m, file); m.Assert(e) && s.IsDir() { - file = m.Cmdx(nfs.TAR, mdb.IMPORT, path.Base(file), file) - defer func() { nfs.Remove(m, file) }() - } - target := path.Join(ice.USR_PUBLISH, kit.Select(path.Base(file), arg, 0)) - m.Logs(mdb.EXPORT, PUBLISH, target, cli.FROM, file) - return m.Cmdx(nfs.LINK, target, file) -} -func _publish_list(m *ice.Message, arg ...string) { - m.Option(nfs.DIR_REG, kit.Select("", arg, 0)) - nfs.DirDeepAll(m, ice.USR_PUBLISH, nfs.PWD, nil, kit.Select(nfs.DIR_WEB_FIELDS, arg, 1)) -} -func _publish_bin_list(m *ice.Message, dir string) { - p := m.Option(cli.CMD_DIR, dir) +func _publish_bin_list(m *ice.Message, p string) *ice.Message { + m.Option(cli.CMD_DIR, p) + defer m.SortTimeR(mdb.TIME) for _, ls := range strings.Split(cli.SystemCmds(m, "ls |xargs file |grep executable"), ice.NL) { if file := strings.TrimSpace(strings.Split(ls, ice.DF)[0]); file != "" { if s, e := nfs.StatFile(m, path.Join(p, file)); e == nil { @@ -43,44 +27,41 @@ func _publish_bin_list(m *ice.Message, dir string) { } } } - m.SortTimeR(mdb.TIME) + return m } -func PublishScript(m *ice.Message, arg ...string) { - u := web.OptionUserWeb(m) - host := tcp.PublishLocalhost(m, strings.Split(u.Host, ice.DF)[0]) - m.Option(cli.CTX_ENV, kit.Select("", ice.SP+kit.JoinKV(ice.EQ, ice.SP, cli.CTX_POD, m.Option(ice.MSG_USERPOD)), m.Option(ice.MSG_USERPOD) != "")) - m.Option(web.DOMAIN, fmt.Sprintf("%s://%s:%s", u.Scheme, host, kit.Select(kit.Select("443", "80", u.Scheme == ice.HTTP), strings.Split(u.Host, ice.DF), 1))) - for _, v := range arg { - m.EchoScript(kit.Renders(v, m)) +func _publish_list(m *ice.Message, arg ...string) *ice.Message { + m.Option(nfs.DIR_REG, kit.Select("", arg, 0)) + return nfs.DirDeepAll(m, ice.USR_PUBLISH, nfs.PWD, nil, kit.Select(nfs.DIR_WEB_FIELDS, arg, 1)) +} +func _publish_file(m *ice.Message, file string, arg ...string) string { + if strings.HasSuffix(file, ice.ICE_BIN) { + file, arg = cli.SystemFind(m, os.Args[0]), kit.Simple(kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH)) + } else if s, e := nfs.StatFile(m, file); m.Assert(e) && s.IsDir() { + file = m.Cmdx(nfs.TAR, mdb.IMPORT, path.Base(file), file) + defer func() { nfs.Remove(m, file) }() } + target := path.Join(ice.USR_PUBLISH, kit.Select(path.Base(file), arg, 0)) + return m.Logs(mdb.EXPORT, PUBLISH, target, nfs.FROM, file).Cmdx(nfs.LINK, target, file) } func _publish_contexts(m *ice.Message, arg ...string) { - u := web.OptionUserWeb(m) - host := tcp.PublishLocalhost(m, strings.Split(u.Host, ice.DF)[0]) - m.Option(cli.CTX_ENV, kit.Select("", ice.SP+kit.JoinKV(ice.EQ, ice.SP, cli.CTX_POD, m.Option(ice.MSG_USERPOD)), m.Option(ice.MSG_USERPOD) != "")) - m.Option(web.DOMAIN, fmt.Sprintf("%s://%s:%s", u.Scheme, host, kit.Select(kit.Select("443", "80", u.Scheme == ice.HTTP), strings.Split(u.Host, ice.DF), 1))) for _, k := range kit.Default(arg, ice.MISC) { switch k { - case INSTALL: - m.Echo(kit.Renders(strings.TrimSpace(m.Config(kit.Keys(ice.CONTEXTS, ice.MISC))), m)) - return - case ice.MISC: - _publish_file(m, ice.ICE_BIN) - case ice.CORE: - m.Option(web.DOMAIN, m.Cmd(web.SPIDE, ice.COM).Append(web.CLIENT_ORIGIN)) case ice.BASE: m.Option(web.DOMAIN, m.Cmd(web.SPIDE, ice.SHY).Append(web.CLIENT_ORIGIN)) - m.Option(nfs.REMOTE, kit.Select(ice.Info.Make.Remote, cli.SystemExec(m, "git", "config", "remote.origin.url"))) + case ice.CORE: + m.Option(web.DOMAIN, m.Cmd(web.SPIDE, ice.DEV).Append(web.CLIENT_ORIGIN)) + default: + m.Options(web.DOMAIN, m.Option(ice.MSG_USERHOST), cli.CTX_ENV, kit.Select("", ice.SP+kit.JoinKV(ice.EQ, ice.SP, cli.CTX_POD, m.Option(ice.MSG_USERPOD)), m.Option(ice.MSG_USERPOD) != "")) + _publish_file(m, ice.ICE_BIN) } - if buf, err := kit.Render(m.Config(kit.Keys(ice.CONTEXTS, k)), m); m.Assert(err) { - m.EchoScript(strings.TrimSpace(string(buf))) + if s := strings.TrimSpace(kit.Renders(m.Config(kit.Keys(ice.CONTEXTS, k)), m)); k == INSTALL { + m.Echo(s) + } else { + m.EchoScript(s) } } } -const ( - GIT = "git" -) const PUBLISH = "publish" func init() { @@ -88,21 +69,17 @@ func init() { PUBLISH: {Name: "publish path auto create volcanos icebergs intshell", Help: "发布", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Config(ice.CONTEXTS, _contexts) }}, ice.VOLCANOS: {Help: "火山架", Hand: func(m *ice.Message, arg ...string) { - defer func() { m.EchoQRCode(m.Option(ice.MSG_USERWEB)) }() - defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.MISC) }() - _publish_list(m, kit.ExtReg(`(html|css|js)`)) + _publish_list(m, kit.ExtReg(`(html|css|js)`)).Cmdy("", ice.CONTEXTS, ice.MISC).Echo(ice.NL).EchoQRCode(m.Option(ice.MSG_USERWEB)) }}, ice.ICEBERGS: {Help: "冰山架", Hand: func(m *ice.Message, arg ...string) { - defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.CORE) }() - _publish_bin_list(m, ice.USR_PUBLISH) + _publish_bin_list(m, ice.USR_PUBLISH).Cmdy("", ice.CONTEXTS, ice.CORE) }}, ice.INTSHELL: {Help: "神农架", Hand: func(m *ice.Message, arg ...string) { - defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.BASE) }() - _publish_list(m, kit.ExtReg(`(sh|vim|conf)`)) + _publish_list(m, kit.ExtReg(`(sh|vim|conf)`)).Cmdy("", ice.CONTEXTS, ice.BASE) }}, ice.CONTEXTS: {Hand: func(m *ice.Message, arg ...string) { _publish_contexts(m, arg...) }}, - mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, arg[1:]).Cut("path,size,time").ProcessAgain() }}, - mdb.CREATE: {Name: "create file", Help: "添加", Hand: func(m *ice.Message, arg ...string) { _publish_file(m, m.Option(nfs.FILE)) }}, + mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, arg[1:]).Cut("path,size,time") }}, + mdb.CREATE: {Name: "create file", Hand: func(m *ice.Message, arg ...string) { _publish_file(m, m.Option(nfs.FILE)) }}, nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { nfs.Trash(m, path.Join(ice.USR_PUBLISH, m.Option(nfs.PATH))) }}, }, ctx.ConfAction(ice.CONTEXTS, _contexts), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, kit.Select("", arg, 0), nfs.DIR_WEB_FIELDS, kit.Dict(nfs.DIR_ROOT, ice.USR_PUBLISH)).SortTimeR(mdb.TIME) @@ -111,13 +88,7 @@ func init() { } var _contexts = kit.Dict( - ice.MISC, ` -export ctx_dev={{.Option "domain"}}{{.Option "ctx_env"}}; temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL $ctx_dev; else wget -O $temp -q $ctx_dev; fi; source $temp app username {{.Option "user.name"}} usernick "{{.Option "user.nick"}}" -`, - ice.CORE, ` -temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL {{.Option "domain"}}; else wget -O $temp -q {{.Option "domain"}}; fi; source $temp binary -`, - ice.BASE, ` -temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL {{.Option "domain"}}; else wget -O $temp -q {{.Option "domain"}}; fi; source $temp source -`, + ice.MISC, `export ctx_dev={{.Option "domain"}}{{.Option "ctx_env"}}; temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL $ctx_dev; else wget -O $temp -q $ctx_dev; fi; source $temp app username {{.Option "user.name"}} usernick "{{.Option "user.nick"}}"`, + ice.CORE, `temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL {{.Option "domain"}}; else wget -O $temp -q {{.Option "domain"}}; fi; source $temp binary`, + ice.BASE, `temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL {{.Option "domain"}}; else wget -O $temp -q {{.Option "domain"}}; fi; source $temp source`, ) diff --git a/core/code/sh.go b/core/code/sh.go index b8518c2f..cf0e361d 100644 --- a/core/code/sh.go +++ b/core/code/sh.go @@ -13,7 +13,7 @@ import ( ) 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) + cmds, text := kit.Select(SH, m.Config(ssh.SHELL)), kit.Format(strings.TrimSpace(nfs.Template(m, "cmd.sh")), 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, "#!")) } @@ -33,18 +33,8 @@ func init() { 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) }}, + TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, "demo.sh")) }}, NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }}, }, PlugAction())}, }) } - -var _sh_template = `#!/bin/sh - -demo() { - echo "hello world" -} -` -var _sh_cmd_template = `export ctx_dev=%s ctx_pod=%s ctx_mod=%s -temp=$(mktemp); if curl -V &>/dev/null; then curl -o $temp -fsSL $ctx_dev; else wget -O $temp -q $ctx_dev; fi && source $temp $ctx_mod -` diff --git a/core/code/shy.go b/core/code/shy.go index 117368d0..dd045756 100644 --- a/core/code/shy.go +++ b/core/code/shy.go @@ -24,7 +24,7 @@ func init() { ctx.ProcessCommand(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1]))) }}, TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { - m.Echo(_shy_template, path.Base(path.Dir(path.Join(arg[2], arg[1])))) + m.Echo(nfs.Template(m, "demo.shy"), 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() { @@ -35,5 +35,3 @@ func init() { }}, }) } - -var _shy_template = `chapter "%s"` diff --git a/core/code/webpack.go b/core/code/webpack.go index af4585e0..e1eb0f25 100644 --- a/core/code/webpack.go +++ b/core/code/webpack.go @@ -25,7 +25,6 @@ func _webpack_can(m *ice.Message) { m.Option(nfs.DIR_ROOT, "") 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))) @@ -52,6 +51,7 @@ func _webpack_cache(m *ice.Message, dir string, write bool) { m.Assert(e) defer js.Close() defer fmt.Fprintln(js, `_can_name = ""`) + defer m.Cmdy(nfs.DIR, _volcanos(m, PAGE)) defer _webpack_can(m) if !write { return @@ -103,7 +103,7 @@ func _webpack_build(m *ice.Message, file string) { if nfs.ExistsFile(m, ice.SRC_MAIN_JS) { main_js = ice.SRC_MAIN_JS } - fmt.Fprintf(f, _webpack_template, + fmt.Fprintf(f, nfs.Template(m, "index.html"), m.Cmdx(nfs.CAT, _volcanos(m, ice.INDEX_CSS)), m.Cmdx(nfs.CAT, _volcanos(m, PAGE_CACHE_CSS)), m.Cmdx(nfs.CAT, _volcanos(m, ice.PROTO_JS)), m.Cmdx(nfs.CAT, kit.Keys(file, JS)), m.Cmdx(nfs.CAT, _volcanos(m, PAGE_CACHE_JS)), m.Cmdx(nfs.CAT, main_js), @@ -131,10 +131,10 @@ const WEBPACK = "webpack" func init() { Index.MergeCommands(ice.Commands{ WEBPACK: {Name: "webpack path auto create remove", Help: "打包", Actions: ice.MergeActions(ice.Actions{ - mdb.CREATE: {Name: "create", Help: "发布", Hand: func(m *ice.Message, arg ...string) { + mdb.CREATE: {Help: "发布", Hand: func(m *ice.Message, arg ...string) { _webpack_cache(m.Spawn(), _volcanos(m), true) }}, - mdb.REMOVE: {Name: "remove", Help: "调试", Hand: func(m *ice.Message, arg ...string) { + mdb.REMOVE: {Help: "调试", Hand: func(m *ice.Message, arg ...string) { _webpack_cache(m.Spawn(), _volcanos(m), false) }}, mdb.INSERT: {Name: "insert path*", Hand: func(m *ice.Message, arg ...string) { @@ -155,18 +155,3 @@ func init() { }}, }) } - -var _webpack_template = ` - - - - - - - - - - - - -` diff --git a/misc/bash/sess.go b/misc/bash/sess.go index e7defbb9..2b24c2d6 100644 --- a/misc/bash/sess.go +++ b/misc/bash/sess.go @@ -10,7 +10,6 @@ import ( "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/web" - "shylinux.com/x/icebergs/core/code" kit "shylinux.com/x/toolkits" ) @@ -63,7 +62,7 @@ func init() { }}, SESS: {Name: "sess hash auto invite prunes", Help: "会话流", Actions: ice.MergeActions(ice.Actions{ aaa.INVITE: {Hand: func(m *ice.Message, arg ...string) { - code.PublishScript(m, `export ctx_dev={{.Option "domain"}}; ctx_temp=$(mktemp); curl -o $ctx_temp -fsSL $ctx_dev; source $ctx_temp`) + // code.PublishScript(m, `export ctx_dev={{.Option "domain"}}; ctx_temp=$(mktemp); curl -o $ctx_temp -fsSL $ctx_dev; source $ctx_temp`) }}, }, mdb.HashAction(mdb.FIELD, "time,hash,status,username,hostname,release,pid,pwd,grant"))}, }) diff --git a/misc/webview/webview.go b/misc/webview/webview.go index 7a8c8313..343ac760 100644 --- a/misc/webview/webview.go +++ b/misc/webview/webview.go @@ -1,6 +1,7 @@ package webview import ( + "path" "strings" ice "shylinux.com/x/icebergs" @@ -39,7 +40,7 @@ func (w WebView) Menu() bool { } else { w.WebView.SetTitle(ice.CONTEXTS) w.WebView.SetSize(200, 60*len(list), webview.HintNone) - w.WebView.Navigate(kit.Format(_menu_template, kit.Join(list, ice.NL))) + w.WebView.Navigate(kit.Format(`data:text/html,`+m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, "webview", "home.html")), kit.Join(list, ice.NL))) return true } } @@ -85,21 +86,3 @@ func Run(cb func(*WebView) ice.Any) { view.navigate("http://localhost:9020") } } - -var _menu_template = `data:text/html, - - - - - - -%s -`