forked from x/icebergs
opt code
This commit is contained in:
parent
96df24975d
commit
f3e0b8bf58
@ -16,6 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func _runtime_init(m *ice.Message) {
|
||||
count := kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))
|
||||
kit.Fetch(kit.UnMarshal(kit.Format(ice.Info.Make)), func(key string, value ice.Any) {
|
||||
m.Conf(RUNTIME, kit.Keys(MAKE, strings.ToLower(key)), value)
|
||||
})
|
||||
@ -30,7 +31,6 @@ func _runtime_init(m *ice.Message) {
|
||||
for _, k := range ENV_LIST {
|
||||
switch m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k)); k {
|
||||
case CTX_PID:
|
||||
// ice.Info.PidPath = kit.Select(path.Join(ice.VAR_LOG, ice.ICE_PID), kit.Env(k))
|
||||
ice.Info.PidPath = kit.Env(k)
|
||||
case CTX_SHARE:
|
||||
ice.Info.CtxShare = kit.Env(k)
|
||||
@ -56,7 +56,7 @@ func _runtime_init(m *ice.Message) {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, nfs.SIZE), msg.Append(nfs.SIZE))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), msg.Append(mdb.HASH))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.TIME), msg.Append(mdb.TIME))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))+1)
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), count+1)
|
||||
m.Conf(RUNTIME, mdb.META, "")
|
||||
m.Conf(RUNTIME, mdb.HASH, "")
|
||||
}
|
||||
@ -90,13 +90,12 @@ const (
|
||||
NODE = "node"
|
||||
)
|
||||
const (
|
||||
GOARCH = "GOARCH"
|
||||
AMD64 = "amd64"
|
||||
X86 = "386"
|
||||
ARM = "arm"
|
||||
ARM64 = "arm64"
|
||||
MIPSLE = "mipsle"
|
||||
|
||||
GOARCH = "GOARCH"
|
||||
AMD64 = "amd64"
|
||||
X86 = "386"
|
||||
ARM = "arm"
|
||||
ARM64 = "arm64"
|
||||
MIPSLE = "mipsle"
|
||||
GOOS = "GOOS"
|
||||
LINUX = "linux"
|
||||
DARWIN = "darwin"
|
||||
|
@ -112,7 +112,6 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
if m.IsErr() {
|
||||
m.Option(ice.MSG_ARGS, kit.Simple(http.StatusBadRequest, cmd.Args, err.String()))
|
||||
m.Echo(strings.TrimRight(err.String(), ice.NL))
|
||||
m.Debug("what %v", m.FormatMeta())
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -257,8 +257,14 @@ func init() {
|
||||
func AutoConfig(args ...ice.Any) *ice.Action {
|
||||
return &ice.Action{Hand: func(m *ice.Message, arg ...string) {
|
||||
if cs := m.Target().Configs; len(args) > 0 {
|
||||
cs[m.CommandKey()] = &ice.Config{Value: kit.Data(args...)}
|
||||
ice.Info.Load(m, m.CommandKey())
|
||||
if cs[m.CommandKey()] == nil {
|
||||
cs[m.CommandKey()] = &ice.Config{Value: kit.Data(args...)}
|
||||
// ice.Info.Load(m, m.CommandKey())
|
||||
} else {
|
||||
for k, v := range kit.Dict(args...) {
|
||||
m.Config(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
if cmd := m.Target().Commands[m.CommandKey()]; cmd == nil {
|
||||
return
|
||||
|
@ -172,8 +172,8 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DIR: {Name: "dir path field auto upload", Help: "目录", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
aaa.White(m, ice.SRC, ice.BIN, ice.USR, ice.USR_PUBLISH, ice.USR_LOCAL_GO)
|
||||
aaa.Black(m, ice.BIN_BOOT_LOG, ice.USR_LOCAL)
|
||||
aaa.White(m, ice.SRC, ice.BIN, ice.USR)
|
||||
aaa.Black(m, ice.USR_LOCAL)
|
||||
}}, mdb.UPLOAD: {},
|
||||
TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(TRASH, mdb.CREATE, m.Option(PATH)) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -213,6 +213,7 @@ func Dir(m *ice.Message, sort string) *ice.Message {
|
||||
}
|
||||
func DirDeepAll(m *ice.Message, root, dir string, cb func(ice.Maps), arg ...string) *ice.Message {
|
||||
m.Options(DIR_TYPE, CAT, DIR_ROOT, root, DIR_DEEP, ice.TRUE)
|
||||
defer m.Options(DIR_TYPE, "", DIR_ROOT, "", DIR_DEEP, "")
|
||||
if msg := m.Cmd(DIR, dir, arg).Tables(cb); cb == nil {
|
||||
return m.Copy(msg)
|
||||
} else {
|
||||
|
@ -3,10 +3,10 @@ package nfs
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -26,7 +26,7 @@ func _save_file(m *ice.Message, name string, text ...string) {
|
||||
defer m.Echo(p)
|
||||
for _, v := range text {
|
||||
if n, e := fmt.Fprint(f, v); m.Assert(e) {
|
||||
m.Logs(mdb.EXPORT, FILE, p, SIZE, n)
|
||||
m.Logs(SAVE, FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -37,7 +37,7 @@ func _push_file(m *ice.Message, name string, text ...string) {
|
||||
defer m.Echo(p)
|
||||
for _, k := range text {
|
||||
if n, e := fmt.Fprint(f, k); m.Assert(e) {
|
||||
m.Logs(mdb.EXPORT, FILE, p, SIZE, n)
|
||||
m.Logs(SAVE, FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,8 +50,8 @@ func _copy_file(m *ice.Message, name string, from ...string) {
|
||||
if s, e := OpenFile(m, path.Join(m.Option(DIR_ROOT), v)); !m.Warn(e, ice.ErrNotFound, v) {
|
||||
defer s.Close()
|
||||
if n, e := io.Copy(f, s); !m.Warn(e, ice.ErrNotValid, v) {
|
||||
m.Logs(mdb.IMPORT, FILE, v, SIZE, n)
|
||||
m.Logs(mdb.EXPORT, FILE, p, SIZE, n)
|
||||
m.Logs(LOAD, FILE, v, SIZE, n)
|
||||
m.Logs(SAVE, FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -70,7 +70,7 @@ func _link_file(m *ice.Message, name string, from string) {
|
||||
if MkdirAll(m, path.Dir(name)); m.Warn(Link(m, from, name)) && m.Warn(Symlink(m, from, name), ice.ErrWarn, from) {
|
||||
return
|
||||
}
|
||||
m.Logs(mdb.CREATE, FILE, name, FROM, from)
|
||||
m.Logs(SAVE, FILE, name, FROM, from)
|
||||
m.Echo(name)
|
||||
}
|
||||
|
||||
@ -117,3 +117,20 @@ func init() {
|
||||
}},
|
||||
})
|
||||
}
|
||||
func Copy(m *ice.Message, cb func([]byte, int) []byte, to, from string) {
|
||||
if _from, e := os.Open(from); m.Assert(e) {
|
||||
defer _from.Close()
|
||||
if _to, e := os.Create(to); m.Assert(e) {
|
||||
defer _to.Close()
|
||||
offset, buf := 0, make([]byte, 1024*1024)
|
||||
for {
|
||||
n, _ := _from.Read(buf)
|
||||
if n, _ = _to.Write(cb(buf[:n], offset)); n == 0 {
|
||||
break
|
||||
}
|
||||
offset += n
|
||||
}
|
||||
m.Logs(SAVE, FILE, to, FROM, from, SIZE, offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func _cache_upload(m *ice.Message, r *http.Request) (mime, name, file, size stri
|
||||
defer f.Close()
|
||||
b.Seek(0, os.SEEK_SET)
|
||||
if n, e := io.Copy(f, b); !m.Warn(e, ice.ErrNotValid, UPLOAD) {
|
||||
m.Logs(mdb.IMPORT, nfs.FILE, p, nfs.SIZE, kit.FmtSize(int64(n)))
|
||||
m.Logs(nfs.LOAD, nfs.FILE, p, nfs.SIZE, kit.FmtSize(int64(n)))
|
||||
return h.Header.Get(ContentType), h.Filename, p, kit.Format(n)
|
||||
}
|
||||
}
|
||||
@ -78,10 +78,12 @@ func _cache_download(m *ice.Message, r *http.Response, file string, cb ice.Any)
|
||||
last, base := 0, 10
|
||||
nfs.CopyFile(m, f, r.Body, base*ice.MOD_BUFS, kit.Int(kit.Select("100", r.Header.Get(ContentLength))), func(count, total, step int) {
|
||||
if step/base != last {
|
||||
m.Logs(mdb.EXPORT, nfs.FILE, p, mdb.COUNT, count, mdb.TOTAL, total, mdb.VALUE, step)
|
||||
m.Logs(nfs.SAVE, nfs.FILE, p, mdb.COUNT, count, mdb.TOTAL, total, mdb.VALUE, step)
|
||||
switch cb := cb.(type) {
|
||||
case func(int, int, int):
|
||||
cb(count, total, step)
|
||||
if cb != nil {
|
||||
cb(count, total, step)
|
||||
}
|
||||
case nil:
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
|
@ -171,6 +171,10 @@ const (
|
||||
SERVE_CHECK = "serve.check"
|
||||
SERVE_STOP = "serve.stop"
|
||||
|
||||
REQUIRE_MODULES = "require/modules/"
|
||||
REQUIRE_USR = "require/usr/"
|
||||
REQUIRE_SRC = "require/src/"
|
||||
|
||||
WEB_LOGIN = "_login"
|
||||
DOMAIN = "domain"
|
||||
INDEX = "index"
|
||||
@ -277,17 +281,17 @@ func init() {
|
||||
}
|
||||
m.RenderDownload(p)
|
||||
}},
|
||||
PP(ice.REQUIRE, ice.NODE_MODULES): {Name: "/require/node_modules/", Help: "依赖库", Hand: func(m *ice.Message, arg ...string) {
|
||||
p := path.Join(ice.USR, ice.NODE_MODULES, path.Join(arg...))
|
||||
PP(REQUIRE_MODULES): {Name: "/require/modules/", Help: "依赖库", Hand: func(m *ice.Message, arg ...string) {
|
||||
p := path.Join(ice.USR_NODE_MODULES, path.Join(arg...))
|
||||
if !nfs.ExistsFile(m, p) {
|
||||
m.Cmd(cli.SYSTEM, "npm", "install", arg[0], kit.Dict(cli.CMD_DIR, ice.USR))
|
||||
}
|
||||
m.RenderDownload(p)
|
||||
}},
|
||||
PP(ice.REQUIRE, ice.USR): {Name: "/require/usr/", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
|
||||
PP(REQUIRE_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: "源代码", Actions: ice.MergeActions(ice.Actions{}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
PP(REQUIRE_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) {
|
||||
|
57
conf.go
57
conf.go
@ -71,14 +71,14 @@ const ( // DIR
|
||||
VAR = "var"
|
||||
USR = "usr"
|
||||
|
||||
JSON = "json"
|
||||
CSV = "csv"
|
||||
SVG = "svg"
|
||||
HTML = "html"
|
||||
CSS = "css"
|
||||
JS = "js"
|
||||
GO = "go"
|
||||
SH = "sh"
|
||||
CSV = "csv"
|
||||
JSON = "json"
|
||||
JS = "js"
|
||||
CSS = "css"
|
||||
HTML = "html"
|
||||
|
||||
LIB = "lib"
|
||||
PAGE = "page"
|
||||
@ -86,29 +86,33 @@ const ( // DIR
|
||||
PLUGIN = "plugin"
|
||||
STORY = "story"
|
||||
|
||||
INDEX_CSS = "index.css"
|
||||
PROTO_JS = "proto.js"
|
||||
FRAME_JS = "frame.js"
|
||||
INDEX_JS = "index.js"
|
||||
INDEX_SH = "index.sh"
|
||||
INDEX_HTML = "index.html"
|
||||
INDEX_CSS = "index.css"
|
||||
PROTO_JS = "proto.js"
|
||||
FRAME_JS = "frame.js"
|
||||
INDEX_JS = "index.js"
|
||||
INDEX_SH = "index.sh"
|
||||
ICE_BIN = "ice.bin"
|
||||
|
||||
FAVICON_ICO = "/favicon.ico"
|
||||
PLUGIN_INPUT = "/plugin/input/"
|
||||
PLUGIN_STORY = "/plugin/story/"
|
||||
PLUGIN_LOCAL = "/plugin/local/"
|
||||
NODE_MODULES = "node_modules/"
|
||||
PLUGIN_STORY = "/plugin/story/"
|
||||
ISH_PLUGED = ".ish/pluged/"
|
||||
CAN_PLUGIN = "can._plugin"
|
||||
MODULES = "modules"
|
||||
|
||||
USR_NODE_MODULES = "usr/node_modules/"
|
||||
|
||||
USR_VOLCANOS = "usr/volcanos/"
|
||||
USR_LEARNING = "usr/learning/"
|
||||
USR_ICEBERGS = "usr/icebergs/"
|
||||
USR_TOOLKITS = "usr/toolkits/"
|
||||
USR_VOLCANOS = "usr/volcanos/"
|
||||
USR_INTSHELL = "usr/intshell/"
|
||||
USR_INSTALL = "usr/install/"
|
||||
USR_PUBLISH = "usr/publish/"
|
||||
USR_TOOLKITS = "usr/toolkits/"
|
||||
USR_ICEBERGS = "usr/icebergs/"
|
||||
USR_RELEASE = "usr/release/"
|
||||
USR_INSTALL = "usr/install/"
|
||||
USR_REQUIRE = "usr/require/"
|
||||
USR_PUBLISH = "usr/publish/"
|
||||
|
||||
USR_LOCAL = "usr/local/"
|
||||
USR_LOCAL_GO = "usr/local/go/"
|
||||
@ -116,22 +120,21 @@ const ( // DIR
|
||||
USR_LOCAL_BIN = "usr/local/bin/"
|
||||
USR_LOCAL_LIB = "usr/local/lib/"
|
||||
USR_LOCAL_WORK = "usr/local/work/"
|
||||
USR_LOCAL_IMAGE = "usr/local/image/"
|
||||
USR_LOCAL_DAEMON = "usr/local/daemon/"
|
||||
USR_LOCAL_EXPORT = "usr/local/export/"
|
||||
USR_LOCAL_REPOS = "usr/local/repos/"
|
||||
|
||||
USR_LOCAL_IMAGE = "usr/local/image/"
|
||||
USR_LOCAL_EXPORT = "usr/local/export/"
|
||||
USR_LOCAL_DAEMON = "usr/local/daemon/"
|
||||
VAR_LOG_BOOT_LOG = "var/log/boot.log"
|
||||
VAR_LOG_ICE_PID = "var/log/ice.pid"
|
||||
|
||||
VAR_TMP = "var/tmp/"
|
||||
VAR_LOG = "var/log/"
|
||||
VAR_TMP = "var/tmp/"
|
||||
VAR_CONF = "var/conf/"
|
||||
VAR_DATA = "var/data/"
|
||||
VAR_FILE = "var/file/"
|
||||
VAR_PROXY = "var/proxy/"
|
||||
VAR_TRASH = "var/trash/"
|
||||
BIN_ICE_BIN = "bin/ice.bin"
|
||||
BIN_BOOT_LOG = "bin/boot.log"
|
||||
ETC_INIT_SHY = "etc/init.shy"
|
||||
ETC_LOCAL_SHY = "etc/local.shy"
|
||||
ETC_EXIT_SHY = "etc/exit.shy"
|
||||
@ -145,16 +148,14 @@ const ( // DIR
|
||||
SRC_MAIN_SH = "src/main.sh"
|
||||
SRC_MAIN_JS = "src/main.js"
|
||||
SRC_MAIN_GO = "src/main.go"
|
||||
SRC_BINPACK_GO = "src/binpack.go"
|
||||
SRC_VERSION_GO = "src/version.go"
|
||||
SRC_WEBVIEW_GO = "src/webview.go"
|
||||
SRC_VERSION_GO = "src/version.go"
|
||||
SRC_BINPACK_GO = "src/binpack.go"
|
||||
README_MD = "README.md"
|
||||
MAKEFILE = "Makefile"
|
||||
LICENSE = "LICENSE"
|
||||
ICE_BIN = "ice.bin"
|
||||
ICE_PID = "ice.pid"
|
||||
GO_SUM = "go.sum"
|
||||
GO_MOD = "go.mod"
|
||||
GO_SUM = "go.sum"
|
||||
)
|
||||
const ( // MSG
|
||||
MSG_DETAIL = "detail"
|
||||
|
@ -1,6 +1,7 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@ -93,15 +94,16 @@ func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
}
|
||||
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, nfs.MODULE) {
|
||||
mod = kit.Split(line, ice.SP)[1]
|
||||
}
|
||||
kit.If(strings.HasPrefix(line, nfs.MODULE), func() { mod = kit.Split(line, ice.SP)[1] })
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
GIT = "git"
|
||||
|
||||
USR_RELEASE_CONF_GO = "usr/release/conf.go"
|
||||
USR_RELEASE_BINPACK_GO = "usr/release/binpack.go"
|
||||
)
|
||||
const AUTOGEN = "autogen"
|
||||
|
||||
@ -141,31 +143,21 @@ func init() {
|
||||
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.*"))
|
||||
}},
|
||||
DEVPACK: {Help: "开发", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(WEBPACK, mdb.REMOVE) }},
|
||||
WEBPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(WEBPACK, mdb.CREATE) }},
|
||||
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 (
|
||||
CONF_GO = "conf.go"
|
||||
BINPACK_GO = "binpack.go"
|
||||
)
|
||||
m.Cmd(nfs.COPY, ice.USR_RELEASE+CONF_GO, ice.USR_ICEBERGS+CONF_GO)
|
||||
cli.SystemCmds(m, kit.Format(`cat %s|sed 's/package main/package ice/g' > %s`, ice.SRC_BINPACK_GO, ice.USR_RELEASE+BINPACK_GO))
|
||||
m.Cmdy(nfs.DIR, ice.USR_RELEASE+BINPACK_GO)
|
||||
m.Cmdy(nfs.DIR, ice.USR_RELEASE+CONF_GO)
|
||||
nfs.Copy(m, func(buf []byte, offset int) []byte {
|
||||
kit.If(offset == 0, func() { buf = bytes.Replace(buf, []byte("package main"), []byte("package ice"), 1) })
|
||||
return buf
|
||||
}, USR_RELEASE_BINPACK_GO, ice.SRC_BINPACK_GO)
|
||||
m.Cmd(nfs.COPY, USR_RELEASE_CONF_GO, ice.USR_ICEBERGS+"conf.go")
|
||||
m.Cmdy(nfs.DIR, USR_RELEASE_BINPACK_GO)
|
||||
m.Cmdy(nfs.DIR, USR_RELEASE_CONF_GO)
|
||||
}
|
||||
m.Cmdy(nfs.CAT, _autogen_version(m))
|
||||
}},
|
||||
VERSION: {Help: "版本", Hand: func(m *ice.Message, arg ...string) {
|
||||
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))
|
||||
}},
|
||||
|
@ -24,11 +24,11 @@ func _binpack_file(m *ice.Message, w io.Writer, arg ...string) {
|
||||
return
|
||||
}
|
||||
switch path.Base(arg[0]) {
|
||||
case "go.mod", "go.sum":
|
||||
case ice.GO_MOD, ice.GO_SUM:
|
||||
return
|
||||
}
|
||||
switch arg[0] {
|
||||
case ice.SRC_BINPACK_GO, ice.SRC_VERSION_GO, ice.ETC_LOCAL_SHY:
|
||||
case ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO, ice.ETC_LOCAL_SHY:
|
||||
return
|
||||
}
|
||||
if f, e := nfs.OpenFile(m, arg[0]); !m.Warn(e, ice.ErrNotFound, arg[0]) {
|
||||
@ -46,8 +46,8 @@ func _binpack_all(m *ice.Message) {
|
||||
if w, p, e := nfs.CreateFile(m, ice.SRC_BINPACK_GO); m.Assert(e) {
|
||||
defer w.Close()
|
||||
defer m.Echo(p)
|
||||
fmt.Fprintln(w, nfs.Template(m, ice.SRC_BINPACK_GO))
|
||||
defer fmt.Fprintln(w, nfs.Template(m, "binpack_end.go"))
|
||||
fmt.Fprint(w, nfs.Template(m, ice.SRC_BINPACK_GO))
|
||||
defer fmt.Fprint(w, nfs.Template(m, "binpack_end.go"))
|
||||
for _, p := range []string{ice.USR_VOLCANOS, ice.USR_INTSHELL, ice.SRC} {
|
||||
_binpack_dir(m, w, p)
|
||||
}
|
||||
@ -65,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|py|js|css|html)"))).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 {
|
||||
@ -74,12 +74,10 @@ func _binpack_all(m *ice.Message) {
|
||||
})
|
||||
}
|
||||
mdb.HashSelects(m).Sort(nfs.PATH).Tables(func(value ice.Maps) {
|
||||
if s, e := nfs.StatFile(m, value[nfs.PATH]); e == nil {
|
||||
if s.IsDir() {
|
||||
_binpack_dir(m, w, value[nfs.PATH])
|
||||
} else {
|
||||
_binpack_file(m, w, value[nfs.PATH])
|
||||
}
|
||||
if strings.HasSuffix(value[nfs.PATH], ice.PS) {
|
||||
_binpack_dir(m, w, value[nfs.PATH])
|
||||
} else {
|
||||
_binpack_file(m, w, value[nfs.PATH])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -26,5 +26,4 @@ shy.go
|
||||
py.go
|
||||
js.go
|
||||
css.go
|
||||
html.go
|
||||
zml.go
|
||||
html.go
|
@ -43,7 +43,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 webpack devpack", 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 devpack upgrade", 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] {
|
||||
@ -56,6 +56,7 @@ func init() {
|
||||
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) }},
|
||||
UPGRADE: {Help: "升级", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(UPGRADE, nfs.TARGET) }},
|
||||
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)
|
||||
}},
|
||||
@ -75,8 +76,8 @@ func init() {
|
||||
m.Copy(msg)
|
||||
return
|
||||
}
|
||||
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.Logs(COMPILE, nfs.TARGET, file, nfs.SOURCE, main)
|
||||
if m.Cmdy(nfs.DIR, file, "time,path,size,hash,link"); strings.Contains(file, ice.ICE) {
|
||||
m.Cmdy(PUBLISH, ice.CONTEXTS)
|
||||
}
|
||||
}},
|
||||
|
@ -7,6 +7,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"
|
||||
)
|
||||
|
||||
@ -16,10 +17,11 @@ 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) {
|
||||
m.EchoIFrame(kit.MergeURL(path.Join("/require/", arg[2], arg[1]), "_v", kit.Hashs("uniq")))
|
||||
m.EchoIFrame(kit.MergeURL(path.Join(ice.PS, ice.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")))
|
||||
p := kit.MergeURL(path.Join(ice.PS, ice.REQUIRE, arg[2], arg[1]), "_v", kit.Hashs("uniq"))
|
||||
m.EchoIFrame(p).StatusTime(web.LINK, p)
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
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()
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func _install_path(m *ice.Message, link string) string {
|
||||
link = kit.Select(m.Option(mdb.LINK), link)
|
||||
link = strings.Split(kit.Select(m.Option(mdb.LINK), link), ice.QS)[0]
|
||||
if p := path.Join(ice.USR_INSTALL, kit.TrimExt(link)); nfs.ExistsFile(m, p) {
|
||||
return p
|
||||
} else if pp := path.Join(ice.USR_INSTALL, path.Base(link)); nfs.ExistsFile(m, pp) {
|
||||
@ -29,14 +29,12 @@ func _install_path(m *ice.Message, link string) string {
|
||||
}
|
||||
func _install_download(m *ice.Message) {
|
||||
link := m.Option(mdb.LINK)
|
||||
name := path.Base(strings.Split(link, "?")[0])
|
||||
name := path.Base(strings.Split(link, ice.QS)[0])
|
||||
file := path.Join(kit.Select(ice.USR_INSTALL, m.Option(nfs.PATH)), name)
|
||||
defer web.ToastSuccess(m)
|
||||
defer m.Cmdy(nfs.DIR, file)
|
||||
if nfs.ExistsFile(m, file) {
|
||||
m.Cmdy(nfs.DIR, file)
|
||||
return
|
||||
}
|
||||
defer m.SetResult()
|
||||
m.Cmd(nfs.SAVE, file, "")
|
||||
mdb.HashCreate(m, mdb.NAME, name, nfs.PATH, file, mdb.LINK, link)
|
||||
web.GoToast(m, name, func(toast func(string, int, int)) {
|
||||
@ -45,9 +43,16 @@ func _install_download(m *ice.Message) {
|
||||
web.SpideSave(m, file, link, func(count, total, step int) {
|
||||
cost := time.Now().Sub(begin)
|
||||
mdb.HashSelectUpdate(m, name, func(value ice.Map) { value[mdb.COUNT], value[mdb.TOTAL], value[mdb.VALUE] = count, total, step })
|
||||
toast(kit.FormatShow("from", begin.Format("15:04:05"), "cost", kit.FmtDuration(cost), "rest", kit.FmtDuration(cost*time.Duration(101)/time.Duration(step+1)-cost)), count, total)
|
||||
toast(kit.FormatShow(nfs.FROM, begin.Format("15:04:05"), "cost", kit.FmtDuration(cost), "rest", kit.FmtDuration(cost*time.Duration(101)/time.Duration(step+1)-cost)), count, total)
|
||||
})
|
||||
})
|
||||
if s, e := nfs.StatFile(m, file); e == nil && s.Size() > 0 {
|
||||
m.Cmdy(nfs.DIR, file)
|
||||
web.ToastSuccess(m)
|
||||
} else {
|
||||
nfs.Trash(m, file)
|
||||
web.ToastFailure(m)
|
||||
}
|
||||
}
|
||||
func _install_build(m *ice.Message, arg ...string) string {
|
||||
p := m.Option(cli.CMD_DIR, _install_path(m, ""))
|
||||
@ -73,11 +78,8 @@ func _install_build(m *ice.Message, arg ...string) string {
|
||||
func _install_order(m *ice.Message, arg ...string) {
|
||||
p := _install_path(m, "")
|
||||
if m.Option(nfs.PATH) == "" {
|
||||
for _, v := range []string{"_install/bin", "bin", "sbin", ""} {
|
||||
if nfs.ExistsFile(m, path.Join(p, v)) {
|
||||
m.Option(nfs.PATH, v)
|
||||
break
|
||||
}
|
||||
for _, v := range []string{"", "sbin", "bin", "_install/bin"} {
|
||||
kit.If(nfs.ExistsFile(m, path.Join(p, v)), func() { m.Option(nfs.PATH, v) })
|
||||
}
|
||||
}
|
||||
m.Cmdy(cli.SYSTEM, nfs.PUSH, path.Join(p, m.Option(nfs.PATH)))
|
||||
@ -133,11 +135,7 @@ func _install_end(m *ice.Message, arg ...string) {
|
||||
})
|
||||
}
|
||||
func _install_trash(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.DAEMON, func(value ice.Maps) {
|
||||
if value[cli.PID] == m.Option(cli.PID) {
|
||||
m.Cmd(cli.DAEMON, mdb.REMOVE, kit.Dict(mdb.HASH, value[mdb.HASH]))
|
||||
}
|
||||
})
|
||||
_install_trash(m, arg...)
|
||||
nfs.Trash(m, kit.Path(ice.USR_LOCAL_DAEMON, m.Option(tcp.PORT), m.Option(nfs.PATH)))
|
||||
}
|
||||
func _install_service(m *ice.Message, arg ...string) {
|
||||
@ -145,8 +143,7 @@ func _install_service(m *ice.Message, arg ...string) {
|
||||
m.Fields(len(arg[1:]), "time,port,status,pid,cmd,dir")
|
||||
m.Cmd(mdb.SELECT, cli.DAEMON, "", mdb.HASH, func(value ice.Maps) {
|
||||
if strings.Contains(value[ice.CMD], path.Join(ice.BIN, arg[0])) {
|
||||
m.Push("", value, kit.Split(m.OptionFields()))
|
||||
switch value[mdb.STATUS] {
|
||||
switch m.Push("", value, kit.Split(m.OptionFields())); value[mdb.STATUS] {
|
||||
case cli.START:
|
||||
m.PushButton(gdb.DEBUG, cli.STOP)
|
||||
case cli.STOP:
|
||||
@ -168,11 +165,8 @@ const INSTALL = "install"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
INSTALL: {Name: "install name port path:text auto download", Help: "安装", Actions: ice.MergeActions(ice.Actions{
|
||||
nfs.PATH: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_install_path(m, kit.Select("", arg, 0))) }},
|
||||
web.DOWNLOAD: {Name: "download link* path", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_download(m)
|
||||
}},
|
||||
cli.BUILD: {Name: "build link*", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
web.DOWNLOAD: {Name: "download link* path", Hand: func(m *ice.Message, arg ...string) { _install_download(m) }},
|
||||
cli.BUILD: {Name: "build link*", Hand: func(m *ice.Message, arg ...string) {
|
||||
web.PushStream(m)
|
||||
defer m.ProcessHold()
|
||||
if err := _install_build(m, arg...); m.Warn(err != "", err) {
|
||||
@ -181,37 +175,21 @@ func init() {
|
||||
web.ToastSuccess(m, cli.BUILD)
|
||||
}
|
||||
}},
|
||||
cli.ORDER: {Name: "order link* path", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_order(m, arg...)
|
||||
}},
|
||||
cli.SPAWN: {Name: "spawn link*", Help: "新建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_spawn(m, arg...)
|
||||
}},
|
||||
cli.START: {Name: "start link* cmd", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_start(m, arg...)
|
||||
}},
|
||||
cli.STOP: {Help: "停止", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_stop(m, arg...)
|
||||
}},
|
||||
cli.END: {Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_end(m, arg...)
|
||||
}},
|
||||
gdb.DEBUG: {Help: "调试", Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.Process(m, XTERM, []string{mdb.TYPE, "gdb"}, arg...)
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_trash(m, arg...)
|
||||
}},
|
||||
nfs.SOURCE: {Name: "source link* path", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.ORDER: {Name: "order link* path", Hand: func(m *ice.Message, arg ...string) { _install_order(m, arg...) }},
|
||||
cli.SPAWN: {Name: "spawn link*", Hand: func(m *ice.Message, arg ...string) { _install_spawn(m, arg...) }},
|
||||
cli.START: {Name: "start link* cmd", Hand: func(m *ice.Message, arg ...string) { _install_start(m, arg...) }},
|
||||
cli.STOP: {Hand: func(m *ice.Message, arg ...string) { _install_stop(m, arg...) }},
|
||||
cli.END: {Help: "清理", Hand: func(m *ice.Message, arg ...string) { _install_end(m, arg...) }},
|
||||
gdb.DEBUG: {Hand: func(m *ice.Message, arg ...string) { ctx.Process(m, XTERM, []string{mdb.TYPE, "gdb"}, arg...) }},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { _install_trash(m, arg...) }},
|
||||
nfs.PATH: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_install_path(m, kit.Select("", arg, 0))) }},
|
||||
nfs.SOURCE: {Name: "source link* path", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(nfs.DIR_ROOT, path.Join(_install_path(m, ""), _INSTALL)); !nfs.ExistsFile(m, m.Option(nfs.DIR_ROOT)) {
|
||||
m.Option(nfs.DIR_ROOT, path.Join(_install_path(m, "")))
|
||||
}
|
||||
m.Cmdy(nfs.DIR, m.Option(nfs.PATH)).StatusTimeCount(nfs.PATH, m.Option(nfs.DIR_ROOT))
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.Trash(m, m.Option(nfs.PATH))
|
||||
mdb.HashRemove(m)
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { nfs.Trash(mdb.HashRemove(m), m.Option(nfs.PATH)) }},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,count,total,name,path,link")), Hand: func(m *ice.Message, arg ...string) {
|
||||
switch len(arg) {
|
||||
case 0:
|
||||
@ -227,17 +205,11 @@ func init() {
|
||||
|
||||
func InstallAction(args ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...),
|
||||
web.DOWNLOAD: {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INSTALL, web.DOWNLOAD, m.Config(nfs.SOURCE))
|
||||
}},
|
||||
cli.BUILD: {Name: "build", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INSTALL, cli.BUILD, m.Config(nfs.SOURCE))
|
||||
}},
|
||||
cli.ORDER: {Name: "order", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
web.DOWNLOAD: {Help: "下载", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(INSTALL, web.DOWNLOAD, m.Config(nfs.SOURCE)) }},
|
||||
cli.BUILD: {Help: "构建", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(INSTALL, cli.BUILD, m.Config(nfs.SOURCE)) }},
|
||||
cli.ORDER: {Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INSTALL, cli.ORDER, m.Config(nfs.SOURCE), path.Join(_INSTALL, ice.BIN))
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.Trash(m, m.Option(nfs.PATH))
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { nfs.Trash(m, m.Option(nfs.PATH)) }},
|
||||
}
|
||||
}
|
||||
|
@ -45,13 +45,16 @@ func _publish_file(m *ice.Message, file string, arg ...string) string {
|
||||
}
|
||||
func _publish_contexts(m *ice.Message, arg ...string) {
|
||||
for _, k := range kit.Default(arg, ice.MISC) {
|
||||
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) != ""))
|
||||
switch k {
|
||||
case INSTALL:
|
||||
m.Echo(strings.TrimSpace(kit.Renders(m.Config(kit.Keys(ice.CONTEXTS, ice.MISC)), m)))
|
||||
return
|
||||
case ice.BASE:
|
||||
m.Option(web.DOMAIN, m.Cmd(web.SPIDE, ice.SHY).Append(web.CLIENT_ORIGIN))
|
||||
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 s := strings.TrimSpace(kit.Renders(m.Config(kit.Keys(ice.CONTEXTS, k)), m)); k == INSTALL {
|
||||
@ -69,20 +72,25 @@ 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) {
|
||||
_publish_list(m, kit.ExtReg(`(html|css|js)`)).Cmdy("", ice.CONTEXTS, ice.MISC).Echo(ice.NL).EchoQRCode(m.Option(ice.MSG_USERWEB))
|
||||
_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) {
|
||||
_publish_bin_list(m, ice.USR_PUBLISH).Cmdy("", ice.CONTEXTS, ice.CORE)
|
||||
}},
|
||||
ice.INTSHELL: {Help: "神农架", Hand: func(m *ice.Message, arg ...string) {
|
||||
_publish_list(m, kit.ExtReg(`(sh|vim|conf)`)).Cmdy("", ice.CONTEXTS, ice.BASE)
|
||||
_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") }},
|
||||
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)
|
||||
if m.Option(nfs.DIR_ROOT, ice.USR_PUBLISH); len(arg) == 0 {
|
||||
m.Cmdy(nfs.DIR, "", nfs.DIR_WEB_FIELDS).SortTimeR(mdb.TIME)
|
||||
} else {
|
||||
m.OptionFields(mdb.DETAIL)
|
||||
m.Cmdy(nfs.DIR, arg[0], "time,path,size,hash,link,action")
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -21,12 +21,12 @@ func init() {
|
||||
nfs.TARGET, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, ice.BIN, nfs.FILE, ice.ICE_BIN)),
|
||||
nfs.BINARY, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, nfs.TAR, nfs.FILE, "contexts.bin.tar.gz")),
|
||||
nfs.SOURCE, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, nfs.TAR, nfs.FILE, "contexts.src.tar.gz")),
|
||||
))},
|
||||
), mdb.META, kit.Dict(mdb.FIELD, "type,file,path"))},
|
||||
}, Commands: ice.Commands{
|
||||
UPGRADE: {Name: "upgrade item=target,binary,source run restart", Help: "升级", Actions: ice.MergeActions(ice.Actions{
|
||||
cli.RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Go(func() { m.Sleep300ms(ice.EXIT, 1) }) }},
|
||||
}, mdb.ClearHashOnExitAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.ZoneSelect(m, kit.Select(nfs.TARGET, arg, 0)).Tables(func(value ice.Maps) {
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.ZoneSelect(m.Spawn(), kit.Select(nfs.TARGET, arg, 0)).Tables(func(value ice.Maps) {
|
||||
if value[nfs.FILE] == ice.ICE_BIN {
|
||||
value[nfs.FILE] = kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH)
|
||||
defer nfs.Rename(m, value[nfs.FILE], ice.BIN_ICE_BIN)
|
||||
@ -34,11 +34,12 @@ func init() {
|
||||
}
|
||||
dir := kit.Select(kit.Format(value[nfs.FILE]), value[nfs.PATH])
|
||||
switch web.SpideSave(m, dir, "/publish/"+kit.Format(value[nfs.FILE]), nil); value[mdb.TYPE] {
|
||||
case ice.BIN:
|
||||
os.Chmod(dir, 0755)
|
||||
case nfs.TAR:
|
||||
m.Cmd(nfs.TAR, mdb.EXPORT, dir, "-C", path.Dir(dir))
|
||||
case ice.BIN:
|
||||
os.Chmod(dir, 0755)
|
||||
}
|
||||
m.Cmdy(nfs.DIR, dir, "time,path,size,hash")
|
||||
})
|
||||
if web.ToastSuccess(m); m.Option(ice.EXIT) == ice.TRUE {
|
||||
m.Cmd("", cli.RESTART)
|
||||
|
@ -12,33 +12,30 @@ 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"
|
||||
)
|
||||
|
||||
func _volcanos(m *ice.Message, file ...string) string {
|
||||
return path.Join(ice.USR_VOLCANOS, path.Join(file...))
|
||||
}
|
||||
func _publish(m *ice.Message, file ...string) string {
|
||||
return path.Join(ice.USR_PUBLISH, path.Join(file...))
|
||||
}
|
||||
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))
|
||||
func _volcanos(m *ice.Message, p ...string) string { return ice.USR_VOLCANOS + path.Join(p...) }
|
||||
func _publish(m *ice.Message, p ...string) string { return ice.USR_PUBLISH + path.Join(p...) }
|
||||
func _require(m *ice.Message, p string) string {
|
||||
return path.Join(ice.PS, strings.TrimPrefix(strings.Replace(p, ice.USR_NODE_MODULES, web.REQUIRE_MODULES, 1), ice.USR_VOLCANOS))
|
||||
}
|
||||
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/", "usr/node_modules/", 1)))
|
||||
fmt.Fprintln(js, `Volcanos.meta.cache["`+path.Join(ice.PS, p)+`"] = []`)
|
||||
fmt.Fprintln(css, kit.Format("/* %s */", _require(m, p)))
|
||||
fmt.Fprintln(css, m.Cmdx(nfs.CAT, p))
|
||||
_webpack_end(m, js, p)
|
||||
}
|
||||
func _webpack_js(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.TrimPrefix(p, ice.REQUIRE+ice.PS)))
|
||||
fmt.Fprintln(js, `_can_name = "`+_require(m, p)+`";`)
|
||||
fmt.Fprintln(js, m.Cmdx(nfs.CAT, p))
|
||||
}
|
||||
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/", "usr/node_modules/", 1)))
|
||||
fmt.Fprintln(js, `Volcanos.meta.cache["`+path.Join(ice.PS, p)+`"] = []`)
|
||||
_webpack_js(m, js, p)
|
||||
_webpack_end(m, js, p)
|
||||
}
|
||||
func _webpack_end(m *ice.Message, js io.Writer, p string) {
|
||||
fmt.Fprintln(js, `Volcanos.meta.cache["`+_require(m, p)+`"] = []`)
|
||||
}
|
||||
func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
if _, e := nfs.DiskFile.StatFile(ice.USR_VOLCANOS); os.IsNotExist(e) {
|
||||
@ -50,9 +47,6 @@ func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
js, _, e := nfs.CreateFile(m, path.Join(dir, PAGE_CACHE_JS))
|
||||
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
|
||||
}
|
||||
@ -63,7 +57,6 @@ func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
}
|
||||
})
|
||||
}
|
||||
fmt.Fprintln(js)
|
||||
for _, k := range []string{LIB, PANEL, PLUGIN} {
|
||||
nfs.DirDeepAll(m, dir, k, func(value ice.Maps) {
|
||||
if kit.Ext(value[nfs.PATH]) == JS {
|
||||
@ -72,42 +65,31 @@ func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
})
|
||||
}
|
||||
for _, k := range []string{ice.FRAME_JS} {
|
||||
_webpack_js(m, js, k)
|
||||
_webpack_js(m, js, _volcanos(m, k))
|
||||
}
|
||||
m.Option(nfs.DIR_ROOT, "")
|
||||
mdb.HashSelects(m).Sort(nfs.PATH).Tables(func(value ice.Maps) {
|
||||
defer fmt.Fprintln(js)
|
||||
p := value[nfs.PATH]
|
||||
switch kit.Ext(p) {
|
||||
case nfs.CSS:
|
||||
_webpack_css(m, css, js, path.Join(ice.REQUIRE, ice.NODE_MODULES, p))
|
||||
return
|
||||
case nfs.JS:
|
||||
default:
|
||||
p = path.Join(p, LIB, p+".js")
|
||||
defer fmt.Fprintln(js, "")
|
||||
if p := value[nfs.PATH]; kit.Ext(p) == nfs.CSS {
|
||||
_webpack_css(m, css, js, path.Join(ice.USR_NODE_MODULES, p))
|
||||
} else {
|
||||
p = kit.Select(path.Join(p, LIB, kit.Keys(p, JS)), p, kit.Ext(p) == nfs.JS)
|
||||
_webpack_node(m, js, path.Join(ice.USR_NODE_MODULES, p))
|
||||
}
|
||||
_webpack_node(m, js, path.Join(ice.REQUIRE, ice.NODE_MODULES, p))
|
||||
})
|
||||
}
|
||||
func _webpack_build(m *ice.Message, file string) {
|
||||
if f, _, e := nfs.CreateFile(m, kit.Keys(file, JS)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
fmt.Fprintln(f, `Volcanos.meta.webpack = true`)
|
||||
fmt.Fprintln(f, `Volcanos.meta.pack = `+kit.Formats(kit.UnMarshal(kit.Select("{}", m.Option(nfs.CONTENT)))))
|
||||
fmt.Fprintln(f, `Volcanos.meta.args = `+kit.Formats(kit.Dict(m.OptionSimple(kit.Split(m.Option(ctx.ARGS))...))))
|
||||
}
|
||||
if f, p, e := nfs.CreateFile(m, kit.Keys(file, HTML)); m.Assert(e) {
|
||||
func _webpack_can(m *ice.Message) {
|
||||
m.Cmd(nfs.COPY, USR_PUBLISH_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))
|
||||
}
|
||||
func _webpack_build(m *ice.Message, name string) {
|
||||
if f, p, e := nfs.CreateFile(m, kit.Keys(name, HTML)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
defer m.Echo(p)
|
||||
main_js := _volcanos(m, PAGE_INDEX_JS)
|
||||
if nfs.ExistsFile(m, ice.SRC_MAIN_JS) {
|
||||
main_js = ice.SRC_MAIN_JS
|
||||
}
|
||||
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),
|
||||
)
|
||||
fmt.Fprintf(f, nfs.Template(m, ice.INDEX_HTML), m.Cmdx(nfs.CAT, USR_PUBLISH_CAN_CSS), m.Cmdx(nfs.CAT, USR_PUBLISH_CAN_JS), kit.JoinKV(ice.EQ, ice.NL,
|
||||
`Volcanos.meta.args`, kit.Formats(kit.Dict(m.OptionSimple(kit.Split(m.Option(ctx.ARGS))...))),
|
||||
`Volcanos.meta.pack`, kit.Formats(kit.UnMarshal(kit.Select("{}", m.Option(nfs.CONTENT)))),
|
||||
`Volcanos.meta.webpack`, ice.TRUE,
|
||||
)+ice.NL, m.Cmdx(nfs.CAT, ice.SRC_MAIN_JS))
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,9 +100,8 @@ const (
|
||||
PLUGIN = "plugin"
|
||||
)
|
||||
const (
|
||||
PAGE_CACHE_CSS = "page/cache.css"
|
||||
PAGE_INDEX_JS = "page/index.js"
|
||||
PAGE_CACHE_JS = "page/cache.js"
|
||||
PAGE_CACHE_CSS = "page/cache.css"
|
||||
USR_PUBLISH_CAN_CSS = "usr/publish/can.css"
|
||||
USR_PUBLISH_CAN_JS = "usr/publish/can.js"
|
||||
)
|
||||
@ -133,25 +114,25 @@ func init() {
|
||||
WEBPACK: {Name: "webpack path auto create remove", Help: "打包", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Help: "发布", Hand: func(m *ice.Message, arg ...string) {
|
||||
_webpack_cache(m.Spawn(), _volcanos(m), true)
|
||||
_webpack_can(m)
|
||||
m.Cmdy("")
|
||||
}},
|
||||
mdb.REMOVE: {Help: "调试", Hand: func(m *ice.Message, arg ...string) {
|
||||
_webpack_cache(m.Spawn(), _volcanos(m), false)
|
||||
m.Cmdy(nfs.DIR, _volcanos(m, PAGE))
|
||||
}},
|
||||
mdb.INSERT: {Name: "insert path*", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, m.OptionSimple(nfs.PATH))
|
||||
}},
|
||||
cli.BUILD: {Name: "build name*=hi", Hand: func(m *ice.Message, arg ...string) {
|
||||
_webpack_cache(m.Spawn(), _volcanos(m), true)
|
||||
_webpack_build(m, _publish(m, WEBPACK, m.Option(mdb.NAME)))
|
||||
kit.If(!nfs.ExistsFile(m, USR_PUBLISH_CAN_JS), func() { m.Cmd("", mdb.CREATE) })
|
||||
_webpack_build(m, _publish(m, m.Option(mdb.NAME)))
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if !strings.Contains(m.Option(nfs.PATH), "page/index") {
|
||||
nfs.Trash(m, m.Option(nfs.PATH))
|
||||
}
|
||||
kit.If(!strings.Contains(m.Option(nfs.PATH), "/page/"), func() { nfs.Trash(m, m.Option(nfs.PATH)) })
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path"), mdb.ClearHashOnExitAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Options(nfs.DIR_TYPE, nfs.CAT, nfs.DIR_DEEP, ice.TRUE)
|
||||
m.Cmdy(nfs.DIR, _volcanos(m, PAGE)).Cmdy(nfs.DIR, _publish(m, WEBPACK))
|
||||
}, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path")), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DIR, ice.USR_PUBLISH, kit.Dict(nfs.DIR_REG, kit.ExtReg(HTML, CSS, JS))).Cmdy(nfs.DIR, _volcanos(m, PAGE))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user