mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-22 17:06:47 +08:00
🎨 🔥 ✨ 🚑 集成前端代码的&兼容容器化部署插件的插件改造&提供了一个新的轮播图插件
This commit is contained in:
@@ -14,9 +14,15 @@ import (
|
||||
_ "hotgo/addons/@{.name}/logic"
|
||||
_ "hotgo/addons/@{.name}/queues"
|
||||
"hotgo/addons/@{.name}/router"
|
||||
"hotgo/addons/migrations"
|
||||
"hotgo/internal/library/addons"
|
||||
"hotgo/internal/service"
|
||||
"sync"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
|
||||
|
||||
)
|
||||
|
||||
type module struct {
|
||||
@@ -77,9 +83,54 @@ func (m *module) GetSkeleton() *addons.Skeleton {
|
||||
return m.skeleton
|
||||
}
|
||||
|
||||
|
||||
// Install 安装模块
|
||||
func (m *module) Install(ctx context.Context) (err error) {
|
||||
// ...
|
||||
sqlExt := ".sql"
|
||||
if migrations.GetDbType(ctx) == "pgsql" {
|
||||
sqlExt = ".pg.sql"
|
||||
}
|
||||
// 执行数据库安装文件
|
||||
sqlPath := gfile.Pwd() + gfile.Separator + "addons/migrations/@{.name}/uninstall"+sqlExt
|
||||
result, err := migrations.DoSqlContent(ctx, sqlPath)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "安装模块", m.skeleton.Label, "失败", err)
|
||||
return
|
||||
}
|
||||
g.Log().Debug(ctx, "安装模块", m.skeleton.Label, "成功", result)
|
||||
|
||||
// 复制web目录下的文件到管理后台对应位置
|
||||
// 插件的前端配置文件位于插件目录下的web子目录
|
||||
sourceWebPath := gfile.Pwd() + gfile.Separator + "addons/@{.name}/web/src/views/addons/@{.name}"
|
||||
targetWebPath := "../web/src/views/addons/@{.name}"
|
||||
g.Log().Debug(ctx, "复制前端配置文件", "源路径:", sourceWebPath, "目标路径:", targetWebPath)
|
||||
|
||||
// 检查源路径是否存在
|
||||
if gfile.Exists(sourceWebPath) {
|
||||
err = gfile.CopyDir(sourceWebPath, targetWebPath)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "复制前端配置文件失败:", err)
|
||||
} else {
|
||||
g.Log().Debug(ctx, "复制前端配置文件成功")
|
||||
}
|
||||
} else {
|
||||
g.Log().Warning(ctx, "前端配置文件源路径不存在:", sourceWebPath)
|
||||
}
|
||||
|
||||
// 复制API文件
|
||||
sourceApiPath := gfile.Pwd() + gfile.Separator + "addons/@{.name}/web/src/api/addons/@{.name}"
|
||||
targetApiPath := "../web/src/api/addons/@{.name}"
|
||||
g.Log().Debug(ctx, "复制API文件", "源路径:", sourceApiPath, "目标路径:", targetApiPath)
|
||||
if gfile.Exists(sourceApiPath) {
|
||||
err = gfile.CopyDir(sourceApiPath, targetApiPath)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "复制API文件失败:", err)
|
||||
} else {
|
||||
g.Log().Debug(ctx, "复制API文件成功")
|
||||
}
|
||||
} else {
|
||||
g.Log().Warning(ctx, "API文件源路径不存在:", sourceApiPath)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -91,6 +142,17 @@ func (m *module) Upgrade(ctx context.Context) (err error) {
|
||||
|
||||
// UnInstall 卸载模块
|
||||
func (m *module) UnInstall(ctx context.Context) (err error) {
|
||||
// ...
|
||||
sqlExt := ".sql"
|
||||
if migrations.GetDbType(ctx) == "pgsql" {
|
||||
sqlExt = ".pg.sql"
|
||||
}
|
||||
// 移除数据库安装文件
|
||||
sqlPath := gfile.Pwd() + gfile.Separator + "addons/migrations/@{.name}/uninstall" + sqlExt
|
||||
result, err := migrations.DoSqlContent(ctx, sqlPath)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, "卸载模块", m.skeleton.Label, "失败", err)
|
||||
return
|
||||
}
|
||||
g.Log().Debug(ctx, "卸载模块", m.skeleton.Label, "成功", result)
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user