compile

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithDebug

func WithDebug() func(c *Compiler) error

WithDebug presents the directory files in readable format.

func WithDefaultCSSRefiners

func WithDefaultCSSRefiners() func(c *Compiler) error

WithDefaultCSSRefiners sets up SASS and SCSS compilers and a CSS minifier.

func WithDefaultImageRefiners

func WithDefaultImageRefiners() func(c *Compiler) error

WithDefaultImageRefiners sets up refiners for SVG, JPEG, PNG, and Webp images.

func WithDefaultOptions

func WithDefaultOptions() func(c *Compiler) error

WithDefaultOptions configures standard compiler behavior.

func WithInclude

func WithInclude(paths ...string) func(c *Compiler) error

WithInclude adds an additional path to look for includes, when neccessary.

func WithLogger

func WithLogger(l *log.Logger) func(c *Compiler) error

WithLogger overrides the default Compiler logger.

func WithParallelTasks

func WithParallelTasks(max int) func(c *Compiler) error

WithParallelTasks sets the maximum number of simultaneous refiners. Higher number speeds up the compilation but consumes more resources. Default value is 50.

func WithRefiners

func WithRefiners(refiners ...Refiner) func(c *Compiler) error

WithRefiners links refiners to the compiler. They will run in the order added for each file.

Types

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

Compiler packs resources for distribution.

func NewCompiler

func NewCompiler(opts ...func(*Compiler) error) (*Compiler, error)

NewCompiler creates a configured compiler.

func (*Compiler) Run

func (c *Compiler) Run(destination string, i *Iterator) (err error)

Run gathers and compiles assets from files and folders in given paths.

type Iterator

type Iterator struct {
	Entries []string // paths to files and folders
	Ignore  []*regexp.Regexp
}

Iterator returns a walking function through paths pointing to files and folders.

func NewIterator

func NewIterator(entries, ignore []string) (*Iterator, error)

NewIterator sets up an Iterator. If the Ignore list is empty, fills it with default values.

func (*Iterator) AllowPath

func (i *Iterator) AllowPath(p string) bool

AllowPath returns true, if the path does not match any of the Ignore patterns.

func (*Iterator) Walk

func (i *Iterator) Walk(f IteratorFunc) error

Walk calls the IteratorFunc for every discovered object.

type IteratorFunc

type IteratorFunc func(target, relative string, info os.FileInfo) error

IteratorFunc is run on every Iterator cycle. First returned error stops the Iterator.

type RefineJavascript

type RefineJavascript struct {
	// contains filtered or unexported fields
}

RefineJavascript compiles a Javascript file to ESNext.

func (*RefineJavascript) Debug

func (rf *RefineJavascript) Debug(destination, source string) error

Debug preserves the comments and keeps Javascript readable.

func (*RefineJavascript) Match

func (rf *RefineJavascript) Match(p string) bool

Match returns true if pattern fits the file path.

func (*RefineJavascript) Refine

func (rf *RefineJavascript) Refine(destination, source string) error

Refine runs the compilation and minification.

func (*RefineJavascript) Rename

func (p *RefineJavascript) Rename(path string) string

type RefineMinify

type RefineMinify struct {
	MatchPath *regexp.Regexp
	Minifier  minify.MinifierFunc
	// contains filtered or unexported fields
}

RefineMinify interfaces with the popular Minifier library.

func (*RefineMinify) Debug

func (p *RefineMinify) Debug(destination, source string) error

func (*RefineMinify) Match

func (rf *RefineMinify) Match(p string) bool

Match returns true if pattern fits the file path.

func (*RefineMinify) Refine

func (rf *RefineMinify) Refine(destination, source string) error

Refine applies a minifier to source and writes the result to destination.

func (*RefineMinify) Rename

func (p *RefineMinify) Rename(path string) string

type RefineRaster

type RefineRaster struct {
	MatchPath *regexp.Regexp
	Encode    func(io.Writer, image.Image) error
	Decode    func(io.Reader) (image.Image, error)
	// contains filtered or unexported fields
}

RefineRaster provides basic image compression.

func (*RefineRaster) Debug

func (p *RefineRaster) Debug(destination, source string) error

func (*RefineRaster) Match

func (rf *RefineRaster) Match(p string) bool

Match returns true if pattern fits the file path.

func (*RefineRaster) Refine

func (rf *RefineRaster) Refine(destination, source string) error

Refine scales the image and reduces its quality for web distribution.

func (*RefineRaster) Rename

func (p *RefineRaster) Rename(path string) string

type RefineSASS

type RefineSASS struct {
	RefineSCSS
}

RefineSASS compiles SASS files to minified CSS.

func (*RefineSASS) Debug

func (rf *RefineSASS) Debug(destination, source string) error

Debug leaves comments, keeps track of source, and preserves readability of the resulting CSS.

func (*RefineSASS) Match

func (rf *RefineSASS) Match(p string) bool

Match returns true if pattern fits the file path.

func (*RefineSASS) Refine

func (rf *RefineSASS) Refine(destination, source string) error

Refine process SASS source into a minified CSS file.

type RefineSCSS

type RefineSCSS struct {
	Paths []string
}

RefineSCSS compiles SCSS files to minified CSS.

func (*RefineSCSS) Debug

func (rf *RefineSCSS) Debug(destination, source string) error

Debug leaves comments, keeps track of source, and preserves readability of the resulting CSS.

func (*RefineSCSS) Match

func (rf *RefineSCSS) Match(p string) bool

Match returns true if pattern fits the file path.

func (*RefineSCSS) Refine

func (rf *RefineSCSS) Refine(destination, source string) error

Refine process SASS source into a minified CSS file.

func (*RefineSCSS) Rename

func (rf *RefineSCSS) Rename(p string) string

Rename switches a SASS asset to a CSS asset.

type RefineText

type RefineText struct {
	MatchPath *regexp.Regexp
	Search    *regexp.Regexp
	Replace   string
	// contains filtered or unexported fields
}

RefineText searches and replaces snippets in text files. Handy for simple file manipulations.

func (*RefineText) Debug

func (p *RefineText) Debug(destination, source string) error

func (*RefineText) Match

func (rf *RefineText) Match(p string) bool

Match returns true if pattern fits the file path.

func (*RefineText) Refine

func (rf *RefineText) Refine(destination, source string) error

Refine writes the contents of source to destination while replacing certain text snippets.

func (*RefineText) Rename

func (p *RefineText) Rename(path string) string

type Refiner

type Refiner interface {
	// Match will activate the refiner on matching paths.
	Match(path string) (ok bool)
	// Some refiners transform one asset into another, like SASS => CSS.
	Rename(oldPath string) (newPath string)
	// Change the content from source to destination.
	Refine(destination, source string) error
	// Same as Refine, but keep the changed files as readable as possible.
	Debug(destination, source string) error
}

Refiner converts one type of asset into another or optimizes the content.

Jump to

Keyboard shortcuts

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