mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt webpack
This commit is contained in:
parent
a3e3d9a82e
commit
278b016efd
@ -139,6 +139,14 @@ func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
|
||||
const HASH = "hash"
|
||||
|
||||
func AutoConfig(args ...interface{}) *ice.Action {
|
||||
return &ice.Action{Hand: func(m *ice.Message, arg ...string) {
|
||||
if cs := m.Target().Configs; cs[m.CommandKey()] == nil {
|
||||
cs[m.CommandKey()] = &ice.Config{Value: kit.Data(args...)}
|
||||
}
|
||||
}}
|
||||
|
||||
}
|
||||
func HashAction(args ...interface{}) map[string]*ice.Action {
|
||||
_key := func(m *ice.Message) string {
|
||||
if m.Config(HASH) == "uniq" {
|
||||
@ -149,12 +157,7 @@ func HashAction(args ...interface{}) map[string]*ice.Action {
|
||||
}
|
||||
return kit.Select(HASH, m.Config(SHORT))
|
||||
}
|
||||
return ice.SelectAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if cs := m.Target().Configs; cs[m.CommandKey()] == nil {
|
||||
cs[m.CommandKey()] = &ice.Config{Value: kit.Data(args...)}
|
||||
}
|
||||
}},
|
||||
return ice.SelectAction(map[string]*ice.Action{ice.CTX_INIT: AutoConfig(args...),
|
||||
INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INPUTS, m.PrefixKey(), "", HASH, arg)
|
||||
}},
|
||||
|
@ -72,7 +72,9 @@ func _link_file(m *ice.Message, name string, from string) {
|
||||
os.Remove(name)
|
||||
MkdirAll(m, path.Dir(name))
|
||||
if e := os.Link(from, name); e != nil {
|
||||
m.Debug("what %v", e)
|
||||
m.Warn(os.Symlink(from, name), ice.ErrFailure, from)
|
||||
m.Debug("what %v", e)
|
||||
}
|
||||
m.Echo(name)
|
||||
}
|
||||
|
@ -18,10 +18,18 @@ func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
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)
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, arg[0])
|
||||
}
|
||||
if !strings.HasSuffix(arg[0], ".tar.gz") {
|
||||
arg[0] += ".tar.gz"
|
||||
}
|
||||
m.Cmd("cli.system", "tar", "zcvf", arg)
|
||||
m.Echo(arg[0])
|
||||
}},
|
||||
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("cli.system", "tar", "xvf", arg)
|
||||
m.Cmd("cli.system", "tar", "xvf", arg)
|
||||
m.Echo(arg[0])
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option("cmd_dir", m.Option(DIR_ROOT))
|
||||
|
@ -10,19 +10,17 @@ import (
|
||||
)
|
||||
|
||||
func _trash_create(m *ice.Message, name string) {
|
||||
if s, e := os.Stat(name); e == nil {
|
||||
if s, e := os.Stat(name); m.Assert(e) {
|
||||
if s.IsDir() {
|
||||
tar := path.Base(name) + ".tar.gz"
|
||||
m.Cmd(TAR, tar, name)
|
||||
name = tar
|
||||
name = m.Cmdx(TAR, mdb.IMPORT, name)
|
||||
}
|
||||
|
||||
if f, e := os.Open(name); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
h := kit.Hashs(f)
|
||||
p := path.Join(m.Config(PATH), h[:2], h)
|
||||
p := path.Join(m.Config(PATH), kit.HashsPath(f))
|
||||
MkdirAll(m, path.Dir(p))
|
||||
os.Remove(p)
|
||||
os.Rename(name, p)
|
||||
m.Cmdy(mdb.INSERT, TRASH, "", mdb.HASH, FILE, p, FROM, name)
|
||||
}
|
||||
@ -56,7 +54,7 @@ func init() {
|
||||
})
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 || m.Length() > 0 {
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 || !kit.FileExists(arg[0]) {
|
||||
m.PushAction(mdb.REVERT, mdb.REMOVE)
|
||||
return
|
||||
}
|
||||
|
@ -118,7 +118,11 @@ type Buffer struct {
|
||||
}
|
||||
|
||||
func (b *Buffer) Write(buf []byte) (int, error) {
|
||||
b.m.PushNoticeGrow(string(buf))
|
||||
if b.m.IsCliUA() {
|
||||
print(string(buf))
|
||||
} else {
|
||||
b.m.PushNoticeGrow(string(buf))
|
||||
}
|
||||
return len(buf), nil
|
||||
}
|
||||
func (b *Buffer) Close() error { return nil }
|
||||
|
1
conf.go
1
conf.go
@ -14,6 +14,7 @@ const (
|
||||
FALSE = "false"
|
||||
SUCCESS = "success"
|
||||
FAILURE = "failure"
|
||||
RESTART = "restart"
|
||||
PROCESS = "process"
|
||||
OF = " of "
|
||||
|
||||
|
@ -13,12 +13,29 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _defs(m *ice.Message, args ...string) {
|
||||
func _defs(m *ice.Message, args ...string) string {
|
||||
for i := 0; i < len(args); i += 2 {
|
||||
if m.Option(args[i]) == "" {
|
||||
m.Option(args[i], args[i+1])
|
||||
}
|
||||
}
|
||||
return m.Option(args[0])
|
||||
}
|
||||
func _defs_list(m *ice.Message) string {
|
||||
list := []string{mdb.LIST}
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case "Hash":
|
||||
list = append(list, "hash auto create")
|
||||
case "Zone":
|
||||
list = append(list, "zone id auto insert")
|
||||
case "Lists":
|
||||
list = append(list, "id auto insert")
|
||||
case "Data":
|
||||
list = append(list, "path auto")
|
||||
case "Code":
|
||||
list = append(list, "port path auto start order build download")
|
||||
}
|
||||
return _defs(m, mdb.LIST, kit.Join(list, ice.SP))
|
||||
}
|
||||
func _autogen_module(m *ice.Message, dir string) {
|
||||
m.Cmd(nfs.DEFS, dir, `package {{.Option "zone"}}
|
||||
@ -30,7 +47,7 @@ import (
|
||||
type {{.Option "name"}} struct {
|
||||
ice.{{.Option "type"}}
|
||||
|
||||
list string {{.Option "tags"}}
|
||||
list string {{.Option "text"}}
|
||||
}
|
||||
|
||||
func (h {{.Option "name"}}) List(m *ice.Message, arg ...string) {
|
||||
@ -40,30 +57,26 @@ func (h {{.Option "name"}}) List(m *ice.Message, arg ...string) {
|
||||
func init() { ice.Cmd("{{.Option "key"}}", {{.Option "name"}}{}) }
|
||||
`)
|
||||
}
|
||||
func _autogen_import(m *ice.Message, main string, ctx string, mod string) (list []string) {
|
||||
func _autogen_import(m *ice.Message, main string, ctx string, mod string) {
|
||||
m.Cmd(nfs.DEFS, main, `package main
|
||||
|
||||
import "shylinux.com/x/ice"
|
||||
|
||||
func main() { print(ice.Run()) }
|
||||
func main() { println(ice.Run()) }
|
||||
`)
|
||||
|
||||
done := false
|
||||
done, list := false, []string{}
|
||||
m.Cmd(nfs.CAT, main, func(line string, index int) {
|
||||
if list = append(list, line); done {
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(line, "import (") {
|
||||
list = append(list, kit.Format(` _ "%s/src/%s"`, mod, ctx), "")
|
||||
done = true
|
||||
done, list = true, append(list, kit.Format(` _ "%s/src/%s"`, mod, ctx), "")
|
||||
} else if strings.HasPrefix(line, "import") {
|
||||
list = append(list, kit.Format(`import _ "%s/src/%s"`, mod, ctx))
|
||||
done = true
|
||||
done, list = true, append(list, kit.Format(`import _ "%s/src/%s"`, mod, ctx))
|
||||
}
|
||||
})
|
||||
|
||||
m.Cmd(nfs.SAVE, main, kit.Join(list, ice.NL))
|
||||
return
|
||||
}
|
||||
func _autogen_script(m *ice.Message, dir string) {
|
||||
m.Cmd(nfs.DEFS, dir, `chapter "{{.Option "name"}}"
|
||||
@ -71,8 +84,8 @@ func _autogen_script(m *ice.Message, dir string) {
|
||||
field "{{.Option "help"}}" {{.Option "key"}}
|
||||
`)
|
||||
}
|
||||
func _autogen_source(m *ice.Message, zone, name string) {
|
||||
m.Cmd(nfs.PUSH, ice.SRC_MAIN_SHY, ice.NL, nfs.SOURCE+ice.SP+path.Join(zone, kit.Keys(name, SHY)), ice.NL)
|
||||
func _autogen_source(m *ice.Message, main, file string) {
|
||||
m.Cmd(nfs.PUSH, strings.ReplaceAll(main, ice.PT+GO, ice.PT+SHY), ice.NL, strings.TrimPrefix(file, ice.SRC+ice.PS), ice.NL)
|
||||
}
|
||||
func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
m.Cmd(nfs.DEFS, ice.GO_MOD, kit.Format(`module %s
|
||||
@ -80,10 +93,9 @@ func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
go 1.11
|
||||
`, path.Base(kit.Path(""))))
|
||||
|
||||
m.Cmd(nfs.CAT, file, func(line string, index int) {
|
||||
m.Cmd(nfs.CAT, file, func(line string) {
|
||||
if strings.HasPrefix(line, "module") {
|
||||
mod = kit.Split(line, ice.SP)[1]
|
||||
m.Logs("module", mod)
|
||||
}
|
||||
})
|
||||
return
|
||||
@ -106,10 +118,10 @@ func _autogen_gits(m *ice.Message, arg ...string) string {
|
||||
}
|
||||
func _autogen_version(m *ice.Message) {
|
||||
if !kit.FileExists(".git") {
|
||||
m.Cmdy(cli.SYSTEM, "git", "init")
|
||||
m.Cmdy(cli.SYSTEM, GIT, ice.INIT)
|
||||
}
|
||||
if !kit.FileExists("go.mod") {
|
||||
m.Cmdy(cli.SYSTEM, "go", "mod", "init", path.Base(kit.Path("")))
|
||||
m.Cmdy(cli.SYSTEM, GO, "mod", ice.INIT, path.Base(kit.Path("")))
|
||||
}
|
||||
|
||||
m.Cmd(nfs.DEFS, ice.SRC_BINPACK_GO, kit.Format(`package main
|
||||
@ -131,16 +143,6 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, ice.SRC_MAIN_GO)
|
||||
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")))
|
||||
defer m.Cmdy(nfs.CAT, ice.ETC_MISS_SH)
|
||||
|
||||
m.Cmdy(nfs.DIR, ice.ETC_MISS_SH)
|
||||
m.Cmdy(nfs.DIR, ice.GO_MOD)
|
||||
m.Cmdy(nfs.DIR, ice.GO_SUM)
|
||||
}
|
||||
|
||||
const AUTOGEN = "autogen"
|
||||
@ -150,39 +152,32 @@ func init() {
|
||||
AUTOGEN: {Name: "autogen path auto create binpack script relay", Help: "生成", Action: map[string]*ice.Action{
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case MAIN:
|
||||
case cli.MAIN:
|
||||
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) {
|
||||
_defs(m, mdb.ZONE, m.Option(mdb.NAME), mdb.HELP, m.Option(mdb.NAME))
|
||||
_defs(m, mdb.KEY, kit.Keys("web.code", m.Option(mdb.ZONE), m.Option(mdb.NAME)))
|
||||
switch kit.Select("Zone", m.Option(mdb.TYPE)) {
|
||||
case "Hash":
|
||||
_defs(m, mdb.LIST, m.Option(mdb.NAME)+" hash auto create")
|
||||
case "Zone":
|
||||
_defs(m, mdb.LIST, m.Option(mdb.NAME)+" zone id auto insert")
|
||||
case "Lists":
|
||||
_defs(m, mdb.LIST, m.Option(mdb.NAME)+" id auto insert")
|
||||
case "Data":
|
||||
_defs(m, mdb.LIST, m.Option(mdb.NAME)+" path auto")
|
||||
case "Code":
|
||||
_defs(m, mdb.LIST, m.Option(mdb.NAME)+" port path auto start order build download")
|
||||
}
|
||||
m.Option("tags", kit.Format("`name:\"%s\" help:\"%s\"`", m.Option(mdb.LIST), m.Option(mdb.HELP)))
|
||||
m.Option(mdb.TEXT, kit.Format("`name:\"%s\" help:\"%s\"`", _defs_list(m), m.Option(mdb.HELP)))
|
||||
|
||||
if p := path.Join(ice.SRC, m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO)); !kit.FileExists(p) {
|
||||
_autogen_module(m, p)
|
||||
_autogen_import(m, m.Option(MAIN), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD))
|
||||
_autogen_import(m, m.Option(cli.MAIN), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD))
|
||||
}
|
||||
if p := path.Join(ice.SRC, m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), SHY)); !kit.FileExists(p) {
|
||||
_autogen_script(m, p)
|
||||
_autogen_source(m, m.Option(mdb.ZONE), m.Option(mdb.NAME))
|
||||
_autogen_source(m, m.Option(cli.MAIN), p)
|
||||
}
|
||||
m.Option(nfs.FILE, path.Join(m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO)))
|
||||
}},
|
||||
ssh.SCRIPT: {Name: "script", Help: "脚本:生成 etc/miss.sh", Hand: func(m *ice.Message, arg ...string) {
|
||||
_autogen_miss(m)
|
||||
m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, m.Conf(web.DREAM, kit.Keym("miss")))
|
||||
defer m.Cmdy(nfs.CAT, ice.ETC_MISS_SH)
|
||||
|
||||
m.Cmdy(nfs.DIR, ice.ETC_MISS_SH)
|
||||
m.Cmdy(nfs.DIR, ice.GO_MOD)
|
||||
m.Cmdy(nfs.DIR, ice.GO_SUM)
|
||||
}},
|
||||
nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.TRASH, path.Join(ice.SRC, m.Option(nfs.PATH)))
|
||||
@ -190,9 +185,12 @@ func init() {
|
||||
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(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`)
|
||||
if m.Cmd(BINPACK, mdb.CREATE); kit.FileExists(ice.USR_RELEASE) {
|
||||
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`)
|
||||
m.Cmdy(nfs.DIR, "usr/release/binpack.go")
|
||||
m.Cmdy(nfs.DIR, "usr/release/conf.go")
|
||||
}
|
||||
}},
|
||||
RELAY: {Name: "relay alias username host port list", Help: "跳板", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(COMPILE, RELAY)
|
||||
@ -201,11 +199,7 @@ func init() {
|
||||
kit.Formats(kit.Dict(m.OptionSimple("username,host,port,list"))))
|
||||
}},
|
||||
}, 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) {
|
||||
m.Cmdy(nfs.DIR, kit.Select(nfs.PWD, arg, 0))
|
||||
} else {
|
||||
m.Cmdy(nfs.CAT, arg[0])
|
||||
}
|
||||
m.Cmdy(nfs.CAT, arg[0], kit.Dict(nfs.DIR_ROOT, ice.SRC))
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package code
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -16,15 +15,9 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _binpack_write(o io.Writer, arg ...string) {
|
||||
for _, v := range arg {
|
||||
fmt.Fprint(o, v)
|
||||
}
|
||||
fmt.Fprintln(o)
|
||||
}
|
||||
func _binpack_file(m *ice.Message, name, file string) string {
|
||||
func _binpack_file(m *ice.Message, arg ...string) string { // file name
|
||||
text := ""
|
||||
if f, e := os.Open(file); e == nil {
|
||||
if f, e := os.Open(arg[0]); e == nil {
|
||||
defer f.Close()
|
||||
|
||||
if b, e := ioutil.ReadAll(f); e == nil && len(b) > 0 {
|
||||
@ -33,14 +26,14 @@ func _binpack_file(m *ice.Message, name, file string) string {
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf(" \"%s\": []byte{%s},\n", name, text)
|
||||
return fmt.Sprintf(" \"%s\": []byte{%s},", kit.Select(arg[0], arg, 1), text)
|
||||
}
|
||||
func _binpack_dir(m *ice.Message, pack *os.File, dir string) {
|
||||
func _binpack_dir(m *ice.Message, f *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) {
|
||||
m.Cmd(nfs.DIR, nfs.PWD).Sort(nfs.PATH).Tables(func(value map[string]string) {
|
||||
if path.Base(value[nfs.PATH]) == "binpack.go" {
|
||||
return
|
||||
}
|
||||
@ -48,30 +41,29 @@ func _binpack_dir(m *ice.Message, pack *os.File, dir string) {
|
||||
case "pluged", "trash":
|
||||
return
|
||||
}
|
||||
|
||||
pack.WriteString(_binpack_file(m, path.Join(dir, value[nfs.PATH]), path.Join(dir, value[nfs.PATH])))
|
||||
fmt.Fprintln(f, _binpack_file(m, path.Join(dir, value[nfs.PATH])))
|
||||
})
|
||||
pack.WriteString(ice.NL)
|
||||
fmt.Fprintln(f)
|
||||
}
|
||||
|
||||
func _binpack_can(m *ice.Message, pack *os.File, dir string) {
|
||||
func _binpack_can(m *ice.Message, f *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(_binpack_file(m, ice.PS+k, path.Join(dir, k)))
|
||||
fmt.Fprintln(f, _binpack_file(m, path.Join(dir, k), ice.PS+k))
|
||||
}
|
||||
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(_binpack_file(m, ice.PS+value[nfs.PATH], path.Join(dir, value[nfs.PATH])))
|
||||
m.Cmd(nfs.DIR, k).Sort(nfs.PATH).Tables(func(value map[string]string) {
|
||||
fmt.Fprintln(f, _binpack_file(m, path.Join(dir, value[nfs.PATH]), ice.PS+value[nfs.PATH]))
|
||||
})
|
||||
}
|
||||
pack.WriteString(ice.NL)
|
||||
fmt.Fprintln(f)
|
||||
}
|
||||
func _binpack_ctx(m *ice.Message, pack *os.File) {
|
||||
_binpack_dir(m, pack, ice.SRC_HELP)
|
||||
_binpack_dir(m, pack, ice.SRC)
|
||||
func _binpack_ctx(m *ice.Message, f *os.File) {
|
||||
_binpack_dir(m, f, ice.SRC_HELP)
|
||||
_binpack_dir(m, f, ice.SRC)
|
||||
}
|
||||
|
||||
const BINPACK = "binpack"
|
||||
@ -100,7 +92,7 @@ func init() {
|
||||
m.Logs(BINPACK, len(b), name)
|
||||
return b // 打包文件
|
||||
}
|
||||
if b, ok := ice.Info.Pack[strings.TrimPrefix(name, ice.USR_VOLCANOS)]; ok && len(b) > 0 {
|
||||
if b, ok := ice.Info.Pack[path.Join(ice.PS, name)]; ok && len(b) > 0 {
|
||||
m.Logs(BINPACK, len(b), name)
|
||||
return b // 打包文件
|
||||
}
|
||||
@ -108,7 +100,7 @@ func init() {
|
||||
m.Logs(BINPACK, len(b), name)
|
||||
return b // 打包文件
|
||||
}
|
||||
if b, ok := ice.Info.Pack[path.Join(ice.PS, name)]; ok && len(b) > 0 {
|
||||
if b, ok := ice.Info.Pack[strings.TrimPrefix(name, ice.USR_VOLCANOS)]; ok && len(b) > 0 {
|
||||
m.Logs(BINPACK, len(b), name)
|
||||
return b // 打包文件
|
||||
}
|
||||
@ -120,23 +112,23 @@ func init() {
|
||||
defer f.Close()
|
||||
defer m.Echo(p)
|
||||
|
||||
_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)
|
||||
fmt.Fprintln(f, `package main`)
|
||||
fmt.Fprintln(f)
|
||||
fmt.Fprintln(f, `import (`)
|
||||
fmt.Fprintln(f, ` ice "shylinux.com/x/icebergs"`)
|
||||
fmt.Fprintln(f, `)`)
|
||||
fmt.Fprintln(f)
|
||||
|
||||
_binpack_write(f, `func init() {`)
|
||||
_binpack_write(f, ` ice.Info.Pack = map[string][]byte{`)
|
||||
fmt.Fprintln(f, `func init() {`)
|
||||
fmt.Fprintln(f, ` ice.Info.Pack = map[string][]byte{`)
|
||||
|
||||
_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)
|
||||
|
||||
_binpack_write(f, ` }`)
|
||||
_binpack_write(f, `}`)
|
||||
fmt.Fprintln(f, ` }`)
|
||||
fmt.Fprintln(f, `}`)
|
||||
}
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -147,9 +139,7 @@ func init() {
|
||||
if strings.HasPrefix(key, ice.PS) {
|
||||
key = ice.USR_VOLCANOS + 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)
|
||||
m.Log_EXPORT(nfs.FILE, kit.WriteFile(key, value), nfs.SIZE, len(value))
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
@ -66,9 +66,9 @@ func init() {
|
||||
m.Option(cli.CMD_DIR, kit.Select(ice.SRC, arg, 2))
|
||||
m.Cmdy(mdb.SEARCH, MAN2, arg[1:])
|
||||
m.Cmdy(mdb.SEARCH, MAN3, arg[1:])
|
||||
_c_tags(m, kit.Select(MAIN, arg, 1))
|
||||
_go_find(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
_c_tags(m, kit.Select(cli.MAIN, arg, 1))
|
||||
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(cli.CMD_DIR, arg[2])
|
||||
@ -94,7 +94,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
for _, i := range []string{"1", "2", "3", "8"} {
|
||||
if text := _c_help(m, i, kit.Select(MAIN, arg, 1)); text != "" {
|
||||
if text := _c_help(m, i, kit.Select(cli.MAIN, arg, 1)); text != "" {
|
||||
m.PushSearch(ice.CMD, MAN, nfs.FILE, kit.Keys(arg[1], MAN+i), nfs.LINE, 1, mdb.TEXT, text)
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,36 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _compile_target(m *ice.Message, arg ...string) (string, string, string, string) {
|
||||
arch := m.Conf(cli.RUNTIME, kit.Keys(tcp.HOST, cli.GOARCH))
|
||||
goos := m.Conf(cli.RUNTIME, kit.Keys(tcp.HOST, cli.GOOS))
|
||||
main, file := ice.SRC_MAIN_GO, ""
|
||||
for _, k := range arg {
|
||||
switch k {
|
||||
case cli.X386, cli.AMD64, cli.ARM64, cli.ARM:
|
||||
arch = k
|
||||
case cli.WINDOWS, cli.DARWIN, cli.LINUX:
|
||||
goos = k
|
||||
default:
|
||||
if kit.Ext(k) == GO {
|
||||
main = k
|
||||
} else {
|
||||
file = k
|
||||
}
|
||||
}
|
||||
}
|
||||
if file == "" {
|
||||
file = path.Join(m.Config(nfs.PATH), kit.Keys(kit.Select(ice.ICE, kit.TrimExt(main), main != ice.SRC_MAIN_GO), goos, arch))
|
||||
}
|
||||
return main, file, goos, arch
|
||||
}
|
||||
|
||||
const (
|
||||
RELAY = "relay"
|
||||
)
|
||||
const COMPILE = "compile"
|
||||
|
||||
func init() {
|
||||
const GIT = "git"
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
COMPILE: {Name: COMPILE, Help: "编译", Value: kit.Data(nfs.PATH, ice.USR_PUBLISH,
|
||||
cli.ENV, kit.Dict("GOPROXY", "https://goproxy.cn,direct", "GOPRIVATE", "shylinux.com,github.com", "CGO_ENABLED", "0"),
|
||||
@ -53,32 +76,13 @@ func init() {
|
||||
if m.Cmdx(cli.SYSTEM, nfs.FIND, GO) == "" && m.Cmdx(COMPILE, INSTALL) == ice.FALSE {
|
||||
return
|
||||
}
|
||||
|
||||
// 下载依赖
|
||||
_autogen_version(m.Spawn())
|
||||
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
||||
|
||||
// 交叉编译
|
||||
main, file := ice.SRC_MAIN_GO, ""
|
||||
goos := m.Conf(cli.RUNTIME, kit.Keys(tcp.HOST, cli.GOOS))
|
||||
arch := m.Conf(cli.RUNTIME, kit.Keys(tcp.HOST, cli.GOARCH))
|
||||
for _, k := range arg {
|
||||
switch k {
|
||||
case cli.X386, cli.AMD64, cli.ARM64, cli.ARM:
|
||||
arch = k
|
||||
case cli.WINDOWS, cli.DARWIN, cli.LINUX:
|
||||
goos = k
|
||||
default:
|
||||
if kit.Ext(k) == GO {
|
||||
main = k
|
||||
} else {
|
||||
file = k
|
||||
}
|
||||
}
|
||||
}
|
||||
if file == "" {
|
||||
file = path.Join(m.Config(nfs.PATH), kit.Keys(kit.Select(ice.ICE, kit.TrimExt(main), main != ice.SRC_MAIN_GO), goos, arch))
|
||||
}
|
||||
|
||||
// 执行编译
|
||||
_autogen_version(m.Spawn())
|
||||
main, file, goos, arch := _compile_target(m, arg...)
|
||||
m.Optionv(cli.CMD_ENV, kit.Simple(m.Configv(cli.ENV), cli.HOME, kit.Env(cli.HOME), cli.PATH, kit.Env(cli.PATH), cli.GOOS, goos, cli.GOARCH, arch))
|
||||
if msg := m.Cmd(cli.SYSTEM, GO, cli.BUILD, "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) {
|
||||
m.Copy(msg)
|
||||
|
@ -172,7 +172,6 @@ func _mod_show(m *ice.Message, file string) {
|
||||
|
||||
const (
|
||||
TAGS = ".tags"
|
||||
MAIN = "main"
|
||||
)
|
||||
const GO = "go"
|
||||
const MOD = "mod"
|
||||
@ -206,10 +205,10 @@ func init() {
|
||||
GO: {Name: "go", Help: "后端", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == GO {
|
||||
_go_tags(m, kit.Select(MAIN, arg, 1))
|
||||
_go_help(m, kit.Select(MAIN, arg, 1))
|
||||
// _go_find(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
// _go_grep(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
_go_tags(m, kit.Select(cli.MAIN, arg, 1))
|
||||
_go_help(m, kit.Select(cli.MAIN, arg, 1))
|
||||
// _go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
// _go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _go_exec(m, arg...) }},
|
||||
|
@ -27,32 +27,27 @@ func _install_download(m *ice.Message) {
|
||||
// 创建文件
|
||||
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, nfs.PATH, file, mdb.LINK, link)
|
||||
m.Richs(INSTALL, "", name, func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
defer m.ToastSuccess()
|
||||
|
||||
p := 0
|
||||
m.OptionCB(web.SPIDE, func(size int, total int) {
|
||||
if n := size * 100 / total; p != n {
|
||||
value[mdb.VALUE], value[mdb.COUNT], value[mdb.TOTAL] = n, size, total
|
||||
toast(name, size, total)
|
||||
p = n
|
||||
// 下载进度
|
||||
m.Richs(INSTALL, "", name, func(key string, value map[string]interface{}) {
|
||||
prev, value := 0, kit.GetMeta(value)
|
||||
m.OptionCB(web.SPIDE, func(count int, total int, step int) {
|
||||
if step >= prev {
|
||||
value[mdb.COUNT], value[mdb.TOTAL], value[mdb.VALUE] = count, total, step
|
||||
toast(name, count, total)
|
||||
prev = step
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// 下载
|
||||
msg := m.Cmd("web.spide", ice.DEV, web.SPIDE_CACHE, web.SPIDE_GET, link)
|
||||
m.Cmd(nfs.LINK, file, msg.Append(nfs.FILE))
|
||||
|
||||
// 解压
|
||||
m.Option(cli.CMD_DIR, path.Dir(file))
|
||||
m.Cmd(nfs.TAR, mdb.EXPORT, name)
|
||||
m.ToastSuccess()
|
||||
// 下载解压
|
||||
m.Cmd("web.spide", ice.DEV, web.SPIDE_SAVE, file, web.SPIDE_GET, link)
|
||||
m.Cmd(nfs.TAR, mdb.EXPORT, name, kit.Dict(cli.CMD_DIR, path.Dir(file)))
|
||||
})
|
||||
}
|
||||
func _install_build(m *ice.Message, arg ...string) {
|
||||
func _install_build(m *ice.Message, arg ...string) string {
|
||||
p := m.Option(cli.CMD_DIR, path.Join(m.Config(nfs.PATH), kit.TrimExt(m.Option(mdb.LINK))))
|
||||
pp := kit.Path(path.Join(p, "_install"))
|
||||
|
||||
@ -66,27 +61,20 @@ func _install_build(m *ice.Message, arg ...string) {
|
||||
cb(p)
|
||||
default:
|
||||
if msg := m.Cmd(cli.SYSTEM, "./configure", "--prefix="+pp, arg[1:]); !cli.IsSuccess(msg) {
|
||||
m.Echo(msg.Append(cli.CMD_ERR))
|
||||
m.Toast(ice.FAILURE, cli.BUILD)
|
||||
return
|
||||
return msg.Append(cli.CMD_ERR)
|
||||
}
|
||||
}
|
||||
|
||||
// 编译
|
||||
if msg := m.Cmd(cli.SYSTEM, "make", "-j8"); !cli.IsSuccess(msg) {
|
||||
m.Echo(msg.Append(cli.CMD_ERR))
|
||||
m.Toast(ice.FAILURE, cli.BUILD)
|
||||
return
|
||||
if msg := m.Cmd(cli.SYSTEM, cli.MAKE, "-j8"); !cli.IsSuccess(msg) {
|
||||
return msg.Append(cli.CMD_ERR)
|
||||
}
|
||||
|
||||
// 安装
|
||||
if msg := m.Cmd(cli.SYSTEM, "make", "PREFIX="+pp, "install"); !cli.IsSuccess(msg) {
|
||||
m.Echo(msg.Append(cli.CMD_ERR))
|
||||
m.Toast(ice.FAILURE, cli.BUILD)
|
||||
return
|
||||
if msg := m.Cmd(cli.SYSTEM, cli.MAKE, "PREFIX="+pp, INSTALL); !cli.IsSuccess(msg) {
|
||||
return msg.Append(cli.CMD_ERR)
|
||||
}
|
||||
|
||||
m.Toast(ice.SUCCESS, cli.BUILD)
|
||||
return ""
|
||||
}
|
||||
func _install_order(m *ice.Message, arg ...string) {
|
||||
p := path.Join(m.Config(nfs.PATH), kit.TrimExt(m.Option(mdb.LINK)), m.Option(nfs.PATH)+ice.NL)
|
||||
@ -108,11 +96,11 @@ 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)
|
||||
defer m.Echo(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(nfs.DIR, path.Join(source, kit.Select("_install", m.Option(INSTALL)))).Tables(func(value map[string]string) {
|
||||
m.Cmd(cli.SYSTEM, "cp", "-r", strings.TrimSuffix(value[nfs.PATH], ice.PS), target+ice.PS)
|
||||
})
|
||||
m.Echo(target)
|
||||
}
|
||||
func _install_start(m *ice.Message, arg ...string) {
|
||||
p := m.Option(cli.CMD_DIR, m.Cmdx(INSTALL, cli.SPAWN))
|
||||
@ -127,18 +115,13 @@ func _install_start(m *ice.Message, arg ...string) {
|
||||
}
|
||||
func _install_service(m *ice.Message, arg ...string) {
|
||||
arg = kit.Split(path.Base(arg[0]), "-.")[:1]
|
||||
|
||||
m.Fields(len(arg[1:]), "time,port,status,pid,cmd,dir")
|
||||
m.Cmd(mdb.SELECT, cli.DAEMON, "", mdb.HASH).Table(func(index int, value map[string]string, head []string) {
|
||||
if strings.Contains(value[ice.CMD], "bin/"+arg[0]) {
|
||||
m.Cmd(mdb.SELECT, cli.DAEMON, "", mdb.HASH).Tables(func(value map[string]string) {
|
||||
if strings.Contains(value[ice.CMD], path.Join(ice.BIN, arg[0])) {
|
||||
m.Push("", value, kit.Split(m.OptionFields()))
|
||||
}
|
||||
})
|
||||
|
||||
m.Appendv(tcp.PORT, []string{})
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(tcp.PORT, path.Base(value[nfs.DIR]))
|
||||
})
|
||||
m.Set(tcp.PORT).Tables(func(value map[string]string) { m.Push(tcp.PORT, path.Base(value[nfs.DIR])) })
|
||||
}
|
||||
|
||||
const (
|
||||
@ -157,7 +140,12 @@ func init() {
|
||||
_install_download(m)
|
||||
}},
|
||||
cli.BUILD: {Name: "build link", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_build(m, arg...)
|
||||
if err := _install_build(m, arg...); err != "" {
|
||||
m.ToastFailure(cli.BUILD)
|
||||
m.Echo(err)
|
||||
} else {
|
||||
m.ToastSuccess(cli.BUILD)
|
||||
}
|
||||
}},
|
||||
cli.ORDER: {Name: "order link path", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_order(m, arg...)
|
||||
@ -189,8 +177,8 @@ func init() {
|
||||
}})
|
||||
}
|
||||
|
||||
func InstallAction(fields ...string) map[string]*ice.Action {
|
||||
return ice.SelectAction(map[string]*ice.Action{
|
||||
func InstallAction(args ...interface{}) map[string]*ice.Action {
|
||||
return ice.SelectAction(map[string]*ice.Action{ice.CTX_INIT: mdb.AutoConfig(args...),
|
||||
web.DOWNLOAD: {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INSTALL, web.DOWNLOAD, m.Config(nfs.SOURCE))
|
||||
}},
|
||||
@ -203,5 +191,5 @@ func InstallAction(fields ...string) map[string]*ice.Action {
|
||||
nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.TRASH, m.Option(nfs.PATH))
|
||||
}},
|
||||
}, fields...)
|
||||
})
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ func init() {
|
||||
if arg[0] == mdb.FOREACH {
|
||||
return
|
||||
}
|
||||
_go_find(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, NODE, arg[1], kit.Dict(cli.CMD_DIR, arg[2])).SetAppend()
|
||||
|
@ -23,10 +23,8 @@ func _publish_file(m *ice.Message, file string, arg ...string) string {
|
||||
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 // 打包目录
|
||||
file = m.Cmdx(nfs.TAR, mdb.IMPORT, path.Base(file), file)
|
||||
defer func() { os.Remove(file) }()
|
||||
}
|
||||
|
||||
// 发布文件
|
||||
@ -50,12 +48,16 @@ func _publish_bin_list(m *ice.Message, dir string) {
|
||||
m.Push(nfs.SIZE, kit.FmtSize(s.Size()))
|
||||
m.Push(nfs.FILE, file)
|
||||
m.PushDownload(mdb.LINK, file, path.Join(p, file))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
m.SortTimeR(mdb.TIME)
|
||||
}
|
||||
|
||||
const (
|
||||
GIT = "git"
|
||||
)
|
||||
const PUBLISH = "publish"
|
||||
|
||||
func init() {
|
||||
@ -80,7 +82,7 @@ func init() {
|
||||
}},
|
||||
ice.INTSHELL: {Name: "intshell", Help: "神农架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS) }()
|
||||
_publish_list(m, ".*\\.(sh|vim|conf)$")
|
||||
_publish_list(m, `.*\.(sh|vim|conf)$`)
|
||||
}},
|
||||
ice.CONTEXTS: {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) {
|
||||
u := kit.ParseURL(tcp.ReplaceLocalhost(m, m.Option(ice.MSG_USERWEB)))
|
||||
@ -97,18 +99,16 @@ func init() {
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DIR, kit.Select(nfs.PWD, arg, 1))
|
||||
m.ProcessAgain()
|
||||
m.Cmdy(nfs.DIR, kit.Select(nfs.PWD, arg, 1)).ProcessAgain()
|
||||
}},
|
||||
mdb.CREATE: {Name: "create file", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
_publish_file(m, m.Option(nfs.FILE))
|
||||
}},
|
||||
nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
p := m.Option(cli.CMD_DIR, m.Config(nfs.PATH))
|
||||
os.Remove(path.Join(p, m.Option(nfs.PATH)))
|
||||
os.Remove(path.Join(m.Config(nfs.PATH), m.Option(nfs.PATH)))
|
||||
}},
|
||||
mdb.EXPORT: {Name: "export", Help: "工具链", Hand: func(m *ice.Message, arg ...string) {
|
||||
var list = []string{ice.USR_LOCAL_LIB}
|
||||
var list = []string{ice.ETC_PATH}
|
||||
m.Cmd(nfs.CAT, ice.ETC_PATH, func(text string) {
|
||||
if strings.HasPrefix(text, ice.USR_PUBLISH) {
|
||||
return
|
||||
@ -124,19 +124,12 @@ func init() {
|
||||
|
||||
web.PushStream(m)
|
||||
defer m.ProcessHold()
|
||||
defer m.ToastSuccess()
|
||||
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.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)
|
||||
|
||||
m.Cmd(nfs.TAR, kit.Path(ice.USR_PUBLISH, "contexts.src.tar.gz"), ice.MAKEFILE, ice.ETC_MISS_SH, ice.SRC_MAIN_GO, ice.GO_MOD, ice.GO_SUM)
|
||||
m.Cmd(nfs.TAR, kit.Path(ice.USR_PUBLISH, "contexts.home.tar.gz"), ".vim/plugged", kit.Dict(nfs.DIR_ROOT, kit.Env(cli.HOME)))
|
||||
m.Cmd("web.code.git.server", mdb.IMPORT)
|
||||
m.ToastSuccess()
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(nfs.DIR_ROOT, m.Config(nfs.PATH))
|
||||
|
@ -25,8 +25,8 @@ func init() {
|
||||
m.Option(cli.CMD_DIR, kit.Select(ice.SRC, arg, 2))
|
||||
m.Cmdy(mdb.SEARCH, MAN1, arg[1:])
|
||||
m.Cmdy(mdb.SEARCH, MAN8, arg[1:])
|
||||
_go_find(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, SH, arg[1], kit.Dict(cli.CMD_DIR, arg[2])).SetAppend()
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -22,8 +23,8 @@ func init() {
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == SHY {
|
||||
_go_find(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(MAIN, arg, 1), arg[2])
|
||||
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -60,8 +61,8 @@ func init() { ice.Cmd("{{.Option "key"}}", {{.Option "name"}}{}) }
|
||||
m.Cmd(nfs.DEFS, path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)), string(buf))
|
||||
switch kit.Ext(m.Option(nfs.FILE)) {
|
||||
case GO:
|
||||
if m.Option(MAIN) != "" && m.Option(mdb.ZONE) != "" {
|
||||
_autogen_import(m, path.Join(m.Option(nfs.PATH), m.Option(MAIN)), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD))
|
||||
if m.Option(cli.MAIN) != "" && m.Option(mdb.ZONE) != "" {
|
||||
_autogen_import(m, path.Join(m.Option(nfs.PATH), m.Option(cli.MAIN)), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,41 +18,36 @@ const UPGRADE = "upgrade"
|
||||
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.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, "go.mod",
|
||||
mdb.TYPE, "txt", nfs.FILE, "go.sum",
|
||||
)),
|
||||
nfs.TARGET, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, "bin", nfs.FILE, "ice.bin")),
|
||||
nfs.SOURCE, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, "tar", nfs.FILE, "contexts.src.tar.gz")),
|
||||
nfs.BINARY, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, "tar", nfs.FILE, "contexts.bin.tar.gz")),
|
||||
))},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
UPGRADE: {Name: "upgrade item=system,binary,source run", Help: "升级", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
UPGRADE: {Name: "upgrade item=target,source,binary run restart", Help: "升级", Action: map[string]*ice.Action{
|
||||
cli.RESTART: {Name: "restart", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Sleep("1s").Go(func() { m.Cmd(ice.EXIT, 1) })
|
||||
}},
|
||||
}, 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.FILE] == ice.ICE_BIN { // 程序文件
|
||||
value[nfs.FILE] = kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH)
|
||||
defer m.Cmd(cli.SYSTEM, "mv", value[nfs.FILE], ice.BIN_ICE_BIN)
|
||||
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), dir)
|
||||
m.Cmd(web.SPIDE, ice.DEV, web.SPIDE_SAVE, dir, web.SPIDE_GET, "/publish/"+kit.Format(value[nfs.FILE]))
|
||||
switch value[mdb.TYPE] {
|
||||
case "sh", "bin":
|
||||
os.Chmod(kit.Format(dir), 0770)
|
||||
case "bin":
|
||||
os.Chmod(dir, 0755)
|
||||
case "tar":
|
||||
m.Cmd(nfs.TAR, mdb.EXPORT, dir, "-C", path.Dir(dir))
|
||||
}
|
||||
})
|
||||
if m.Option(ice.EXIT) == ice.TRUE {
|
||||
if m.ToastSuccess(); m.Option(ice.EXIT) == ice.TRUE {
|
||||
m.Sleep("1s").Go(func() { m.Cmd(ice.EXIT, 1) })
|
||||
m.ToastRestart()
|
||||
}
|
||||
}},
|
||||
}})
|
||||
|
@ -3,23 +3,28 @@ package code
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _volcanos(m *ice.Message, file ...string) string {
|
||||
return path.Join(m.Conf(web.SERVE, kit.Keym(ice.VOLCANOS, nfs.PATH)), path.Join(file...))
|
||||
return path.Join(ice.USR_VOLCANOS, path.Join(file...))
|
||||
}
|
||||
func _publish(m *ice.Message, file ...string) string {
|
||||
return path.Join(m.Conf(PUBLISH, kit.Keym(nfs.PATH)), path.Join(file...))
|
||||
return path.Join(ice.USR_PUBLISH, path.Join(file...))
|
||||
}
|
||||
func _webpack_cache(m *ice.Message, dir string) {
|
||||
func _webpack_can(m *ice.Message) {
|
||||
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))
|
||||
}
|
||||
func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
if len(ice.Info.Pack) > 0 {
|
||||
return
|
||||
}
|
||||
@ -32,49 +37,51 @@ func _webpack_cache(m *ice.Message, dir string) {
|
||||
m.Assert(e)
|
||||
defer js.Close()
|
||||
|
||||
defer _webpack_can(m)
|
||||
if !write {
|
||||
return
|
||||
}
|
||||
|
||||
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) {
|
||||
m.Cmd(nfs.DIR, k).Tables(func(value map[string]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]))
|
||||
fmt.Fprintln(css, m.Cmdx(nfs.CAT, value[nfs.PATH]))
|
||||
fmt.Fprintln(js, `Volcanos.meta.cache["`+path.Join(ice.PS, value[nfs.PATH])+`"] = []`)
|
||||
}
|
||||
})
|
||||
}
|
||||
js.WriteString(ice.NL)
|
||||
fmt.Fprintln(js)
|
||||
for _, k := range []string{LIB, PANEL, PLUGIN} {
|
||||
m.Cmd(nfs.DIR, k).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(nfs.DIR, k).Tables(func(value map[string]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]))
|
||||
fmt.Fprintln(js, `_can_name = "`+path.Join(ice.PS, value[nfs.PATH])+`"`)
|
||||
fmt.Fprintln(js, 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))
|
||||
fmt.Fprintln(js, `_can_name = "`+path.Join(ice.PS, k)+`"`)
|
||||
fmt.Fprintln(js, 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)))))
|
||||
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 := kit.Create(kit.Keys(file, HTML)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
defer m.Echo(p)
|
||||
|
||||
f.WriteString(fmt.Sprintf(`
|
||||
fmt.Fprintf(f, `
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
@ -93,7 +100,7 @@ func _webpack_build(m *ice.Message, file string) {
|
||||
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)),
|
||||
))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,8 +112,8 @@ const (
|
||||
)
|
||||
const (
|
||||
PUBLISH_ORDER_JS = "publish/order.js"
|
||||
PAGE_CACHE_CSS = "page/cache.css"
|
||||
PAGE_INDEX_CSS = "page/index.css"
|
||||
PAGE_CACHE_CSS = "page/cache.css"
|
||||
PAGE_CACHE_JS = "page/cache.js"
|
||||
PAGE_INDEX_JS = "page/index.js"
|
||||
PAGE_CAN_CSS = "page/can.css"
|
||||
@ -120,30 +127,26 @@ func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
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))
|
||||
_webpack_cache(m.Spawn(), _volcanos(m), true)
|
||||
}},
|
||||
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))
|
||||
_webpack_cache(m.Spawn(), _volcanos(m), false)
|
||||
}},
|
||||
nfs.TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.TRASH, _publish(m, m.Option(nfs.PATH)))
|
||||
if !strings.Contains(m.Option(nfs.PATH), "page/index") {
|
||||
m.Cmd(nfs.TRASH, 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_cache(m.Spawn(), _volcanos(m), true)
|
||||
_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.Cmdy(nfs.DIR, _volcanos(m, PAGE), nfs.DIR_WEB_FIELDS)
|
||||
m.Cmdy(nfs.DIR, _publish(m, WEBPACK), nfs.DIR_WEB_FIELDS)
|
||||
m.OptionFields(nfs.DIR_WEB_FIELDS)
|
||||
m.Cmdy(nfs.DIR, _volcanos(m, PAGE))
|
||||
m.Cmdy(nfs.DIR, _publish(m, WEBPACK))
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
7
meta.go
7
meta.go
@ -297,6 +297,13 @@ func (m *Message) Sort(key string, arg ...string) *Message {
|
||||
}
|
||||
return m
|
||||
}
|
||||
func (m *Message) Tables(cbs ...func(value map[string]string)) *Message {
|
||||
return m.Table(func(index int, value map[string]string, head []string) {
|
||||
for _, cb := range cbs {
|
||||
cb(value)
|
||||
}
|
||||
})
|
||||
}
|
||||
func (m *Message) Table(cbs ...func(index int, value map[string]string, head []string)) *Message {
|
||||
if len(cbs) > 0 && cbs[0] != nil {
|
||||
if m.FieldsIsDetail() {
|
||||
|
@ -169,7 +169,7 @@ func init() {
|
||||
}, 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).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushScript("git clone " + m.MergeURL2("/x/"+value[nfs.PATH]))
|
||||
m.PushScript("git clone " + m.MergeLink("/x/"+strings.TrimSuffix(value[nfs.PATH], ice.PS)))
|
||||
})
|
||||
m.StatusTimeCount()
|
||||
return
|
||||
|
@ -138,9 +138,9 @@ func (m *Message) ToastProcess(arg ...interface{}) func() {
|
||||
m.Toast(PROCESS, arg...)
|
||||
return func() { m.Toast(SUCCESS, arg...) }
|
||||
}
|
||||
func (m *Message) ToastSuccess(arg ...interface{}) {
|
||||
m.Toast(SUCCESS, arg...)
|
||||
}
|
||||
func (m *Message) ToastRestart(arg ...interface{}) { m.Toast(RESTART, arg...) }
|
||||
func (m *Message) ToastFailure(arg ...interface{}) { m.Toast(SUCCESS, arg...) }
|
||||
func (m *Message) ToastSuccess(arg ...interface{}) { m.Toast(SUCCESS, arg...) }
|
||||
func (m *Message) Toast(text string, arg ...interface{}) { // [title [duration [progress]]]
|
||||
if len(arg) > 1 {
|
||||
switch val := arg[1].(type) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user