// Package bnp builds codeless .bnp plugin artifacts: it validates the // declarative plugin files and packs them as a zstd-compressed tar. package bnp import ( "bytes" "encoding/json" "errors" "fmt" "io/fs" "os" "path" "path/filepath" "strings" "time" abiv1 "git.dev.alexdunmow.com/block/pluginsdk/abi/v1" core "git.dev.alexdunmow.com/block/pluginsdk/plugin" "golang.org/x/mod/semver" "google.golang.org/protobuf/proto" "gopkg.in/yaml.v3" ) // Codeless artifacts (WO-WZ-020): a .bnp with NO plugin.wasm — pure // declaration the host runs. Classification is by repo shape: a plugin repo // with no Go source builds codeless; a repo with Go builds wasm as always // (a converted repo DELETES its Go — that's the point). Both artifact kinds // may carry blocks/, templates/, and seed/; codeless just has nothing else. // Required top-level artifact members (mirrors the CMS reader). const ( FileMod = "plugin.mod" FileManifest = "manifest.pb" ) // Declarative artifact dirs shared by both build paths. const ( DirBlocks = "blocks" DirTemplates = "templates" DirSeed = "seed" ) // hostAbiVersion is the ABI major version the packer speaks. It must equal // the guest AbiVersion / the reader's supported major (1). const hostAbiVersion uint32 = 1 // manifestYAMLName is the optional root-level declarative manifest source for // codeless plugins (the counterpart of what DESCRIBE captures from Go code). const manifestYAMLName = "manifest.yaml" // BuildOptions configures BuildCodeless. type BuildOptions struct { // Dir is the plugin repo root (holds plugin.mod and the main Go package). Dir string // Output is the destination .bnp path. Empty → "-.bnp" in // the current working directory. Output string } // BuildResult summarizes a produced artifact for the CLI summary table. type BuildResult struct { OutputPath string Name string Version string // Codeless marks a declarative artifact (no plugin.wasm, WO-WZ-020). Codeless bool WasmBytes int64 ManifestBytes int64 ArtifactBytes int64 // on-disk .bnp size UncompBytes int64 // sum of packed file sizes BlockCount int TemplateCount int AdminPages int JobTypes int Hooks []string DataDir bool IncludedDirs []string // PreviewIncluded/ScreenshotCount report the packed presentation members // (root preview.png + screenshots/); the registry ingests these into the // plugin's gallery at publish. PreviewIncluded bool ScreenshotCount int } // manifestYAML mirrors the declarative PluginManifest fields a codeless // plugin can set. File-valued keys are paths relative to the repo root. type manifestYAML struct { ThemePresets string `yaml:"theme_presets"` // JSON file BundledFonts string `yaml:"bundled_fonts"` // JSON file SettingsSchema string `yaml:"settings_schema"` // JSON file MasterPages string `yaml:"master_pages"` // JSON file ([]masterPageJSON) RequiredIconPacks []string `yaml:"required_icon_packs"` SystemTemplates []struct { Key string `yaml:"key"` Title string `yaml:"title"` Description string `yaml:"description"` } `yaml:"system_templates"` PageTemplates []struct { System string `yaml:"system"` Key string `yaml:"key"` Title string `yaml:"title"` Description string `yaml:"description"` Slots []string `yaml:"slots"` } `yaml:"page_templates"` // TemplateOverrides declare theme-scoped overrides of builtin block // rendering. Source convention: templates/overrides/