mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 03:09:26 +08:00
Build swagger ui in seperate webpack build (#102046)
* Build swagger ui in seperate webpack build * render grafana and swagger * include light theme * merge main * update webassets usage --------- Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
@ -20,10 +20,9 @@ type ManifestInfo struct {
|
||||
Integrity string `json:"integrity,omitempty"`
|
||||
|
||||
// The known entrypoints
|
||||
App *EntryPointInfo `json:"app,omitempty"`
|
||||
Dark *EntryPointInfo `json:"dark,omitempty"`
|
||||
Light *EntryPointInfo `json:"light,omitempty"`
|
||||
Swagger *EntryPointInfo `json:"swagger,omitempty"`
|
||||
App *EntryPointInfo `json:"app,omitempty"`
|
||||
Dark *EntryPointInfo `json:"dark,omitempty"`
|
||||
Light *EntryPointInfo `json:"light,omitempty"`
|
||||
}
|
||||
|
||||
type EntryPointInfo struct {
|
||||
@ -38,7 +37,7 @@ var (
|
||||
entryPointAssetsCache *dtos.EntryPointAssets // TODO: get rid of global state
|
||||
)
|
||||
|
||||
func GetWebAssets(ctx context.Context, cfg *setting.Cfg, license licensing.Licensing) (*dtos.EntryPointAssets, error) {
|
||||
func GetWebAssets(ctx context.Context, build string, cfg *setting.Cfg, license licensing.Licensing) (*dtos.EntryPointAssets, error) {
|
||||
entryPointAssetsCacheMu.RLock()
|
||||
ret := entryPointAssetsCache
|
||||
entryPointAssetsCacheMu.RUnlock()
|
||||
@ -54,11 +53,11 @@ func GetWebAssets(ctx context.Context, cfg *setting.Cfg, license licensing.Licen
|
||||
|
||||
cdn := "" // "https://grafana-assets.grafana.net/grafana/10.3.0-64123/"
|
||||
if cdn != "" {
|
||||
result, err = readWebAssetsFromCDN(ctx, cdn)
|
||||
result, err = readWebAssetsFromCDN(ctx, build, cdn)
|
||||
}
|
||||
|
||||
if result == nil {
|
||||
result, err = readWebAssetsFromFile(filepath.Join(cfg.StaticRootPath, "build", "assets-manifest.json"))
|
||||
result, err = readWebAssetsFromFile(filepath.Join(cfg.StaticRootPath, build, "assets-manifest.json"))
|
||||
if err == nil {
|
||||
cdn, _ = cfg.GetContentDeliveryURL(license.ContentDeliveryPrefix())
|
||||
if cdn != "" {
|
||||
@ -83,8 +82,8 @@ func readWebAssetsFromFile(manifestpath string) (*dtos.EntryPointAssets, error)
|
||||
return readWebAssets(f)
|
||||
}
|
||||
|
||||
func readWebAssetsFromCDN(ctx context.Context, baseURL string) (*dtos.EntryPointAssets, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, baseURL+"public/build/assets-manifest.json", nil)
|
||||
func readWebAssetsFromCDN(ctx context.Context, build string, baseURL string) (*dtos.EntryPointAssets, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, baseURL+"public/"+build+"/assets-manifest.json", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -123,23 +122,16 @@ func readWebAssets(r io.Reader) (*dtos.EntryPointAssets, error) {
|
||||
if entryPoints.App == nil || len(entryPoints.App.Assets.JS) == 0 {
|
||||
return nil, fmt.Errorf("missing app entry, try running `yarn build`")
|
||||
}
|
||||
if entryPoints.Dark == nil || len(entryPoints.Dark.Assets.CSS) == 0 {
|
||||
return nil, fmt.Errorf("missing dark entry, try running `yarn build`")
|
||||
}
|
||||
if entryPoints.Light == nil || len(entryPoints.Light.Assets.CSS) == 0 {
|
||||
return nil, fmt.Errorf("missing light entry, try running `yarn build`")
|
||||
}
|
||||
if entryPoints.Swagger == nil || len(entryPoints.Swagger.Assets.JS) == 0 {
|
||||
return nil, fmt.Errorf("missing swagger entry, try running `yarn build`")
|
||||
}
|
||||
|
||||
rsp := &dtos.EntryPointAssets{
|
||||
JSFiles: make([]dtos.EntryPointAsset, 0, len(entryPoints.App.Assets.JS)),
|
||||
CSSFiles: make([]dtos.EntryPointAsset, 0, len(entryPoints.App.Assets.CSS)),
|
||||
Dark: entryPoints.Dark.Assets.CSS[0],
|
||||
Light: entryPoints.Light.Assets.CSS[0],
|
||||
Swagger: make([]dtos.EntryPointAsset, 0, len(entryPoints.Swagger.Assets.JS)),
|
||||
SwaggerCSSFiles: make([]dtos.EntryPointAsset, 0, len(entryPoints.Swagger.Assets.CSS)),
|
||||
JSFiles: make([]dtos.EntryPointAsset, 0, len(entryPoints.App.Assets.JS)),
|
||||
CSSFiles: make([]dtos.EntryPointAsset, 0, len(entryPoints.App.Assets.CSS)),
|
||||
}
|
||||
if entryPoints.Dark != nil && len(entryPoints.Dark.Assets.CSS) > 0 {
|
||||
rsp.Dark = entryPoints.Dark.Assets.CSS[0]
|
||||
}
|
||||
if entryPoints.Light != nil && len(entryPoints.Light.Assets.CSS) > 0 {
|
||||
rsp.Light = entryPoints.Light.Assets.CSS[0]
|
||||
}
|
||||
|
||||
for _, entry := range entryPoints.App.Assets.JS {
|
||||
@ -154,17 +146,5 @@ func readWebAssets(r io.Reader) (*dtos.EntryPointAssets, error) {
|
||||
Integrity: integrity[entry],
|
||||
})
|
||||
}
|
||||
for _, entry := range entryPoints.Swagger.Assets.JS {
|
||||
rsp.Swagger = append(rsp.Swagger, dtos.EntryPointAsset{
|
||||
FilePath: entry,
|
||||
Integrity: integrity[entry],
|
||||
})
|
||||
}
|
||||
for _, entry := range entryPoints.Swagger.Assets.CSS {
|
||||
rsp.SwaggerCSSFiles = append(rsp.SwaggerCSSFiles, dtos.EntryPointAsset{
|
||||
FilePath: entry,
|
||||
Integrity: integrity[entry],
|
||||
})
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user