forked from x/icebergs
opt code
This commit is contained in:
parent
396c088e4d
commit
a3e3d9a82e
@ -83,6 +83,7 @@ const (
|
||||
BACK = "back"
|
||||
FROM = "from"
|
||||
MAIN = "main"
|
||||
KILL = "kill"
|
||||
|
||||
OPEN = "open"
|
||||
CLOSE = "close"
|
||||
@ -113,15 +114,13 @@ func init() {
|
||||
m.Cmdy(DAEMON, kit.Split(m.Option(ice.CMD)))
|
||||
}},
|
||||
RESTART: {Name: "restart", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(DAEMON, STOP)
|
||||
m.Sleep3s()
|
||||
m.Cmdy(DAEMON, START)
|
||||
m.Cmdy(DAEMON, STOP).Sleep3s().Cmdy(DAEMON, START)
|
||||
}},
|
||||
STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionFields(m.Config(mdb.FIELD))
|
||||
m.Cmd(mdb.SELECT, DAEMON, "", mdb.HASH, m.OptionSimple(mdb.HASH)).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, m.OptionSimple(mdb.HASH), STATUS, STOP)
|
||||
m.Cmdy(SYSTEM, "kill", value[PID])
|
||||
m.Cmdy(SYSTEM, KILL, value[PID])
|
||||
})
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
@ -141,7 +141,7 @@ func init() {
|
||||
m.Option(FG, kit.Select(BLUE, arg, 1))
|
||||
|
||||
if m.IsCliUA() {
|
||||
_qrcode_cli(m, kit.Select(m.Conf("share", kit.Keym("domain")), arg, 0))
|
||||
_qrcode_cli(m, kit.Select(ice.Info.Domain, arg, 0))
|
||||
} else {
|
||||
_qrcode_web(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
|
||||
}
|
||||
|
@ -21,11 +21,6 @@ func _runtime_init(m *ice.Message) {
|
||||
m.Conf(RUNTIME, kit.Keys(MAKE, strings.ToLower(key)), value)
|
||||
})
|
||||
|
||||
// 环境变量 conf
|
||||
for _, k := range []string{CTX_SHY, CTX_DEV, CTX_OPS, CTX_ARG, CTX_PID, CTX_USER, CTX_SHARE, CTX_RIVER} {
|
||||
m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k))
|
||||
}
|
||||
|
||||
// 主机信息 host
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOARCH), runtime.GOARCH)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOOS), runtime.GOOS)
|
||||
@ -66,6 +61,11 @@ func _runtime_init(m *ice.Message) {
|
||||
// 启动次数 boot
|
||||
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, ice.BIN), _system_find(m, os.Args[0]))
|
||||
|
||||
// 环境变量 conf
|
||||
for _, k := range []string{CTX_SHY, CTX_DEV, CTX_OPS, CTX_ARG, CTX_PID, CTX_USER, CTX_SHARE, CTX_RIVER} {
|
||||
m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k))
|
||||
}
|
||||
}
|
||||
func _runtime_hostinfo(m *ice.Message) {
|
||||
m.Push("nCPU", strings.Count(m.Cmdx(nfs.CAT, "/proc/cpuinfo"), "processor"))
|
||||
@ -83,9 +83,8 @@ func _runtime_diskinfo(m *ice.Message) {
|
||||
m.Push("", value, head)
|
||||
}
|
||||
})
|
||||
m.Display("/plugin/story/pie.js?field=Size")
|
||||
m.RenameAppend("%iused", "piused")
|
||||
m.RenameAppend("Use%", "Usep")
|
||||
m.RenameAppend("%iused", "piused", "Use%", "Usep")
|
||||
m.DisplayStory("pie.js?field=Size")
|
||||
}
|
||||
|
||||
func NodeInfo(m *ice.Message, kind, name string) {
|
||||
@ -97,17 +96,17 @@ func NodeInfo(m *ice.Message, kind, name string) {
|
||||
const (
|
||||
MAKE = "make"
|
||||
TEST = "test"
|
||||
CONF = "conf"
|
||||
HOST = "host"
|
||||
BOOT = "boot"
|
||||
CONF = "conf"
|
||||
NODE = "node"
|
||||
)
|
||||
const (
|
||||
GOARCH = "GOARCH"
|
||||
X386 = "386"
|
||||
AMD64 = "amd64"
|
||||
ARM64 = "arm64"
|
||||
X386 = "386"
|
||||
ARM = "arm"
|
||||
ARM64 = "arm64"
|
||||
|
||||
GOOS = "GOOS"
|
||||
LINUX = "linux"
|
||||
@ -188,7 +187,7 @@ func init() {
|
||||
m.StatusTimeCount()
|
||||
}},
|
||||
PROCKILL: {Name: "prockill", Help: "结束进程", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SYSTEM, "kill", m.Option("PID"))
|
||||
m.Cmdy(SYSTEM, KILL, m.Option("PID"))
|
||||
m.ProcessRefresh30ms()
|
||||
}},
|
||||
DISKINFO: {Name: "diskinfo", Help: "磁盘信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -21,7 +21,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
// 运行目录
|
||||
if cmd.Dir = m.Option(CMD_DIR); len(cmd.Dir) > 0 {
|
||||
if m.Log_EXPORT(CMD_DIR, cmd.Dir); !kit.FileExists(cmd.Dir) {
|
||||
os.MkdirAll(cmd.Dir, ice.MOD_DIR)
|
||||
nfs.MkdirAll(m, cmd.Dir)
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ func _system_find(m *ice.Message, bin string, dir ...string) string {
|
||||
return bin
|
||||
}
|
||||
if strings.HasPrefix(bin, nfs.PWD) {
|
||||
return kit.Path(bin)
|
||||
return kit.Path(m.Option(CMD_DIR), bin)
|
||||
}
|
||||
if len(dir) == 0 {
|
||||
dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...)
|
||||
@ -107,8 +107,7 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
m.Cost(CODE, cmd.ProcessState.ExitCode(), ctx.ARGS, cmd.Args)
|
||||
}
|
||||
|
||||
m.Push(mdb.TIME, m.Time())
|
||||
m.Push(CODE, int(cmd.ProcessState.ExitCode()))
|
||||
m.Push(mdb.TIME, m.Time()).Push(CODE, int(cmd.ProcessState.ExitCode()))
|
||||
}
|
||||
func IsSuccess(m *ice.Message) bool {
|
||||
return m.Append(CODE) == "0" || m.Append(CODE) == ""
|
||||
|
@ -201,6 +201,10 @@ func Dir(m *ice.Message, sort string) *ice.Message {
|
||||
m.Copy(m.Cmd(DIR, PWD).Sort(sort))
|
||||
return m
|
||||
}
|
||||
func MkdirAll(m *ice.Message, p string) error {
|
||||
m.Log_EXPORT("mkdir", "dir", p)
|
||||
return os.MkdirAll(p, ice.MOD_DIR)
|
||||
}
|
||||
|
||||
const (
|
||||
TYPE_ALL = "all"
|
||||
@ -214,6 +218,10 @@ const (
|
||||
DIR_TYPE = "dir_type"
|
||||
DIR_DEEP = "dir_deep"
|
||||
DIR_REG = "dir_reg"
|
||||
|
||||
DIR_DEF_FIELDS = "time,path,size,action"
|
||||
DIR_WEB_FIELDS = "time,size,path,action,link"
|
||||
DIR_CLI_FIELDS = "path,size,time"
|
||||
)
|
||||
const DIR = "dir"
|
||||
|
||||
@ -251,8 +259,9 @@ func init() {
|
||||
}
|
||||
_dir_list(m, kit.Select(PWD, m.Option(DIR_ROOT)), kit.Select(PWD, arg, 0),
|
||||
0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)),
|
||||
kit.Split(kit.Select(kit.Select("time,path,size,action", m.OptionFields()), kit.Join(kit.Slice(arg, 1)))))
|
||||
kit.Split(kit.Select(kit.Select(DIR_DEF_FIELDS, m.OptionFields()), kit.Join(kit.Slice(arg, 1)))))
|
||||
m.SortTimeR(mdb.TIME)
|
||||
m.StatusTimeCount()
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func _save_file(m *ice.Message, name string, text ...string) {
|
||||
func _push_file(m *ice.Message, name string, text ...string) {
|
||||
p := path.Join(m.Option(DIR_ROOT), name)
|
||||
if strings.Contains(p, ice.PS) {
|
||||
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
||||
MkdirAll(m, path.Dir(p))
|
||||
}
|
||||
|
||||
if f, e := os.OpenFile(p, os.O_WRONLY|os.O_APPEND|os.O_CREATE, ice.MOD_FILE); m.Assert(e) {
|
||||
@ -70,7 +70,7 @@ func _link_file(m *ice.Message, name string, from string) {
|
||||
return
|
||||
}
|
||||
os.Remove(name)
|
||||
os.MkdirAll(path.Dir(name), ice.MOD_DIR)
|
||||
MkdirAll(m, path.Dir(name))
|
||||
if e := os.Link(from, name); e != nil {
|
||||
m.Warn(os.Symlink(from, name), ice.ErrFailure, from)
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -15,7 +16,14 @@ const TAR = "tar"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
TAR: {Name: "tar file path auto", Help: "打包", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
TAR: {Name: "tar file path auto", Help: "打包", Action: map[string]*ice.Action{
|
||||
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("cli.system", "tar", "zcvf", arg)
|
||||
}},
|
||||
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("cli.system", "tar", "xvf", arg)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option("cmd_dir", m.Option(DIR_ROOT))
|
||||
m.Debug("cmd_dir: %v", m.Option("cmd_dir"))
|
||||
m.Cmdy("cli.system", "tar", "zcvf", arg)
|
||||
|
@ -22,7 +22,7 @@ func _trash_create(m *ice.Message, name string) {
|
||||
|
||||
h := kit.Hashs(f)
|
||||
p := path.Join(m.Config(PATH), h[:2], h)
|
||||
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
||||
MkdirAll(m, path.Dir(p))
|
||||
os.Rename(name, p)
|
||||
m.Cmdy(mdb.INSERT, TRASH, "", mdb.HASH, FILE, p, FROM, name)
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func _port_right(m *ice.Message, arg ...string) string {
|
||||
if _, e := os.Stat(p); e == nil {
|
||||
continue
|
||||
}
|
||||
os.MkdirAll(p, ice.MOD_DIR)
|
||||
nfs.MkdirAll(m, p)
|
||||
|
||||
m.Log_SELECT(PORT, i)
|
||||
return m.Config(CURRENT, i)
|
||||
@ -57,10 +57,15 @@ func init() {
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Option(nfs.DIR_ROOT, m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)))
|
||||
m.Cmd(nfs.DIR, nfs.PWD, "time,path,size").Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(nfs.DIR, nfs.PWD, nfs.DIR_CLI_FIELDS).Table(func(index int, value map[string]string, head []string) {
|
||||
bin := m.Cmd(nfs.DIR, path.Join(value[nfs.PATH], ice.BIN), nfs.DIR_CLI_FIELDS).Append(nfs.PATH)
|
||||
if bin == "" {
|
||||
bin = m.Cmd(nfs.DIR, path.Join(value[nfs.PATH], "sbin"), nfs.DIR_CLI_FIELDS).Append(nfs.PATH)
|
||||
}
|
||||
m.Push(mdb.TIME, value[mdb.TIME])
|
||||
m.Push(PORT, path.Base(value[nfs.PATH]))
|
||||
m.Push(nfs.SIZE, value[nfs.SIZE])
|
||||
m.Push(ice.BIN, bin)
|
||||
})
|
||||
m.SortInt(PORT)
|
||||
return
|
||||
|
@ -41,7 +41,7 @@ func _dream_show(m *ice.Message, name string) {
|
||||
if m.Option(nfs.REPOS) != "" { // 下载源码
|
||||
m.Cmd("web.code.git.repos", mdb.CREATE, m.OptionSimple(nfs.REPOS), nfs.PATH, p)
|
||||
} else { // 创建目录
|
||||
os.MkdirAll(p, ice.MOD_DIR)
|
||||
nfs.MkdirAll(m, p)
|
||||
}
|
||||
|
||||
// 任务模板
|
||||
@ -118,6 +118,7 @@ func init() {
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
_dream_list(m)
|
||||
m.Sort("status,type,name")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,6 @@ func _route_list(m *ice.Message) {
|
||||
m.Push(ROUTE, ice.Info.NodeName)
|
||||
m.PushAnchor(tcp.LOCALHOST, kit.Format("%s://%s:%s", u.Scheme, tcp.LOCALHOST, u.Port()))
|
||||
m.PushButton(tcp.START)
|
||||
|
||||
m.Sort(ROUTE)
|
||||
}
|
||||
|
||||
const ROUTE = "route"
|
||||
@ -104,6 +102,7 @@ func init() {
|
||||
if len(arg) == 0 || arg[0] == "" { // 路由列表
|
||||
if _route_travel(m, kit.Select("", arg, 0)); m.W != nil {
|
||||
_route_list(m)
|
||||
m.Sort("type,route")
|
||||
}
|
||||
|
||||
} else if len(arg) == 1 || arg[1] == "" { // 模块列表
|
||||
|
@ -270,6 +270,9 @@ func init() {
|
||||
m.Done(value[cli.STATUS] == tcp.START)
|
||||
})
|
||||
}},
|
||||
DOMAIN: {Name: "domain", Help: "域名", Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.Info.Domain = m.Conf(SHARE, kit.Keym(DOMAIN, m.Config(DOMAIN, arg[0])))
|
||||
}},
|
||||
aaa.BLACK: {Name: "black", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, k := range arg {
|
||||
m.Log_CREATE(aaa.BLACK, k)
|
||||
@ -283,8 +286,8 @@ func init() {
|
||||
}
|
||||
}},
|
||||
cli.START: {Name: "start dev name=ops proto=http host port=9020 nodename password username userrole", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.Info.Address = kit.Select(kit.Format("%s://%s:%s", m.Option(tcp.PROTO),
|
||||
kit.Select(m.Cmd(tcp.HOST).Append(aaa.IP), m.Option(tcp.HOST)), m.Option(tcp.PORT)), ice.Info.Address)
|
||||
ice.Info.Domain = kit.Select(kit.Format("%s://%s:%s", m.Option(tcp.PROTO),
|
||||
kit.Select(m.Cmd(tcp.HOST).Append(aaa.IP), m.Option(tcp.HOST)), m.Option(tcp.PORT)), ice.Info.Domain)
|
||||
if cli.NodeInfo(m, SERVER, kit.Select(ice.Info.HostName, m.Option("nodename"))); m.Option(tcp.PORT) == tcp.RANDOM {
|
||||
m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT))
|
||||
}
|
||||
|
@ -93,6 +93,7 @@ func _share_local(m *ice.Message, arg ...string) {
|
||||
}
|
||||
|
||||
const (
|
||||
TOPIC = "topic"
|
||||
LOGIN = "login"
|
||||
RIVER = "river"
|
||||
STORM = "storm"
|
||||
|
@ -301,7 +301,7 @@ func init() {
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushAnchor(value[mdb.NAME], _space_link(m, kit.Keys(m.Option(ice.MSG_USERPOD), value[mdb.NAME])))
|
||||
})
|
||||
m.SortStrR(mdb.NAME)
|
||||
m.Sort("type,name,text")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
1
conf.go
1
conf.go
@ -143,6 +143,7 @@ const ( // DIR
|
||||
SRC_MAIN_SVG = "src/main.svg"
|
||||
SRC_VERSION_GO = "src/version.go"
|
||||
SRC_BINPACK_GO = "src/binpack.go"
|
||||
SRC_RELAY_GO = "src/relay.go"
|
||||
MAKEFILE = "Makefile"
|
||||
ICE_BIN = "ice.bin"
|
||||
GO_MOD = "go.mod"
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
@ -119,7 +120,7 @@ func init() {
|
||||
}},
|
||||
|
||||
code.WEBPACK: {Name: "webpack", Help: "打包页面", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.WEBPACK, mdb.CREATE, m.OptionSimple(mdb.NAME))
|
||||
m.Cmdy(code.WEBPACK, cli.BUILD, m.OptionSimple(mdb.NAME))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
msg := m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME))
|
||||
|
@ -132,6 +132,7 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, ice.SRC_VERSION_GO)
|
||||
m.Cmdy(nfs.DIR, ice.SRC_BINPACK_GO)
|
||||
m.Cmdy(nfs.DIR, "usr/release/binpack.go")
|
||||
m.Cmdy(nfs.DIR, "usr/release/conf.go")
|
||||
}
|
||||
func _autogen_miss(m *ice.Message) {
|
||||
m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, m.Conf(web.DREAM, kit.Keym("miss")))
|
||||
@ -150,7 +151,7 @@ func init() {
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case MAIN:
|
||||
m.Cmdy(nfs.DIR, ice.SRC, "path,size,time", kit.Dict(nfs.DIR_REG, `.*\.go`)).RenameAppend(nfs.PATH, arg[0])
|
||||
m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, `.*\.go`)).RenameAppend(nfs.PATH, arg[0])
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create main=src/main.go@key zone name=hi help type=Hash,Zone,Lists,Data,Code list key", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -183,16 +184,21 @@ func init() {
|
||||
ssh.SCRIPT: {Name: "script", Help: "脚本:生成 etc/miss.sh", Hand: func(m *ice.Message, arg ...string) {
|
||||
_autogen_miss(m)
|
||||
}},
|
||||
nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.TRASH, path.Join(ice.SRC, m.Option(nfs.PATH)))
|
||||
}},
|
||||
BINPACK: {Name: "binpack", Help: "打包:生成 src/binpack.go", Hand: func(m *ice.Message, arg ...string) {
|
||||
_autogen_version(m)
|
||||
m.Cmdy(WEBPACK, mdb.CREATE)
|
||||
m.Cmd(BINPACK, mdb.CREATE)
|
||||
m.Cmd(cli.SYSTEM, "sh", "-c", `cat src/binpack.go|sed 's/package main/package ice/g' > usr/release/binpack.go`)
|
||||
m.Cmd(nfs.COPY, path.Join(ice.USR_RELEASE, "conf.go"), path.Join(ice.USR_ICEBERGS, "conf.go"))
|
||||
m.Cmd(cli.SYSTEM, "sh", "-c", `cat src/binpack.go|sed 's/package main/package ice/g' > usr/release/binpack.go`)
|
||||
}},
|
||||
"relay": {Name: "relay alias username host port list", Help: "跳板", Hand: func(m *ice.Message, arg ...string) {
|
||||
RELAY: {Name: "relay alias username host port list", Help: "跳板", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(COMPILE, RELAY)
|
||||
m.Cmd(nfs.LINK, path.Join(ice.USR_PUBLISH, m.Option(mdb.ALIAS)), RELAY)
|
||||
m.Cmd(nfs.SAVE, path.Join(kit.Env(cli.HOME), ".ssh/"+m.Option(mdb.ALIAS)+".json"),
|
||||
kit.Formats(kit.Dict(m.OptionSimple("username,host,port,list"))))
|
||||
m.Cmd(nfs.LINK, path.Join(ice.USR_PUBLISH, m.Option(mdb.ALIAS)), "relay")
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Option(nfs.DIR_ROOT, ice.SRC); len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
|
||||
|
@ -16,13 +16,13 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _pack_write(o io.Writer, arg ...string) {
|
||||
func _binpack_write(o io.Writer, arg ...string) {
|
||||
for _, v := range arg {
|
||||
fmt.Fprint(o, v)
|
||||
}
|
||||
fmt.Fprintln(o)
|
||||
}
|
||||
func _pack_file(m *ice.Message, name, file string) string {
|
||||
func _binpack_file(m *ice.Message, name, file string) string {
|
||||
text := ""
|
||||
if f, e := os.Open(file); e == nil {
|
||||
defer f.Close()
|
||||
@ -35,10 +35,10 @@ func _pack_file(m *ice.Message, name, file string) string {
|
||||
}
|
||||
return fmt.Sprintf(" \"%s\": []byte{%s},\n", name, text)
|
||||
}
|
||||
func _pack_dir(m *ice.Message, pack *os.File, dir string) {
|
||||
m.Option(nfs.DIR_DEEP, ice.TRUE)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
func _binpack_dir(m *ice.Message, pack *os.File, dir string) {
|
||||
m.Option(nfs.DIR_ROOT, dir)
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
|
||||
m.Cmd(nfs.DIR, nfs.PWD).Sort(nfs.PATH).Table(func(index int, value map[string]string, head []string) {
|
||||
if path.Base(value[nfs.PATH]) == "binpack.go" {
|
||||
@ -49,29 +49,29 @@ func _pack_dir(m *ice.Message, pack *os.File, dir string) {
|
||||
return
|
||||
}
|
||||
|
||||
pack.WriteString(_pack_file(m, path.Join(dir, value[nfs.PATH]), path.Join(dir, value[nfs.PATH])))
|
||||
pack.WriteString(_binpack_file(m, path.Join(dir, value[nfs.PATH]), path.Join(dir, value[nfs.PATH])))
|
||||
})
|
||||
pack.WriteString(ice.NL)
|
||||
}
|
||||
|
||||
func _pack_volcanos(m *ice.Message, pack *os.File, dir string) {
|
||||
m.Option(nfs.DIR_DEEP, ice.TRUE)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
func _binpack_can(m *ice.Message, pack *os.File, dir string) {
|
||||
m.Option(nfs.DIR_ROOT, dir)
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
|
||||
for _, k := range []string{ice.FAVICON, ice.PROTO_JS, ice.FRAME_JS} {
|
||||
pack.WriteString(_pack_file(m, ice.PS+k, path.Join(dir, k)))
|
||||
pack.WriteString(_binpack_file(m, ice.PS+k, path.Join(dir, k)))
|
||||
}
|
||||
for _, k := range []string{"lib", "page", "panel", "plugin"} {
|
||||
for _, k := range []string{LIB, PAGE, PANEL, PLUGIN} {
|
||||
m.Cmd(nfs.DIR, k).Sort(nfs.PATH).Table(func(index int, value map[string]string, head []string) {
|
||||
pack.WriteString(_pack_file(m, ice.PS+value[nfs.PATH], path.Join(dir, value[nfs.PATH])))
|
||||
pack.WriteString(_binpack_file(m, ice.PS+value[nfs.PATH], path.Join(dir, value[nfs.PATH])))
|
||||
})
|
||||
}
|
||||
pack.WriteString(ice.NL)
|
||||
}
|
||||
func _pack_ctx(m *ice.Message, pack *os.File) {
|
||||
_pack_dir(m, pack, ice.SRC_HELP)
|
||||
_pack_dir(m, pack, ice.SRC)
|
||||
func _binpack_ctx(m *ice.Message, pack *os.File) {
|
||||
_binpack_dir(m, pack, ice.SRC_HELP)
|
||||
_binpack_dir(m, pack, ice.SRC)
|
||||
}
|
||||
|
||||
const BINPACK = "binpack"
|
||||
@ -81,40 +81,34 @@ func init() {
|
||||
BINPACK: {Name: "binpack path auto create remove export", Help: "打包", Action: map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
|
||||
if len(ice.Info.Pack) == 0 {
|
||||
return false
|
||||
}
|
||||
if ice.Dump(w, r.URL.Path, func(name string) { web.RenderType(w, name, "") }) {
|
||||
return true // 打包文件
|
||||
}
|
||||
return false
|
||||
})
|
||||
nfs.AddRewrite(func(msg *ice.Message, name string) []byte {
|
||||
if strings.HasPrefix(name, ice.SRC) {
|
||||
if _, e := os.Stat(name); e == nil {
|
||||
if f, e := os.Open(name); e == nil {
|
||||
defer f.Close()
|
||||
if b, e := ioutil.ReadAll(f); e == nil {
|
||||
m.Logs("local", len(b), name)
|
||||
return b // 本地文件
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(ice.Info.Pack) == 0 {
|
||||
return nil
|
||||
}
|
||||
if strings.HasPrefix(name, ice.SRC) && kit.FileExists(name) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if b, ok := ice.Info.Pack[name]; ok {
|
||||
m.Logs(BINPACK, len(b), name)
|
||||
return b // 打包文件
|
||||
}
|
||||
if b, ok := ice.Info.Pack[strings.TrimPrefix(name, ice.USR_VOLCANOS)]; ok && len(b) > 0 {
|
||||
m.Debug("cat binpack %s", name)
|
||||
m.Logs(BINPACK, len(b), name)
|
||||
return b // 打包文件
|
||||
}
|
||||
if b, ok := ice.Info.Pack[path.Join(m.Option(nfs.DIR_ROOT), name)]; ok && len(b) > 0 {
|
||||
m.Debug("cat binpack %s", name)
|
||||
m.Logs(BINPACK, len(b), name)
|
||||
return b // 打包文件
|
||||
}
|
||||
if b, ok := ice.Info.Pack[path.Join(ice.PS, name)]; ok && len(b) > 0 {
|
||||
m.Debug("cat binpack %s", name)
|
||||
m.Logs(BINPACK, len(b), name)
|
||||
return b // 打包文件
|
||||
}
|
||||
@ -122,27 +116,27 @@ func init() {
|
||||
})
|
||||
}},
|
||||
mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
if pack, p, e := kit.Create(ice.SRC_BINPACK_GO); m.Assert(e) {
|
||||
defer pack.Close()
|
||||
if f, p, e := kit.Create(ice.SRC_BINPACK_GO); m.Assert(e) {
|
||||
defer f.Close()
|
||||
defer m.Echo(p)
|
||||
|
||||
_pack_write(pack, `package main`)
|
||||
_pack_write(pack)
|
||||
_pack_write(pack, `import (`)
|
||||
_pack_write(pack, ` ice "shylinux.com/x/icebergs"`)
|
||||
_pack_write(pack, `)`)
|
||||
_pack_write(pack)
|
||||
_binpack_write(f, `package main`)
|
||||
_binpack_write(f)
|
||||
_binpack_write(f, `import (`)
|
||||
_binpack_write(f, ` ice "shylinux.com/x/icebergs"`)
|
||||
_binpack_write(f, `)`)
|
||||
_binpack_write(f)
|
||||
|
||||
_pack_write(pack, `func init() {`)
|
||||
_pack_write(pack, ` ice.Info.Pack = map[string][]byte{`)
|
||||
_binpack_write(f, `func init() {`)
|
||||
_binpack_write(f, ` ice.Info.Pack = map[string][]byte{`)
|
||||
|
||||
_pack_volcanos(m, pack, ice.USR_VOLCANOS)
|
||||
_pack_dir(m, pack, ice.USR_LEARNING)
|
||||
_pack_dir(m, pack, ice.USR_INTSHELL)
|
||||
_pack_ctx(m, pack)
|
||||
_binpack_dir(m, f, ice.USR_LEARNING)
|
||||
_binpack_can(m, f, ice.USR_VOLCANOS)
|
||||
_binpack_dir(m, f, ice.USR_INTSHELL)
|
||||
_binpack_ctx(m, f)
|
||||
|
||||
_pack_write(pack, ` }`)
|
||||
_pack_write(pack, `}`)
|
||||
_binpack_write(f, ` }`)
|
||||
_binpack_write(f, `}`)
|
||||
}
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -153,14 +147,14 @@ func init() {
|
||||
if strings.HasPrefix(key, ice.PS) {
|
||||
key = ice.USR_VOLCANOS + key
|
||||
}
|
||||
m.Warn(os.MkdirAll(path.Dir(key), ice.MOD_DIR), "mkdir", key)
|
||||
m.Log_EXPORT(nfs.FILE, key, nfs.SIZE, len(value))
|
||||
m.Warn(nfs.MkdirAll(m, path.Dir(key)), "mkdir", key)
|
||||
m.Warn(ioutil.WriteFile(key, value, ice.MOD_FILE), "write", key)
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
for k, v := range ice.Info.Pack {
|
||||
m.Push(mdb.NAME, k)
|
||||
m.Push(nfs.SIZE, len(v))
|
||||
m.Push(mdb.NAME, k).Push(nfs.SIZE, len(v))
|
||||
}
|
||||
m.Sort(mdb.NAME)
|
||||
}},
|
||||
|
@ -13,6 +13,9 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
RELAY = "relay"
|
||||
)
|
||||
const COMPILE = "compile"
|
||||
|
||||
func init() {
|
||||
@ -22,17 +25,15 @@ func init() {
|
||||
cli.ENV, kit.Dict("GOPROXY", "https://goproxy.cn,direct", "GOPRIVATE", "shylinux.com,github.com", "CGO_ENABLED", "0"),
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
COMPILE: {Name: "compile arch=amd64,386,arm,arm64 os=linux,darwin,windows src=src/main.go@key run binpack install", Help: "编译", Action: map[string]*ice.Action{
|
||||
COMPILE: {Name: "compile arch=amd64,386,arm,arm64 os=linux,darwin,windows src=src/main.go@key run binpack relay install", Help: "编译", Action: map[string]*ice.Action{
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DIR, ice.SRC, "path,size,time", kit.Dict(nfs.DIR_REG, `.*\.go$`)).Sort(nfs.PATH)
|
||||
}},
|
||||
BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(AUTOGEN, BINPACK)
|
||||
m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, `.*\.go$`)).Sort(nfs.PATH)
|
||||
}},
|
||||
INSTALL: {Name: "compile", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
if strings.Contains(m.Cmdx(cli.RUNTIME, kit.Keys(tcp.HOST, cli.OSID)), cli.ALPINE) {
|
||||
web.PushStream(m)
|
||||
m.Cmd(cli.SYSTEM, "apk", "add", GIT, GO)
|
||||
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
||||
return
|
||||
}
|
||||
if m.Cmdx(cli.SYSTEM, nfs.FIND, GIT) == "" {
|
||||
@ -42,6 +43,12 @@ func init() {
|
||||
}
|
||||
m.Cmd(INSTALL, web.DOWNLOAD, "https://golang.google.cn/dl/go1.15.5.linux-amd64.tar.gz", ice.USR_LOCAL)
|
||||
}},
|
||||
BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(AUTOGEN, BINPACK)
|
||||
}},
|
||||
RELAY: {Name: "relay", Help: "跳板", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(COMPILE, ice.SRC_RELAY_GO, path.Join(ice.USR_PUBLISH, RELAY))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Cmdx(cli.SYSTEM, nfs.FIND, GO) == "" && m.Cmdx(COMPILE, INSTALL) == ice.FALSE {
|
||||
return
|
||||
@ -80,8 +87,8 @@ func init() {
|
||||
|
||||
// 编译成功
|
||||
m.Log_EXPORT(nfs.SOURCE, main, nfs.TARGET, file)
|
||||
m.Cmdy(PUBLISH, ice.CONTEXTS, "core", "binary")
|
||||
m.Cmdy(nfs.DIR, file, "time,path,size,link")
|
||||
m.Cmdy(nfs.DIR, file, nfs.DIR_WEB_FIELDS)
|
||||
m.Cmdy(PUBLISH, ice.CONTEXTS)
|
||||
m.StatusTimeCount()
|
||||
}},
|
||||
}})
|
||||
|
@ -140,7 +140,7 @@ func init() {
|
||||
if m.Option(ctx.ACTION) == "website" {
|
||||
switch arg[0] {
|
||||
case nfs.FILE:
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, "path,size,time", kit.Dict(nfs.DIR_ROOT, "src/website/")).ProcessAgain()
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_ROOT, "src/website/")).ProcessAgain()
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -148,18 +148,18 @@ func init() {
|
||||
switch arg[0] {
|
||||
case cli.MAIN:
|
||||
m.Option(nfs.DIR_REG, "*.go")
|
||||
m.Cmdy(nfs.DIR, "src/", "path,size,time").ProcessAgain()
|
||||
m.Cmdy(nfs.DIR, "src/", nfs.DIR_CLI_FIELDS).ProcessAgain()
|
||||
case nfs.PATH:
|
||||
m.Cmdy(nfs.DIR, arg[1:], "path,size,time").ProcessAgain()
|
||||
m.Cmdy(nfs.DIR, arg[1:], nfs.DIR_CLI_FIELDS).ProcessAgain()
|
||||
case nfs.FILE:
|
||||
p := kit.Select(nfs.PWD, arg, 1)
|
||||
if !strings.HasSuffix(p, ice.FS) {
|
||||
p = path.Dir(p)
|
||||
}
|
||||
m.Cmdy(nfs.DIR, p+ice.PS, "path,size,time", kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH))).ProcessAgain()
|
||||
m.Cmdy(nfs.DIR, p+ice.PS, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH))).ProcessAgain()
|
||||
case "url":
|
||||
m.Option(nfs.DIR_ROOT, "usr/volcanos/plugin/local/code/")
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, "path,size,time", kit.Dict(nfs.DIR_DEEP, ice.TRUE)).ProcessAgain()
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_DEEP, ice.TRUE)).ProcessAgain()
|
||||
default:
|
||||
m.Cmdy(FAVOR, mdb.INPUTS, arg)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@ -17,20 +16,19 @@ import (
|
||||
|
||||
func _install_download(m *ice.Message) {
|
||||
link := m.Option(mdb.LINK)
|
||||
name := path.Base(link)
|
||||
name := path.Base(strings.Split(link, "?")[0])
|
||||
file := path.Join(kit.Select(m.Config(nfs.PATH), m.Option(nfs.PATH)), name)
|
||||
|
||||
defer m.Cmdy(nfs.DIR, file)
|
||||
if _, e := os.Stat(file); e == nil {
|
||||
if kit.FileExists(file) {
|
||||
return // 文件存在
|
||||
}
|
||||
|
||||
// 创建文件
|
||||
m.Cmd(nfs.SAVE, file, "")
|
||||
|
||||
m.GoToast(web.DOWNLOAD, func(toast func(string, int, int)) {
|
||||
// 进度
|
||||
m.Cmd(mdb.INSERT, INSTALL, "", mdb.HASH, mdb.NAME, name, mdb.LINK, link)
|
||||
m.Cmd(mdb.INSERT, INSTALL, "", mdb.HASH, mdb.NAME, name, nfs.PATH, file, mdb.LINK, link)
|
||||
m.Richs(INSTALL, "", name, func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
|
||||
@ -50,7 +48,8 @@ func _install_download(m *ice.Message) {
|
||||
|
||||
// 解压
|
||||
m.Option(cli.CMD_DIR, path.Dir(file))
|
||||
m.Cmd(cli.SYSTEM, "tar", "xvf", name)
|
||||
m.Cmd(nfs.TAR, mdb.EXPORT, name)
|
||||
m.ToastSuccess()
|
||||
})
|
||||
}
|
||||
func _install_build(m *ice.Message, arg ...string) {
|
||||
@ -98,8 +97,7 @@ func _install_order(m *ice.Message, arg ...string) {
|
||||
}
|
||||
func _install_spawn(m *ice.Message, arg ...string) {
|
||||
if kit.Int(m.Option(tcp.PORT)) >= 10000 {
|
||||
p := path.Join(m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)), m.Option(tcp.PORT))
|
||||
if _, e := os.Stat(p); e == nil {
|
||||
if p := path.Join(m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)), m.Option(tcp.PORT)); kit.FileExists(p) {
|
||||
m.Echo(p)
|
||||
return
|
||||
}
|
||||
@ -109,9 +107,10 @@ func _install_spawn(m *ice.Message, arg ...string) {
|
||||
|
||||
target := path.Join(m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)), m.Option(tcp.PORT))
|
||||
source := path.Join(m.Config(nfs.PATH), kit.TrimExt(m.Option(mdb.LINK)))
|
||||
nfs.MkdirAll(m, target)
|
||||
|
||||
m.Cmd(nfs.DIR, path.Join(source, kit.Select("_install", m.Option("install")))).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(cli.SYSTEM, "cp", "-r", strings.TrimSuffix(value[nfs.PATH], ice.PS), target)
|
||||
m.Cmd(cli.SYSTEM, "cp", "-r", strings.TrimSuffix(value[nfs.PATH], ice.PS), target+ice.PS)
|
||||
})
|
||||
m.Echo(target)
|
||||
}
|
||||
@ -126,10 +125,6 @@ func _install_start(m *ice.Message, arg ...string) {
|
||||
|
||||
m.Cmdy(cli.DAEMON, arg[1:], args)
|
||||
}
|
||||
func _install_package(m *ice.Message, arg ...string) {
|
||||
m.Fields(len(arg), "time,name,path")
|
||||
m.Cmdy(mdb.SELECT, INSTALL, "", mdb.HASH)
|
||||
}
|
||||
func _install_service(m *ice.Message, arg ...string) {
|
||||
arg = kit.Split(path.Base(arg[0]), "-.")[:1]
|
||||
|
||||
@ -153,9 +148,11 @@ const INSTALL = "install"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
INSTALL: {Name: INSTALL, Help: "安装", Value: kit.Data(mdb.SHORT, mdb.NAME, nfs.PATH, ice.USR_INSTALL)},
|
||||
INSTALL: {Name: INSTALL, Help: "安装", Value: kit.Data(
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,path,link", nfs.PATH, ice.USR_INSTALL,
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
INSTALL: {Name: "install name port path auto download compile", Help: "安装", Meta: kit.Dict(), Action: map[string]*ice.Action{
|
||||
INSTALL: {Name: "install name port path auto download", Help: "安装", Meta: kit.Dict(), Action: ice.MergeAction(map[string]*ice.Action{
|
||||
web.DOWNLOAD: {Name: "download link path", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_download(m)
|
||||
}},
|
||||
@ -176,10 +173,10 @@ func init() {
|
||||
defer m.StatusTime(nfs.PATH, m.Option(nfs.DIR_ROOT))
|
||||
m.Cmdy(nfs.DIR, m.Option(nfs.PATH))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch len(arg) {
|
||||
case 0: // 源码列表
|
||||
_install_package(m, arg...)
|
||||
mdb.HashSelect(m, arg...)
|
||||
|
||||
case 1: // 服务列表
|
||||
_install_service(m, arg...)
|
||||
@ -203,5 +200,8 @@ func InstallAction(fields ...string) map[string]*ice.Action {
|
||||
cli.ORDER: {Name: "order", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INSTALL, cli.ORDER, m.Config(nfs.SOURCE), "_install/bin")
|
||||
}},
|
||||
nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.TRASH, m.Option(nfs.PATH))
|
||||
}},
|
||||
}, fields...)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func init() {
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case BINNARY:
|
||||
m.Cmdy(nfs.DIR, "bin/", "path,size,time").RenameAppend(nfs.PATH, BINNARY)
|
||||
m.Cmdy(nfs.DIR, "bin/", nfs.DIR_CLI_FIELDS).RenameAppend(nfs.PATH, BINNARY)
|
||||
case SERVICE:
|
||||
m.Cmd(web.SPIDE).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(SERVICE, kit.MergeURL2(value["client.url"], "/debug/pprof/profile"))
|
||||
|
@ -17,7 +17,31 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _bin_list(m *ice.Message, dir string) {
|
||||
func _publish_file(m *ice.Message, file string, arg ...string) string {
|
||||
if strings.HasSuffix(file, ice.ICE_BIN) { // 打包应用
|
||||
arg = kit.Simple(kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH))
|
||||
file = cli.SystemFind(m, os.Args[0])
|
||||
|
||||
} else if s, e := os.Stat(file); m.Assert(e) && s.IsDir() {
|
||||
p := path.Base(file) + ".tar.gz"
|
||||
m.Cmd(nfs.TAR, mdb.IMPORT, p, file)
|
||||
defer func() { os.Remove(p) }()
|
||||
file = p // 打包目录
|
||||
}
|
||||
|
||||
// 发布文件
|
||||
target := path.Join(m.Config(nfs.PATH), kit.Select(path.Base(file), arg, 0))
|
||||
m.Log_EXPORT(PUBLISH, target, cli.FROM, file)
|
||||
m.Cmd(nfs.LINK, target, file)
|
||||
return target
|
||||
}
|
||||
func _publish_list(m *ice.Message, arg ...string) {
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_ROOT, m.Config(nfs.PATH))
|
||||
m.Option(nfs.DIR_REG, kit.Select("", arg, 0))
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, kit.Select(nfs.DIR_WEB_FIELDS, arg, 1))
|
||||
}
|
||||
func _publish_bin_list(m *ice.Message, dir string) {
|
||||
p := m.Option(cli.CMD_DIR, dir)
|
||||
for _, ls := range strings.Split(strings.TrimSpace(m.Cmd(cli.SYSTEM, "bash", "-c", "ls |xargs file |grep executable").Append(cli.CMD_OUT)), ice.NL) {
|
||||
if file := strings.TrimSpace(strings.Split(ls, ":")[0]); file != "" {
|
||||
@ -32,43 +56,11 @@ func _bin_list(m *ice.Message, dir string) {
|
||||
m.SortTimeR(mdb.TIME)
|
||||
}
|
||||
|
||||
func _publish_file(m *ice.Message, file string, arg ...string) string {
|
||||
if strings.HasSuffix(file, "ice.bin") { // 打包应用
|
||||
arg = kit.Simple(kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH))
|
||||
file = kit.Path(os.Args[0])
|
||||
|
||||
} else if s, e := os.Stat(file); m.Assert(e) && s.IsDir() {
|
||||
p := path.Base(file) + ".tar.gz"
|
||||
m.Cmd(nfs.TAR, p, file)
|
||||
defer func() { os.Remove(p) }()
|
||||
file = p // 打包目录
|
||||
}
|
||||
|
||||
// 发布文件
|
||||
target := path.Join(m.Config(nfs.PATH), kit.Select(path.Base(file), arg, 0))
|
||||
m.Log_EXPORT(PUBLISH, target, "from", file)
|
||||
m.Cmd(nfs.LINK, target, file)
|
||||
return target
|
||||
}
|
||||
func _publish_list(m *ice.Message, arg ...string) {
|
||||
m.Option(nfs.DIR_DEEP, ice.TRUE)
|
||||
m.Option(nfs.DIR_REG, kit.Select("", arg, 0))
|
||||
m.Option(nfs.DIR_ROOT, m.Config(nfs.PATH))
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, kit.Select("time,size,line,path,link", arg, 1))
|
||||
}
|
||||
|
||||
const PUBLISH = "publish"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
PUBLISH: {Name: PUBLISH, Help: "发布", Value: kit.Data(
|
||||
nfs.PATH, ice.USR_PUBLISH, ice.CONTEXTS, _contexts,
|
||||
SH, `#! /bin/sh
|
||||
echo "hello world"
|
||||
`,
|
||||
JS, `Volcanos("onengine", {})
|
||||
`,
|
||||
)},
|
||||
PUBLISH: {Name: PUBLISH, Help: "发布", Value: kit.Data(nfs.PATH, ice.USR_PUBLISH, ice.CONTEXTS, _contexts)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
PUBLISH: {Name: "publish path auto create volcanos icebergs intshell export", Help: "发布", Action: map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -78,24 +70,16 @@ echo "hello world"
|
||||
}},
|
||||
ice.VOLCANOS: {Name: "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.CORE) }()
|
||||
m.Cmd(PUBLISH, mdb.CREATE, nfs.FILE, ice.ETC_MISS_SH)
|
||||
m.Cmd(PUBLISH, mdb.CREATE, nfs.FILE, ice.GO_MOD)
|
||||
|
||||
m.Cmd(nfs.DEFS, path.Join(m.Config(nfs.PATH), ice.ORDER_JS), m.Config(JS))
|
||||
m.Cmd(nfs.DEFS, path.Join(m.Conf(web.SERVE, kit.Keym(ice.VOLCANOS, nfs.PATH)), PAGE_CACHE_JS), "")
|
||||
m.Cmd(nfs.DEFS, path.Join(m.Conf(web.SERVE, kit.Keym(ice.VOLCANOS, nfs.PATH)), PAGE_CACHE_CSS), "")
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS) }()
|
||||
_publish_list(m, `.*\.(html|css|js)$`)
|
||||
}},
|
||||
ice.ICEBERGS: {Name: "icebergs", Help: "冰山架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.BASE) }()
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS) }()
|
||||
m.Cmd(PUBLISH, mdb.CREATE, nfs.FILE, ice.BIN_ICE_BIN)
|
||||
m.Cmd(PUBLISH, mdb.CREATE, nfs.FILE, ice.BIN_ICE_SH)
|
||||
_bin_list(m, m.Config(nfs.PATH))
|
||||
_publish_bin_list(m, m.Config(nfs.PATH))
|
||||
}},
|
||||
ice.INTSHELL: {Name: "intshell", Help: "神农架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.MISC) }()
|
||||
m.Cmd(nfs.DEFS, path.Join(m.Config(nfs.PATH), ice.ORDER_SH), m.Config(SH))
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS) }()
|
||||
_publish_list(m, ".*\\.(sh|vim|conf)$")
|
||||
}},
|
||||
ice.CONTEXTS: {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -104,7 +88,7 @@ echo "hello world"
|
||||
kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(u.Host, ice.DF), 1)))
|
||||
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, "core", "binary")
|
||||
arg = append(arg, ice.CORE, ice.BASE)
|
||||
}
|
||||
for _, k := range arg {
|
||||
if buf, err := kit.Render(m.Config(kit.Keys(ice.CONTEXTS, k)), m); m.Assert(err) {
|
||||
@ -124,7 +108,7 @@ echo "hello world"
|
||||
os.Remove(path.Join(p, m.Option(nfs.PATH)))
|
||||
}},
|
||||
mdb.EXPORT: {Name: "export", Help: "工具链", Hand: func(m *ice.Message, arg ...string) {
|
||||
var list = []string{}
|
||||
var list = []string{ice.USR_LOCAL_LIB}
|
||||
m.Cmd(nfs.CAT, ice.ETC_PATH, func(text string) {
|
||||
if strings.HasPrefix(text, ice.USR_PUBLISH) {
|
||||
return
|
||||
@ -142,11 +126,12 @@ echo "hello world"
|
||||
defer m.ProcessHold()
|
||||
defer m.StatusTimeCount()
|
||||
m.Cmd(nfs.TAR, kit.Path(ice.USR_PUBLISH, "vim.tar.gz"), ".vim/plugged", kit.Dict(nfs.DIR_ROOT, kit.Env(cli.HOME)))
|
||||
m.Cmd(nfs.TAR, kit.Path(ice.USR_PUBLISH, "contexts.lib.tar.gz"), ice.USR_LOCAL_LIB)
|
||||
m.Cmd(nfs.TAR, kit.Path(ice.USR_PUBLISH, "contexts.bin.tar.gz"), list)
|
||||
m.Cmd(PUBLISH, mdb.CREATE, ice.ETC_PATH)
|
||||
|
||||
m.Cmd(PUBLISH, mdb.CREATE, ice.MAKEFILE)
|
||||
m.Cmd(PUBLISH, mdb.CREATE, ice.ETC_MISS_SH)
|
||||
m.Cmd(PUBLISH, mdb.CREATE, ice.SRC_MAIN_GO)
|
||||
m.Cmd(PUBLISH, mdb.CREATE, ice.GO_MOD)
|
||||
m.Cmd(PUBLISH, mdb.CREATE, ice.GO_SUM)
|
||||
|
||||
@ -155,31 +140,22 @@ echo "hello world"
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(nfs.DIR_ROOT, m.Config(nfs.PATH))
|
||||
m.Cmdy(nfs.DIR, kit.Select("", arg, 0), "time,size,path,action,link")
|
||||
m.Cmdy(nfs.DIR, kit.Select("", arg, 0), nfs.DIR_WEB_FIELDS)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
||||
var _contexts = kit.Dict(
|
||||
"misc", `# 终端环境
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp dev
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); wget -O $ctx_temp $ctx_dev; source $ctx_temp dev
|
||||
`,
|
||||
"core", `# 定制版
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -o $ctx_temp -fsSL $ctx_dev; source $ctx_temp app
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); wget -O $ctx_temp $ctx_dev; source $ctx_temp app
|
||||
`,
|
||||
"binary", `# 官方版
|
||||
"base", `# 官方版
|
||||
ctx_temp=$(mktemp); curl -o $ctx_temp -fsSL https://shylinux.com; source $ctx_temp binary
|
||||
ctx_temp=$(mktemp); wget -O $ctx_temp https://shylinux.com; source $ctx_temp binary
|
||||
`,
|
||||
|
||||
"source", `# 下载源码
|
||||
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp source
|
||||
`,
|
||||
"project", `# 创建项目
|
||||
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp project
|
||||
`,
|
||||
"base", `# 开发环境
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp dev
|
||||
`,
|
||||
"misc", `# 终端环境
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp
|
||||
`,
|
||||
)
|
||||
|
@ -2,6 +2,7 @@ package code
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
@ -18,27 +19,37 @@ func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
UPGRADE: {Name: UPGRADE, Help: "升级", Value: kit.Dict(mdb.HASH, kit.Dict(
|
||||
cli.SYSTEM, kit.Dict(mdb.LIST, kit.List(
|
||||
mdb.TYPE, "bin", nfs.FILE, "ice.sh", nfs.PATH, ice.BIN_ICE_SH,
|
||||
mdb.TYPE, "bin", nfs.FILE, "ice.bin", nfs.PATH, ice.BIN_ICE_BIN,
|
||||
)),
|
||||
nfs.BINARY, kit.Dict(mdb.LIST, kit.List(
|
||||
mdb.TYPE, "txt", nfs.FILE, "path", nfs.PATH, ice.ETC_PATH,
|
||||
mdb.TYPE, "tar", nfs.FILE, "contexts.bin.tar.gz",
|
||||
)),
|
||||
nfs.SOURCE, kit.Dict(mdb.LIST, kit.List(
|
||||
mdb.TYPE, "sh", nfs.FILE, "miss.sh", nfs.PATH, ice.ETC_MISS_SH,
|
||||
mdb.TYPE, "txt", nfs.FILE, "main.go", nfs.PATH, ice.SRC_MAIN_GO,
|
||||
mdb.TYPE, "txt", nfs.FILE, "miss.sh", nfs.PATH, ice.ETC_MISS_SH,
|
||||
mdb.TYPE, "txt", nfs.FILE, "go.mod", nfs.PATH, ice.GO_MOD,
|
||||
mdb.TYPE, "txt", nfs.FILE, "go.mod",
|
||||
mdb.TYPE, "txt", nfs.FILE, "go.sum",
|
||||
)),
|
||||
))},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
UPGRADE: {Name: "upgrade item=system,source run", Help: "升级", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
UPGRADE: {Name: "upgrade item=system,binary,source run", Help: "升级", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Grows(cmd, kit.Keys(mdb.HASH, kit.Select(cli.SYSTEM, arg, 0)), "", "", func(index int, value map[string]interface{}) {
|
||||
if value[nfs.PATH] == ice.BIN_ICE_BIN { // 程序文件
|
||||
if value[nfs.FILE] == ice.ICE_BIN { // 程序文件
|
||||
value[nfs.FILE] = kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH)
|
||||
m.Option(ice.EXIT, ice.TRUE)
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
dir := kit.Select(kit.Format(value[nfs.FILE]), value[nfs.PATH])
|
||||
msg := m.Cmd(web.SPIDE, ice.DEV, web.SPIDE_CACHE, web.SPIDE_GET, "/publish/"+kit.Format(value[nfs.FILE]))
|
||||
m.Cmd(web.STORY, web.WATCH, msg.Append(nfs.FILE), value[nfs.PATH])
|
||||
os.Chmod(kit.Format(value[nfs.PATH]), 0770)
|
||||
m.Cmd(web.STORY, web.WATCH, msg.Append(nfs.FILE), dir)
|
||||
switch value[mdb.TYPE] {
|
||||
case "sh", "bin":
|
||||
os.Chmod(kit.Format(dir), 0770)
|
||||
case "tar":
|
||||
m.Cmd(nfs.TAR, mdb.EXPORT, dir, "-C", path.Dir(dir))
|
||||
}
|
||||
})
|
||||
if m.Option(ice.EXIT) == ice.TRUE {
|
||||
m.Sleep("1s").Go(func() { m.Cmd(ice.EXIT, 1) })
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"path"
|
||||
|
||||
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"
|
||||
@ -17,7 +19,90 @@ func _volcanos(m *ice.Message, file ...string) string {
|
||||
func _publish(m *ice.Message, file ...string) string {
|
||||
return path.Join(m.Conf(PUBLISH, kit.Keym(nfs.PATH)), path.Join(file...))
|
||||
}
|
||||
func _webpack_cache(m *ice.Message, dir string) {
|
||||
if len(ice.Info.Pack) > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
css, _, e := kit.Create(path.Join(dir, PAGE_CACHE_CSS))
|
||||
m.Assert(e)
|
||||
defer css.Close()
|
||||
|
||||
js, _, e := kit.Create(path.Join(dir, PAGE_CACHE_JS))
|
||||
m.Assert(e)
|
||||
defer js.Close()
|
||||
|
||||
m.Option(nfs.DIR_ROOT, dir)
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_PACK, true)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
|
||||
for _, k := range []string{LIB, PANEL, PLUGIN} {
|
||||
m.Cmd(nfs.DIR, k).Table(func(index int, value map[string]string, head []string) {
|
||||
if kit.Ext(value[nfs.PATH]) == CSS {
|
||||
js.WriteString(`Volcanos.meta.cache["` + path.Join(ice.PS, value[nfs.PATH]) + "\"] = []\n")
|
||||
css.WriteString(m.Cmdx(nfs.CAT, value[nfs.PATH]))
|
||||
}
|
||||
})
|
||||
}
|
||||
js.WriteString(ice.NL)
|
||||
for _, k := range []string{LIB, PANEL, PLUGIN} {
|
||||
m.Cmd(nfs.DIR, k).Table(func(index int, value map[string]string, head []string) {
|
||||
if kit.Ext(value[nfs.PATH]) == JS {
|
||||
js.WriteString(`_can_name = "` + path.Join(ice.PS, value[nfs.PATH]) + "\";\n")
|
||||
js.WriteString(m.Cmdx(nfs.CAT, value[nfs.PATH]))
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, k := range []string{PUBLISH_ORDER_JS, ice.FRAME_JS} {
|
||||
js.WriteString(`_can_name = "` + path.Join(ice.PS, k) + "\"\n")
|
||||
js.WriteString(m.Cmdx(nfs.CAT, k))
|
||||
}
|
||||
}
|
||||
func _webpack_build(m *ice.Message, file string) {
|
||||
if f, _, e := kit.Create(kit.Keys(file, JS)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
f.WriteString(ice.NL)
|
||||
f.WriteString(kit.Format(`Volcanos.meta.args = %s`, kit.Formats(kit.Dict(m.OptionSimple(kit.Split(m.Option(ctx.ARGS))...)))))
|
||||
f.WriteString(ice.NL)
|
||||
f.WriteString(`Volcanos.meta.webpack = true`)
|
||||
f.WriteString(ice.NL)
|
||||
f.WriteString(`Volcanos.meta.pack = ` + kit.Formats(kit.UnMarshal(kit.Select("{}", m.Option(nfs.CONTENT)))))
|
||||
}
|
||||
|
||||
if f, p, e := kit.Create(kit.Keys(file, HTML)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
defer m.Echo(p)
|
||||
|
||||
f.WriteString(fmt.Sprintf(`
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style type="text/css">%s</style>
|
||||
<style type="text/css">%s</style>
|
||||
</head>
|
||||
<body>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
</body>
|
||||
`,
|
||||
m.Cmdx(nfs.CAT, _volcanos(m, PAGE_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, _volcanos(m, PAGE_INDEX_JS)),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
LIB = "lib"
|
||||
PAGE = "page"
|
||||
PANEL = "panel"
|
||||
PLUGIN = "plugin"
|
||||
)
|
||||
const (
|
||||
PUBLISH_ORDER_JS = "publish/order.js"
|
||||
PAGE_CACHE_CSS = "page/cache.css"
|
||||
@ -33,103 +118,32 @@ const WEBPACK = "webpack"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
WEBPACK: {Name: "webpack path auto create prunes", Help: "打包", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create name=hi", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
dir := _volcanos(m)
|
||||
css, _, e := kit.Create(path.Join(dir, PAGE_CACHE_CSS))
|
||||
m.Assert(e)
|
||||
defer css.Close()
|
||||
|
||||
js, _, e := kit.Create(path.Join(dir, PAGE_CACHE_JS))
|
||||
m.Assert(e)
|
||||
defer js.Close()
|
||||
|
||||
m.Option(nfs.DIR_ROOT, dir)
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_PACK, true)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
|
||||
for _, k := range []string{"lib", "panel", "plugin"} {
|
||||
m.Cmd(nfs.DIR, k).Table(func(index int, value map[string]string, head []string) {
|
||||
if kit.Ext(value[nfs.PATH]) == CSS {
|
||||
js.WriteString(`Volcanos.meta.cache["` + path.Join(ice.PS, value[nfs.PATH]) + "\"] = []\n")
|
||||
css.WriteString(m.Cmdx(nfs.CAT, value[nfs.PATH]))
|
||||
}
|
||||
})
|
||||
}
|
||||
js.WriteString(ice.NL)
|
||||
for _, k := range []string{"lib", "panel", "plugin"} {
|
||||
m.Cmd(nfs.DIR, k).Table(func(index int, value map[string]string, head []string) {
|
||||
if kit.Ext(value[nfs.PATH]) == JS {
|
||||
js.WriteString(`_can_name = "` + path.Join(ice.PS, value[nfs.PATH]) + "\";\n")
|
||||
js.WriteString(m.Cmdx(nfs.CAT, value[nfs.PATH]))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for _, k := range []string{PUBLISH_ORDER_JS, ice.FRAME_JS} {
|
||||
js.WriteString(`_can_name = "` + path.Join(ice.PS, k) + "\"\n")
|
||||
js.WriteString(m.Cmdx(nfs.CAT, k))
|
||||
}
|
||||
|
||||
if f, _, e := kit.Create(_publish(m, WEBPACK, kit.Keys(m.Option(mdb.NAME), JS))); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
f.WriteString(ice.NL)
|
||||
f.WriteString(kit.Format(`Volcanos.meta.args = {river: "%s", storm: "%s"}`, m.Option(web.RIVER), m.Option(web.STORM)))
|
||||
f.WriteString(ice.NL)
|
||||
f.WriteString(`Volcanos.meta.pack = ` + kit.Formats(kit.UnMarshal(kit.Select("{}", m.Option("content")))))
|
||||
}
|
||||
|
||||
m.Option(nfs.DIR_ROOT, "")
|
||||
if f, p, e := kit.Create(_publish(m, WEBPACK, kit.Keys(m.Option(mdb.NAME), HTML))); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
f.WriteString(fmt.Sprintf(_pack,
|
||||
m.Cmdx(nfs.CAT, _volcanos(m, PAGE_CACHE_CSS)),
|
||||
m.Cmdx(nfs.CAT, _volcanos(m, PAGE_INDEX_CSS)),
|
||||
|
||||
m.Cmdx(nfs.CAT, _volcanos(m, ice.PROTO_JS)),
|
||||
m.Cmdx(nfs.CAT, _publish(m, path.Join(WEBPACK, kit.Keys(m.Option(mdb.NAME), JS)))),
|
||||
|
||||
m.Cmdx(nfs.CAT, _volcanos(m, PAGE_CACHE_JS)),
|
||||
m.Cmdx(nfs.CAT, _volcanos(m, PAGE_INDEX_JS)),
|
||||
))
|
||||
m.Echo(p)
|
||||
}
|
||||
|
||||
WEBPACK: {Name: "webpack path auto create remove", Help: "打包", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_webpack_cache(m.Spawn(), _volcanos(m))
|
||||
m.Cmd(nfs.COPY, _volcanos(m, PAGE_CAN_CSS), _volcanos(m, PAGE_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.Cmdy(nfs.DIR, _volcanos(m, PAGE))
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.SAVE, _volcanos(m, PAGE_CACHE_JS))
|
||||
m.Cmd(nfs.SAVE, _volcanos(m, PAGE_CACHE_CSS))
|
||||
|
||||
m.Cmd(nfs.COPY, _volcanos(m, PAGE_CAN_CSS), _volcanos(m, PAGE_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.Cmdy(nfs.DIR, _volcanos(m, PAGE))
|
||||
}},
|
||||
nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.TRASH, _publish(m, m.Option(nfs.PATH)))
|
||||
}},
|
||||
cli.BUILD: {Name: "build name=hi", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_webpack_cache(m.Spawn(), _volcanos(m))
|
||||
_webpack_build(m, _publish(m, WEBPACK, m.Option(mdb.NAME)))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
m.Option(nfs.DIR_ROOT, m.Conf(PUBLISH, kit.Keym(nfs.PATH)))
|
||||
|
||||
m.Cmdy(nfs.DIR, WEBPACK, "time,size,path,action,link")
|
||||
m.Cmdy(nfs.DIR, _volcanos(m, PAGE), nfs.DIR_WEB_FIELDS)
|
||||
m.Cmdy(nfs.DIR, _publish(m, WEBPACK), nfs.DIR_WEB_FIELDS)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
||||
const _pack = `
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style type="text/css">%s</style>
|
||||
<style type="text/css">%s</style>
|
||||
</head>
|
||||
<body>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>Volcanos.meta.webpack = true</script>
|
||||
</body>
|
||||
`
|
||||
|
@ -39,8 +39,8 @@ func init() {
|
||||
ice.DisplayLocal(""),
|
||||
), Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DIR, "src/", kit.Dict(nfs.DIR_DEEP, ice.TRUE, nfs.DIR_REG, ".*\\.shy"), "path,line,time")
|
||||
m.Cmdy(nfs.DIR, "src/help/", kit.Dict(nfs.DIR_DEEP, ice.TRUE, nfs.DIR_REG, ".*\\.shy"), "path,line,time")
|
||||
m.Cmdy(nfs.DIR, "src/", kit.Dict(nfs.DIR_DEEP, ice.TRUE, nfs.DIR_REG, ".*\\.shy"), nfs.DIR_CLI_FIELDS)
|
||||
m.Cmdy(nfs.DIR, "src/help/", kit.Dict(nfs.DIR_DEEP, ice.TRUE, nfs.DIR_REG, ".*\\.shy"), nfs.DIR_CLI_FIELDS)
|
||||
}},
|
||||
web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(arg[0], ctx.ACTION, ice.RUN, arg[2:])
|
||||
|
2
info.go
2
info.go
@ -23,7 +23,7 @@ var Info = struct {
|
||||
UserName string
|
||||
PassWord string
|
||||
|
||||
Address string
|
||||
Domain string
|
||||
NodeType string
|
||||
NodeName string
|
||||
CtxShare string
|
||||
|
2
logs.go
2
logs.go
@ -59,7 +59,7 @@ func (m *Message) join(arg ...interface{}) string {
|
||||
if i == len(args)-1 {
|
||||
list = append(list, args[i])
|
||||
} else {
|
||||
list = append(list, args[i]+kit.Select("", ":", !strings.HasSuffix(strings.TrimSpace(args[i]), ":")), kit.Format(args[i+1]))
|
||||
list = append(list, strings.TrimSpace(args[i])+kit.Select("", DF, !strings.HasSuffix(strings.TrimSpace(args[i]), DF)), kit.Format(args[i+1]))
|
||||
}
|
||||
}
|
||||
return kit.Join(list, SP)
|
||||
|
25
meta.go
25
meta.go
@ -203,6 +203,9 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
|
||||
return m
|
||||
}
|
||||
func (m *Message) Sort(key string, arg ...string) *Message {
|
||||
ls := kit.Split(key)
|
||||
key = ls[0]
|
||||
|
||||
if m.FieldsIsDetail() && key != KEY {
|
||||
return m
|
||||
}
|
||||
@ -234,6 +237,22 @@ func (m *Message) Sort(key string, arg ...string) *Message {
|
||||
number[index] = -int64(kit.Time(line[key]))
|
||||
}
|
||||
})
|
||||
compare := func(i, j int, op string) bool {
|
||||
for k := range ls[1:] {
|
||||
if table[i][ls[k]] == table[j][ls[k]] {
|
||||
continue
|
||||
}
|
||||
|
||||
if op == ">" && table[i][ls[k]] > table[j][ls[k]] {
|
||||
return true
|
||||
}
|
||||
if op == "<" && table[i][ls[k]] < table[j][ls[k]] {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 排序数据
|
||||
for i := 0; i < len(table)-1; i++ {
|
||||
@ -243,14 +262,20 @@ func (m *Message) Sort(key string, arg ...string) *Message {
|
||||
case "", "str":
|
||||
if table[i][key] > table[j][key] {
|
||||
result = true
|
||||
} else if table[i][key] == table[j][key] && compare(i, j, ">") {
|
||||
result = true
|
||||
}
|
||||
case "str_r":
|
||||
if table[i][key] < table[j][key] {
|
||||
result = true
|
||||
} else if table[i][key] == table[j][key] && compare(i, j, "<") {
|
||||
result = true
|
||||
}
|
||||
default:
|
||||
if number[i] > number[j] {
|
||||
result = true
|
||||
} else if table[i][key] == table[j][key] && compare(i, j, ">") {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
|
||||
|
16
misc.go
16
misc.go
@ -116,12 +116,14 @@ func (m *Message) SetResult(arg ...string) *Message {
|
||||
func (m *Message) SetAppend(arg ...string) *Message {
|
||||
return m.Set(MSG_APPEND, arg...)
|
||||
}
|
||||
func (m *Message) RenameAppend(from, to string) *Message {
|
||||
for i, v := range m.meta[MSG_APPEND] {
|
||||
if v == from {
|
||||
m.meta[MSG_APPEND][i] = to
|
||||
m.meta[to] = m.meta[from]
|
||||
delete(m.meta, from)
|
||||
func (m *Message) RenameAppend(arg ...string) *Message { // [from to]...
|
||||
for i := 0; i < len(arg)-1; i += 2 {
|
||||
for j, v := range m.meta[MSG_APPEND] {
|
||||
if v == arg[i] {
|
||||
m.meta[MSG_APPEND][j] = arg[i+1]
|
||||
m.meta[arg[i+1]] = m.meta[arg[i]]
|
||||
delete(m.meta, arg[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
return m
|
||||
@ -154,7 +156,7 @@ func (m *Message) MergeURL2(url string, arg ...interface{}) string {
|
||||
return kit.MergeURL2(m.Option(MSG_USERWEB), url, arg...)
|
||||
}
|
||||
func (m *Message) MergePOD(name string, arg ...interface{}) string {
|
||||
return kit.MergePOD(kit.Select(Info.Address, m.Option(MSG_USERWEB)), name, arg...)
|
||||
return kit.MergePOD(kit.Select(Info.Domain, m.Option(MSG_USERWEB)), name, arg...)
|
||||
}
|
||||
|
||||
func (m *Message) cmd(arg ...interface{}) *Message {
|
||||
|
@ -160,14 +160,15 @@ func init() {
|
||||
}},
|
||||
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(REPOS, ice.OptionFields("time,name,path")).Table(func(index int, value map[string]string, head []string) {
|
||||
remote := strings.Split(m.MergeURL2("/x/"+value[REPOS]), "?")[0]
|
||||
m.Option(cli.CMD_DIR, value[nfs.PATH])
|
||||
m.Cmd(cli.SYSTEM, GIT, PUSH, m.MergeURL2("/x/"+value[mdb.NAME]), MASTER)
|
||||
m.Cmd(cli.SYSTEM, GIT, PUSH, "--tags", m.MergeURL2("/x/"+value[mdb.NAME]), MASTER)
|
||||
m.Cmd(cli.SYSTEM, GIT, PUSH, remote, MASTER)
|
||||
m.Cmd(cli.SYSTEM, GIT, PUSH, "--tags", remote, MASTER)
|
||||
})
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Option(nfs.DIR_ROOT, path.Join(ice.USR_LOCAL, REPOS)); len(arg) == 0 {
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, "time,path,size").Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmdy(nfs.DIR, nfs.PWD).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushScript("git clone " + m.MergeURL2("/x/"+value[nfs.PATH]))
|
||||
})
|
||||
m.StatusTimeCount()
|
||||
|
Loading…
x
Reference in New Issue
Block a user