Help us shape the future of Go! Take the 2026 Go Developer Survey

compile

package
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 77 Imported by: 0

Documentation

Overview

Package compile turns an lfm project into a deployable output folder.

One compile runs a fixed lifecycle. A stage starts only when the previous ones produced no errors, and every stage reports through the same diagnostics, so one run explains everything that needs fixing:

  1. load read lfm.json and data/
  2. prepare check template bindings and links statically, then render
  3. assemble resolve, bundle and pack every referenced resource
  4. optimize (release) split critical CSS after measuring it in Chrome
  5. finalize serialize and compact the document
  6. verify run every document check on the exact final bytes
  7. audit (release) runtime probe and Lighthouse in a headless browser
  8. publish replace output/ in one rename

Nothing is written before verify passes; a failed compile keeps the previous output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProjectCheckOptions added in v0.1.9

func ProjectCheckOptions(dir string, options check.Options) (check.Options, error)

ProjectCheckOptions pairs an already built page with the same project facts and validation settings used by Compile. Resource bytes stay those of the target.

func Rules

func Rules() []diagnostic.RuleInfo

Rules lists every rule any stage of the lifecycle can report, sorted by ID.

func TemplateHelp added in v0.1.9

func TemplateHelp() string

TemplateHelp describes the helper set installed by the compiler.

Types

type AssetDecision

type AssetDecision struct {
	Source           string   `json:"source"`
	Aliases          []string `json:"aliases,omitempty"`
	Pinned           bool     `json:"pinned,omitempty"`
	Mode             string   `json:"mode"`
	Bytes            int      `json:"bytes"`
	Contribution     int      `json:"encodedContributionBytes"`
	HTMLContribution int      `json:"htmlContributionBytes"`
	Occurrences      int      `json:"occurrences"`
	Reason           string   `json:"reason"`
	Output           string   `json:"output,omitempty"`
	Encoding         string   `json:"encoding,omitempty"`
}

type Cost

type Cost struct {
	HTMLBytes        int `json:"htmlBytes"`
	GzipBytes        int `json:"htmlGzipLevel1Bytes"`
	SidecarBytes     int `json:"sidecarBytes"`
	TotalBytes       int `json:"totalRawBytes"`
	CSSBytes         int `json:"totalCSSBytes"`
	JSBytes          int `json:"totalJSBytes"`
	ExternalCSSBytes int `json:"externalCSSBytes"`
	ExternalJSBytes  int `json:"externalJSBytes"`
}

type Failure

type Failure struct{ Errors int }

Failure is returned when diagnostics block the compile.

func (*Failure) Error

func (f *Failure) Error() string

type File

type File struct {
	Name   string `json:"name"`
	Bytes  int    `json:"bytes"`
	SHA256 string `json:"sha256"`
}

File is one emitted output file.

type Options

type Options struct {
	Release bool   // browser-backed optimize and audit stages
	Publish bool   // replace output/ on success
	Waiting func() // called when another compile of the project holds the lock
}

Options select the optional lifecycle stages.

type Result

type Result struct {
	Root     string            `json:"root"`
	Output   string            `json:"output"`
	PageURL  string            `json:"url,omitempty"`
	Files    []File            `json:"files"`
	Artifact map[string][]byte `json:"-"` // emitted bytes by file name
	// Distribution holds the store packages per unit (each deliverable and
	// the bundle) by file name, published to distribution/<unit>/ and never
	// deployed. A unit without an entry is left as it is; an empty one is
	// removed.
	Distribution map[string]map[string][]byte `json:"-"`
	// Previews are rendered deliverable pages lfm serve shows and publish
	// never writes, such as each printable edition as HTML.
	Previews    map[string][]byte    `json:"-"`
	External    []string             `json:"externalAssets,omitempty"`
	Validation  *check.Report        `json:"validation,omitempty"`
	Published   bool                 `json:"published"`
	Release     *release.Result      `json:"release,omitempty"`
	Packing     []AssetDecision      `json:"assets,omitempty"`
	Cost        *Cost                `json:"cost,omitempty"`
	Compaction  *htmlcompact.Result  `json:"htmlCompaction,omitempty"`
	Images      []imaging.Decision   `json:"images,omitempty"`
	Fonts       []fontcheck.Info     `json:"fonts,omitempty"`
	Research    research.Summary     `json:"research"`
	Concept     concept.Summary      `json:"concept"`
	SocialMeta  []string             `json:"socialMetaRepairs,omitempty"`
	FontHints   int                  `json:"fontHintRepairs,omitempty"`
	PageOffers  bool                 `json:"pageOffers,omitempty"`
	Starter     bool                 `json:"starter"` // the template is still the starter page of lfm init
	Book        *book.Summary        `json:"book,omitempty"`
	Printable   *printable.Summary   `json:"printable,omitempty"`
	Bundle      *bundle.Summary      `json:"bundle,omitempty"`
	Spreadsheet *spreadsheet.Summary `json:"spreadsheet,omitempty"`
	Document    *document.Summary    `json:"document,omitempty"`
	Deck        *deck.Summary        `json:"deck,omitempty"`
	// Optional names the helpers a release found missing and what each
	// would add; no release needs them.
	Optional []string      `json:"optional,omitempty"`
	Inputs   []string      `json:"-"` // resolved source files, for watchers
	Duration time.Duration `json:"-"`
}

Result describes a compile, filled as far as the lifecycle got.

func Compile

func Compile(ctx context.Context, dir string, options Options) (result Result, err error)

Compile runs the lifecycle on the project in dir. Cancelling ctx stops it between stages; a cancelled compile never publishes.

func (Result) Errors

func (r Result) Errors() int

Errors and Warnings count the reported diagnostics.

func (Result) PageNeeded added in v0.1.12

func (r Result) PageNeeded() bool

PageNeeded reports whether the current page participates in selling the deliverables.

func (Result) Warnings

func (r Result) Warnings() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL