Documentation
¶
Overview ¶
Package registry is the Gx component registry format (REQ-REG-01). A registry is static HTTP: an index.json and one items/<name>.json per item. Build turns a source folder of items into that shape; Validate checks it against the JSON Schema.
Index ¶
- Constants
- func Lint(src string, props PropReader) ([]string, error)
- func Merge(base, local, upstream string) (string, bool)
- func SaveLock(root string, lock Lock) error
- func Schema() ([]byte, error)
- func ValidateItem(item Item) error
- func ValidateRegistry(dir string) error
- type Change
- type File
- type Index
- type Installer
- type Item
- type Lock
- type LockItem
- type Manifest
- type PropDoc
- type PropReader
- type Summary
- type Target
Constants ¶
const BaseDir = ".gx/base"
BaseDir is the committed base snapshot directory (REQ-REG-02).
const DefaultRoot = "ui"
DefaultRoot is the published target root that Dir replaces.
const RegistryImport = "github.com/alternayte/gx/registry/"
RegistryImport is the import prefix of the official registry source. An installed item rewrites it to the app module path (REQ-REG-05).
Variables ¶
This section is empty.
Functions ¶
func Lint ¶
func Lint(src string, props PropReader) ([]string, error)
Lint checks every source item of a registry against REQ-REG-06: each item has a USAGE.md with usage examples, a do and don't section and a keyboard spec table, every component has a fixtures file, and every prop has a description. It returns one finding per violation.
func Merge ¶
Merge merges a local edit and an upstream edit of one file against their base (REQ-REG-03). It returns the merged text and whether a conflict wrote markers.
The merge is line-based. A region that only one side changed takes that side. A region both sides changed takes the change when the two texts are equal and writes conflict markers otherwise.
func ValidateItem ¶
ValidateItem checks one item against the format rules (REQ-REG-01).
func ValidateRegistry ¶
ValidateRegistry reads a published registry and checks every item and the index (REQ-REG-01).
Types ¶
type Change ¶
type Change struct {
// Target is the published target path of the file.
Target string
// Status is unchanged, local, upstream, merged, conflict,
// upstream-added, upstream-removed or local-removed.
Status string
}
Change is the state of one file in gx diff or gx update (REQ-REG-03).
type File ¶
type File struct {
// Path is the path inside the item source.
Path string `json:"path"`
// Target is the path inside the app, relative to the module root.
Target string `json:"target"`
// Content is the file text.
Content string `json:"content"`
// SHA256 is the hex digest of Content.
SHA256 string `json:"sha256"`
}
File is one file of an item.
type Index ¶
type Index struct {
Items []Summary `json:"items"`
}
Index is the registry index.json (REQ-REG-01).
type Installer ¶
type Installer struct {
// Root is the app module root that holds gx.toml and gx.lock.
Root string
// Source is the registry base: an http(s) URL or a directory that
// holds index.json and items/ (REQ-REG-01).
Source string
// Dir is the app directory the published DefaultRoot maps to. Empty
// keeps DefaultRoot.
Dir string
// Headers are "name: value" strings sent with every HTTP request
// (REQ-REG-04).
Headers []string
// Client is the HTTP client, or a client with a 30 s timeout.
Client *http.Client
}
Installer installs published registry items into an app (REQ-REG-02).
func (*Installer) Add ¶
Add fetches one item and its dependency closure, verifies every file hash (SI-09), writes the files, stores the base snapshots and records the items in gx.lock. It returns the items in install order, dependencies first.
func (*Installer) Diff ¶
Diff reports the local, base and upstream state of one installed item (REQ-REG-03).
func (*Installer) Update ¶
Update merges the current registry version into one installed item (REQ-REG-03). A clean change takes the upstream text, a local-only change stays, and a region both sides changed writes conflict markers and is reported. The base snapshot and gx.lock move to the upstream version either way, so a second update is a no-op.
type Item ¶
type Item struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
// Kind is "component", "block" or "theme".
Kind string `json:"kind"`
Files []File `json:"files"`
RegistryDependencies []string `json:"registryDependencies,omitempty"`
IconPacks []string `json:"iconPacks,omitempty"`
JSPins []string `json:"jsPins,omitempty"`
RequiredTokens []string `json:"requiredTokens,omitempty"`
// Usage is the USAGE.md of the item.
Usage string `json:"usage"`
}
Item is one published registry item (REQ-REG-01).
func LoadSnapshot ¶
LoadSnapshot reads the base snapshot of one installed version (REQ-REG-02).
type LockItem ¶
type LockItem struct {
Version string `json:"version"`
// Files maps the installed app path to the sha256 of its bytes.
Files map[string]string `json:"files"`
}
LockItem is one installed item.
type Manifest ¶
type Manifest struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Kind string `json:"kind"`
Files []Target `json:"files"`
RegistryDependencies []string `json:"registryDependencies,omitempty"`
IconPacks []string `json:"iconPacks,omitempty"`
JSPins []string `json:"jsPins,omitempty"`
RequiredTokens []string `json:"requiredTokens,omitempty"`
}
Manifest is the source gx-item.json of one item folder (REQ-REG-01).
type PropReader ¶
PropReader reads the props block of one .gx file. The caller passes the parser: this package installs items and must not depend on the compiler, which runs commands (SI-09).