2024-01-16 09:27:04 +01:00
|
|
|
package arcast
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"encoding/json"
|
|
|
|
"io/fs"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"forge.cadoles.com/arcad/arcast/pkg/server"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
DefaultApps []server.App
|
2024-04-24 17:32:01 +02:00
|
|
|
//go:embed apps/main/build/**
|
2024-01-16 09:27:04 +01:00
|
|
|
appsFS embed.FS
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2024-04-24 17:32:01 +02:00
|
|
|
defaultApps, err := loadApps(
|
|
|
|
"apps/main/build",
|
|
|
|
)
|
2024-01-16 09:27:04 +01:00
|
|
|
if err != nil {
|
|
|
|
panic(errors.WithStack(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultApps = defaultApps
|
|
|
|
}
|
|
|
|
|
2024-04-24 17:32:01 +02:00
|
|
|
func loadApps(appDirs ...string) ([]server.App, error) {
|
2024-01-16 09:27:04 +01:00
|
|
|
apps := make([]server.App, 0)
|
|
|
|
|
2024-04-24 17:32:01 +02:00
|
|
|
for _, dir := range appDirs {
|
|
|
|
rawManifest, err := fs.ReadFile(appsFS, filepath.Join(dir, "arcast-app.json"))
|
2024-01-16 09:27:04 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var app server.App
|
|
|
|
|
|
|
|
if err := json.Unmarshal(rawManifest, &app); err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
2024-04-24 17:32:01 +02:00
|
|
|
fs, err := fs.Sub(appsFS, dir)
|
2024-01-16 09:27:04 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
app.FS = fs
|
|
|
|
|
|
|
|
apps = append(apps, app)
|
|
|
|
}
|
|
|
|
|
|
|
|
return apps, nil
|
|
|
|
}
|