assetmatrix

package module
v0.0.0-...-550750b Latest Latest
Warning

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

Go to latest
Published: May 24, 2019 License: BSD-3-Clause Imports: 17 Imported by: 6

README

asset-matrix-go

Asset compilation with flexible external dependency management.

This is very much just hacked together, but it works and I plan on making it a lot better when I have the time.

Supports SCSS (.scss), ERB (.erb), JSX (.jsx), and ES6 modules for JavaScript (.js).

There is asset caching between builds for everything except SCSS and ERB (as these have access to the cache breaker and significant refactoring is required to handle this properly).

Usage

// compiler.go
package main

import (
	"log"

	matrix "github.com/jvatic/asset-matrix-go"
)

func main() {
	m := matrix.New(&matrix.Config{
		Paths: []*matrix.AssetRoot{
			{
				Path: "./src",
			},
			{
				GitRepo:   "git://github.com/jvatic/marbles-js.git",
				GitBranch: "master",
				GitRef:    "6d5491bbc51f4454e0c605af6e7faa4e0539441a",
				Path:      "src",
			},
		},
		Outputs: []string{
			"application.js",
			"application.scss",
			"marbles/*.js",
			"*.png",
		},
		OutputDir: "./build",
	})
	if err := m.Build(); err != nil {
		log.Fatal(err)
	}
	m.RemoveOldAssets()
}
go run compiler.go

See here for an example of compiling an HTML template.

Outputs: []string{} will output everything, or you can explicitly specify what you'd like in your build directory.

How import paths are resolved

Lets say you have twoAssetRoots specified in your config pointing to ./src and ./vendor. If ./vendor has the following relative paths, foo/bar.js and foo/bar.scss, then you can import them as import Bar from 'foo/bar'; and @import "foo/bar"; in your JavaScript and SCSS files respectively. However, if you have either of these paths in ./src (which we're assuming is given before ./vendor in the config), then that file will be used instead of the one in ./vendor.

Contributing

Pull requests are always welcome!

Though it's always a good idea to discuss things in an issue before implementing them.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AssetNotFoundError = errors.New("Asset not found")

Functions

This section is empty.

Types

type Asset

type Asset interface {
	Open() (*os.File, error)
	Initialize() error
	Checksum() string
	Path() string
	RelPath() (string, error)
	SetIndexKey(string)
	IndexKey() string
	ImportPaths() []string
	Compile() (io.Reader, error)
	OutputExt() string
	OutputPath() string
}

func NewAsset

func NewAsset(r *AssetRoot, p string) Asset

func NewERBAsset

func NewERBAsset(r *AssetRoot, input Asset, p string) Asset

func NewESLintAsset

func NewESLintAsset(r *AssetRoot, input Asset, p string) Asset

func NewJSXAsset

func NewJSXAsset(r *AssetRoot, input Asset, p string) Asset

func NewJavaScriptAsset

func NewJavaScriptAsset(r *AssetRoot, input Asset, p string) Asset

func NewSCSSAsset

func NewSCSSAsset(r *AssetRoot, input Asset, p string) Asset

type AssetRoot

type AssetRoot struct {
	Path             string
	GitRepo          string
	GitBranch        string
	GitRef           string
	ESLintConfigPath string
	Log              log.Logger
	// contains filtered or unexported fields
}

func (*AssetRoot) CloneRepo

func (r *AssetRoot) CloneRepo() error

func (*AssetRoot) SetCacheBreaker

func (r *AssetRoot) SetCacheBreaker(cacheBreaker string)

type Cache

type Cache struct {
	Dir string
	// contains filtered or unexported fields
}

func (*Cache) CacheAsset

func (c *Cache) CacheAsset(ar io.Reader, checksum string) io.Reader

func (*Cache) CleanupCacheDir

func (c *Cache) CleanupCacheDir() error

func (*Cache) FindCachedAsset

func (c *Cache) FindCachedAsset(a Asset) (Asset, error)

type CachedAsset

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

func (*CachedAsset) Checksum

func (a *CachedAsset) Checksum() string

func (*CachedAsset) Compile

func (a *CachedAsset) Compile() (io.Reader, error)

func (*CachedAsset) ImportPaths

func (a *CachedAsset) ImportPaths() []string

func (*CachedAsset) IndexKey

func (a *CachedAsset) IndexKey() string

func (*CachedAsset) Initialize

func (a *CachedAsset) Initialize() error

func (*CachedAsset) Open

func (a *CachedAsset) Open() (*os.File, error)

func (*CachedAsset) OutputExt

func (a *CachedAsset) OutputExt() string

func (*CachedAsset) OutputPath

func (a *CachedAsset) OutputPath() string

func (*CachedAsset) Path

func (a *CachedAsset) Path() string

func (*CachedAsset) RelPath

func (a *CachedAsset) RelPath() (string, error)

func (*CachedAsset) SetIndexKey

func (a *CachedAsset) SetIndexKey(key string)

type Config

type Config struct {
	Paths          []*AssetRoot
	Outputs        []string
	OutputDir      string
	CacheDir       string
	AssetURLPrefix string
}

type ERBAsset

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

func (*ERBAsset) Checksum

func (a *ERBAsset) Checksum() string

func (*ERBAsset) Compile

func (a *ERBAsset) Compile() (io.Reader, error)

func (*ERBAsset) ImportPaths

func (a *ERBAsset) ImportPaths() []string

func (*ERBAsset) IndexKey

func (a *ERBAsset) IndexKey() string

func (*ERBAsset) Initialize

func (a *ERBAsset) Initialize() error

func (*ERBAsset) Open

func (a *ERBAsset) Open() (*os.File, error)

func (*ERBAsset) OutputExt

func (a *ERBAsset) OutputExt() string

func (*ERBAsset) OutputPath

func (a *ERBAsset) OutputPath() string

func (*ERBAsset) Path

func (a *ERBAsset) Path() string

func (*ERBAsset) RelPath

func (a *ERBAsset) RelPath() (string, error)

func (*ERBAsset) SetIndexKey

func (a *ERBAsset) SetIndexKey(key string)

type ESLintAsset

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

func (*ESLintAsset) Checksum

func (a *ESLintAsset) Checksum() string

func (*ESLintAsset) Compile

func (a *ESLintAsset) Compile() (io.Reader, error)

func (*ESLintAsset) ImportPaths

func (a *ESLintAsset) ImportPaths() []string

func (*ESLintAsset) IndexKey

func (a *ESLintAsset) IndexKey() string

func (*ESLintAsset) Initialize

func (a *ESLintAsset) Initialize() error

func (*ESLintAsset) Open

func (a *ESLintAsset) Open() (*os.File, error)

func (*ESLintAsset) OutputExt

func (a *ESLintAsset) OutputExt() string

func (*ESLintAsset) OutputPath

func (a *ESLintAsset) OutputPath() string

func (*ESLintAsset) Path

func (a *ESLintAsset) Path() string

func (*ESLintAsset) RelPath

func (a *ESLintAsset) RelPath() (string, error)

func (*ESLintAsset) SetIndexKey

func (a *ESLintAsset) SetIndexKey(k string)

type GenericAsset

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

func (*GenericAsset) Checksum

func (a *GenericAsset) Checksum() string

func (*GenericAsset) Compile

func (a *GenericAsset) Compile() (io.Reader, error)

func (*GenericAsset) ImportPaths

func (a *GenericAsset) ImportPaths() []string

func (*GenericAsset) IndexKey

func (a *GenericAsset) IndexKey() string

func (*GenericAsset) Initialize

func (a *GenericAsset) Initialize() error

func (*GenericAsset) Open

func (a *GenericAsset) Open() (*os.File, error)

func (*GenericAsset) OutputExt

func (a *GenericAsset) OutputExt() string

func (*GenericAsset) OutputPath

func (a *GenericAsset) OutputPath() string

func (*GenericAsset) Path

func (a *GenericAsset) Path() string

func (*GenericAsset) RelPath

func (a *GenericAsset) RelPath() (string, error)

func (*GenericAsset) SetIndexKey

func (a *GenericAsset) SetIndexKey(k string)

type JSXAsset

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

func (*JSXAsset) Checksum

func (a *JSXAsset) Checksum() string

func (*JSXAsset) Compile

func (a *JSXAsset) Compile() (io.Reader, error)

func (*JSXAsset) ImportPaths

func (a *JSXAsset) ImportPaths() []string

func (*JSXAsset) IndexKey

func (a *JSXAsset) IndexKey() string

func (*JSXAsset) Initialize

func (a *JSXAsset) Initialize() error

func (*JSXAsset) Open

func (a *JSXAsset) Open() (*os.File, error)

func (*JSXAsset) OutputExt

func (a *JSXAsset) OutputExt() string

func (*JSXAsset) OutputPath

func (a *JSXAsset) OutputPath() string

func (*JSXAsset) Path

func (a *JSXAsset) Path() string

func (*JSXAsset) RelPath

func (a *JSXAsset) RelPath() (string, error)

func (*JSXAsset) SetIndexKey

func (a *JSXAsset) SetIndexKey(key string)

type JavaScriptAsset

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

func (*JavaScriptAsset) Checksum

func (a *JavaScriptAsset) Checksum() string

func (*JavaScriptAsset) Compile

func (a *JavaScriptAsset) Compile() (io.Reader, error)

func (*JavaScriptAsset) ImportPaths

func (a *JavaScriptAsset) ImportPaths() []string

func (*JavaScriptAsset) IndexKey

func (a *JavaScriptAsset) IndexKey() string

func (*JavaScriptAsset) Initialize

func (a *JavaScriptAsset) Initialize() error

func (*JavaScriptAsset) Open

func (a *JavaScriptAsset) Open() (*os.File, error)

func (*JavaScriptAsset) OutputExt

func (a *JavaScriptAsset) OutputExt() string

func (*JavaScriptAsset) OutputPath

func (a *JavaScriptAsset) OutputPath() string

func (*JavaScriptAsset) Path

func (a *JavaScriptAsset) Path() string

func (*JavaScriptAsset) RelPath

func (a *JavaScriptAsset) RelPath() (string, error)

func (*JavaScriptAsset) SetIndexKey

func (a *JavaScriptAsset) SetIndexKey(k string)

type Manifest

type Manifest struct {
	Assets map[string]string `json:"assets"`
	// contains filtered or unexported fields
}

type Matrix

type Matrix struct {
	Manifest *Manifest
	Log      log.Logger
	// contains filtered or unexported fields
}

func New

func New(config *Config) *Matrix

func (*Matrix) Build

func (m *Matrix) Build() error

func (*Matrix) RemoveOldAssets

func (m *Matrix) RemoveOldAssets()

type SCSSAsset

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

func (*SCSSAsset) Checksum

func (a *SCSSAsset) Checksum() string

func (*SCSSAsset) Compile

func (a *SCSSAsset) Compile() (io.Reader, error)

func (*SCSSAsset) ImportPaths

func (a *SCSSAsset) ImportPaths() []string

func (*SCSSAsset) IndexKey

func (a *SCSSAsset) IndexKey() string

func (*SCSSAsset) Initialize

func (a *SCSSAsset) Initialize() error

func (*SCSSAsset) Open

func (a *SCSSAsset) Open() (*os.File, error)

func (*SCSSAsset) OutputExt

func (a *SCSSAsset) OutputExt() string

func (*SCSSAsset) OutputPath

func (a *SCSSAsset) OutputPath() string

func (*SCSSAsset) Path

func (a *SCSSAsset) Path() string

func (*SCSSAsset) RelPath

func (a *SCSSAsset) RelPath() (string, error)

func (*SCSSAsset) SetIndexKey

func (a *SCSSAsset) SetIndexKey(key string)

Jump to

Keyboard shortcuts

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