1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 17:44:05 +08:00

add modpack

This commit is contained in:
shaoying 2020-08-11 22:08:07 +08:00
parent e5e926fbc7
commit e15e1d80aa
6 changed files with 173 additions and 29 deletions

View File

@ -108,12 +108,16 @@ var RENDER = struct {
Field string Field string
Frame string Frame string
Button string Button string
Download string
}{ }{
A: "a", A: "a",
IMG: "img", IMG: "img",
Field: "field", Field: "field",
Frame: "frame", Frame: "frame",
Button: "button", Button: "button",
Download: "download",
} }
func init() { func init() {
@ -137,6 +141,10 @@ func init() {
RENDER.Button: {Hand: func(m *ice.Message, arg ...string) { RENDER.Button: {Hand: func(m *ice.Message, arg ...string) {
m.Echo(`<input type="button" value="%s">`, arg[0]) m.Echo(`<input type="button" value="%s">`, arg[0])
}}, }},
RENDER.Download: {Hand: func(m *ice.Message, arg ...string) {
u := kit.Select(arg[0], arg, 1)
m.Echo(`<a href="%s" target="_blank" download="%s">%s</a>`, u, path.Base(arg[0]), arg[0])
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if arg[0] == mdb.RENDER { if arg[0] == mdb.RENDER {
m.Search("_render", func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { m.Search("_render", func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {

View File

@ -1,9 +1,9 @@
package chat package chat
import ( import (
"github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"fmt" "fmt"
) )
@ -52,20 +52,20 @@ func init() {
"pack": {Name: "pack", Help: "打包", Hand: func(m *ice.Message, arg ...string) { "pack": {Name: "pack", Help: "打包", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy("web.code.webpack", "pack") m.Cmdy("web.code.webpack", "pack")
if f, _, e := kit.Create("usr/volcanos/pack/" + m.Option("name") + "/cache.js"); m.Assert(e) { if f, _, e := kit.Create("usr/volcanos/pack/" + m.Option("name") + ".js"); m.Assert(e) {
defer f.Close() defer f.Close()
data := kit.UnMarshal(m.Option("content")) data := kit.UnMarshal(m.Option("content"))
f.WriteString(`Volcanos.meta.pack = ` + kit.Formats(data)) f.WriteString(`Volcanos.meta.pack = ` + kit.Formats(data))
} }
if f, p, e := kit.Create("usr/volcanos/pack/" + m.Option("name") + "/index.html"); m.Assert(e) { if f, p, e := kit.Create("usr/volcanos/pack/" + m.Option("name") + ".html"); m.Assert(e) {
f.WriteString(fmt.Sprintf(_pack, f.WriteString(fmt.Sprintf(_pack,
m.Cmdx(nfs.CAT, "usr/volcanos/cache.css"), m.Cmdx(nfs.CAT, "usr/volcanos/cache.css"),
m.Cmdx(nfs.CAT, "usr/volcanos/index.css"), m.Cmdx(nfs.CAT, "usr/volcanos/index.css"),
m.Cmdx(nfs.CAT, "usr/volcanos/proto.js"), m.Cmdx(nfs.CAT, "usr/volcanos/proto.js"),
m.Cmdx(nfs.CAT, "usr/volcanos/cache.js"), m.Cmdx(nfs.CAT, "usr/volcanos/cache.js"),
m.Cmdx(nfs.CAT, "usr/volcanos/pack/"+m.Option("name")+"/cache.js"), m.Cmdx(nfs.CAT, "usr/volcanos/pack/"+m.Option("name")+".js"),
m.Cmdx(nfs.CAT, "usr/volcanos/index.js"), m.Cmdx(nfs.CAT, "usr/volcanos/index.js"),
)) ))
m.Echo(p) m.Echo(p)

View File

@ -1,7 +1,11 @@
package code package code
import ( import (
"bufio"
"bytes"
ice "github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/base/web"
@ -117,6 +121,7 @@ func _pack_intshell(m *ice.Message, pack *os.File) {
const ( const (
WEBPACK = "webpack" WEBPACK = "webpack"
BINPACK = "binpack" BINPACK = "binpack"
MODPACK = "modpack"
) )
func init() { func init() {
@ -160,28 +165,161 @@ func init() {
m.Option(nfs.DIR_DEEP, "true") m.Option(nfs.DIR_DEEP, "true")
m.Cmdy(nfs.DIR, "pack") m.Cmdy(nfs.DIR, "pack")
m.Table(func(index int, value map[string]string, head []string) { m.Table(func(index int, value map[string]string, head []string) {
m.Push("link", m.Cmdx(mdb.RENDER, web.RENDER.A, "/"+value["path"])) m.Push("link", m.Cmdx(mdb.RENDER, web.RENDER.Download, "/"+value["path"]))
}) })
}}, }},
BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { BINPACK: {Name: "binpack", Help: "打包", Action: map[string]*ice.Action{
pack, p, e := kit.Create("usr/icebergs/pack/binpack.go") "pack": {Name: "pack", Help: "pack", Hand: func(m *ice.Message, arg ...string) {
m.Assert(e) pack, p, e := kit.Create("usr/icebergs/pack/binpack.go")
defer pack.Close() m.Assert(e)
defer pack.Close()
pack.WriteString(`package pack` + "\n\n") pack.WriteString(`package pack` + "\n\n")
pack.WriteString(`import "github.com/shylinux/icebergs"` + "\n\n") pack.WriteString(`import "github.com/shylinux/icebergs"` + "\n\n")
pack.WriteString(`func init() {` + "\n") pack.WriteString(`func init() {` + "\n")
pack.WriteString(` ice.BinPack = map[string][]byte{` + "\n") pack.WriteString(` ice.BinPack = map[string][]byte{` + "\n")
_pack_volcanos(m, pack) _pack_volcanos(m, pack)
_pack_learning(m, pack) _pack_learning(m, pack)
_pack_icebergs(m, pack) _pack_icebergs(m, pack)
_pack_intshell(m, pack) _pack_intshell(m, pack)
pack.WriteString(` }` + "\n") pack.WriteString(` }` + "\n")
pack.WriteString(`}` + "\n") pack.WriteString(`}` + "\n")
m.Echo(p) m.Echo(p)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(nfs.DIR_ROOT, "usr/icebergs")
m.Option(nfs.DIR_TYPE, nfs.FILE)
m.Option(nfs.DIR_DEEP, "true")
m.Cmdy(nfs.DIR, "pack")
m.Table(func(index int, value map[string]string, head []string) {
m.Push("link", m.Cmdx(mdb.RENDER, web.RENDER.Download, value["path"], "/share/local/usr/icebergs/"+value["path"]))
})
}}, }},
MODPACK: {Name: "modpack path=auto 查看:button 返回:button 创建:button", Help: "打包", Meta: kit.Dict(
"style", "editor", "创建", kit.List("_input", "text", "name", "name"),
), Action: map[string]*ice.Action{
mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Option("name", "hi")
m.Option("help", "hello")
for i := 0; i < len(arg)-1; i += 2 {
m.Option(arg[i], arg[i+1])
}
os.Mkdir(path.Join("src/", arg[1]), ice.MOD_DIR)
name := m.Option("name")
kit.Fetch(m.Confv(MODPACK, "meta.base"), func(key string, value string) {
p := path.Join("src/", arg[1], arg[1]+"."+key)
if _, e := os.Stat(p); e != nil && os.IsNotExist(e) {
if f, p, e := kit.Create(p); m.Assert(e) {
if b, e := kit.Render(value, m); m.Assert(e) {
if n, e := f.Write(b); m.Assert(e) {
m.Log_EXPORT("file", p, arg[1], "size", n)
m.Echo(p)
}
}
}
}
})
mod := ""
if f, e := os.Open("go.mod"); e == nil {
defer f.Close()
for bio := bufio.NewScanner(f); bio.Scan(); {
if strings.HasPrefix(bio.Text(), "module") {
mod = strings.Split(bio.Text(), " ")[1]
break
}
}
}
begin, has := false, false
if f, e := os.Open("src/main.go"); e == nil {
for bio := bufio.NewScanner(f); bio.Scan(); {
if strings.HasPrefix(bio.Text(), "import (") {
begin = true
continue
}
if strings.HasPrefix(bio.Text(), "import") {
begin = true
continue
}
if strings.HasPrefix(bio.Text(), ")") {
begin = false
continue
}
if begin {
if strings.Contains(bio.Text(), mod+"/src/"+name) {
has = true
}
}
}
f.Close()
}
if !has {
if f, e := os.Open("src/main.go"); e == nil {
if b, e := ioutil.ReadAll(f); e == nil {
f.Close()
if f, e := os.Create("src/main.go"); e == nil {
for bio := bufio.NewScanner(bytes.NewBuffer(b)); bio.Scan(); {
f.WriteString(bio.Text())
f.WriteString("\n")
if strings.HasPrefix(bio.Text(), "package") {
f.WriteString("\n")
f.WriteString(`import _ "` + mod + "/src/" + name + `"`)
f.WriteString("\n")
m.Debug("src/main.go import: %v", begin, mod+"/src/"+name)
}
}
}
}
}
}
m.Cmd(cli.SYSTEM, "gofmt", "-w", "src/main.go")
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(nfs.DIR_TYPE, nfs.FILE)
m.Option(nfs.DIR_DEEP, "true")
m.Option(nfs.DIR_ROOT, "src")
m.Cmdy(nfs.DIR, kit.Select("", arg, 0))
if len(arg) > 0 {
m.Option("_display", "/plugin/local/code/inner.js")
}
}},
},
Configs: map[string]*ice.Config{
MODPACK: {Name: MODPACK, Help: "modpack", Value: kit.Data(
"base", kit.Dict(
"shy", `title {{.Option "name"}}
`,
"go", `package {{.Option "name"}}
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/chat"
kit "github.com/shylinux/toolkits"
)
var Index = &ice.Context{Name: "{{.Option "name"}}", Help: "{{.Option "help"}}",
Configs: map[string]*ice.Config{
"{{.Option "name"}}": {Name: "{{.Option "name"}}", Help: "{{.Option "name"}}", Value: kit.Data()},
},
Commands: map[string]*ice.Command{
"{{.Option "name"}}": {Name: "{{.Option "name"}}", Help: "{{.Option "name"}}", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo("hello {{.Option "name"}} world")
}},
},
}
func init() { chat.Index.Register(Index, &web.Frame{}) }
`,
),
)},
}, },
}, nil) }, nil)
} }

View File

@ -1,12 +1,12 @@
package mp package mp
import ( import (
"github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/aaa" "github.com/shylinux/icebergs/base/aaa"
"github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/chat" "github.com/shylinux/icebergs/core/chat"
"github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"net/http" "net/http"
"path" "path"
@ -15,7 +15,6 @@ import (
const MP = "mp" const MP = "mp"
var Index = &ice.Context{Name: "mp", Help: "小程序", var Index = &ice.Context{Name: "mp", Help: "小程序",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
"login": {Name: "login", Help: "认证", Value: kit.Data( "login": {Name: "login", Help: "认证", Value: kit.Data(
"auth", "/sns/jscode2session?grant_type=authorization_code", "auth", "/sns/jscode2session?grant_type=authorization_code",

View File

@ -56,11 +56,14 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
)}, )},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
TEXT: {Name: "text 保存:button text:textarea", Help: "文本", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { TEXT: {Name: "text 保存:button 清空:button text:textarea", Help: "文本", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 && arg[0] != "" { if len(arg) > 0 && arg[0] != "" {
m.Cmd(_tmux, "set-buffer", arg[0]) m.Cmd(_tmux, "set-buffer", arg[0])
m.Cmdy("web.wiki.image", "qrcode", arg[0])
m.Echo("\n")
} }
m.Echo(m.Cmdx(_tmux, "show-buffer")) m.Echo(m.Cmdx(_tmux, "show-buffer"))
m.Render("")
}}, }},
BUFFER: {Name: "buffer [buffer=auto [value]] auto", Help: "缓存", Action: map[string]*ice.Action{ BUFFER: {Name: "buffer [buffer=auto [value]] auto", Help: "缓存", Action: map[string]*ice.Action{
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) { mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {

View File

@ -7,10 +7,6 @@ refer "" `
` `
image qrcode `https://weixin.qq.com` image qrcode `https://weixin.qq.com`
chapter "技术"
field webpack web.code.webpack
field binpack web.code.binpack
chapter "应用" chapter "应用"
field "阅读器" web.code.inner args `[ src/ main.shy ]` field "阅读器" web.code.inner args `[ src/ main.shy ]`