kit

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2017 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package kit is all of the tools used to interact with shopify themes.

Index

Constants

View Source
const DefaultEnvironment string = "development"

DefaultEnvironment is the environment that will be loaded if no environment is specified.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout to kill any stalled processes.

Variables

View Source
var BlueText = color.New(color.FgBlue).SprintFunc()

BlueText is a func that wraps a string in blue color tags and it will be blue when printed out.

View Source
var CyanText = color.New(color.FgCyan).SprintFunc()

CyanText is a func that wraps a string in cyan color tags and it will be cyan when printed out.

View Source
var ErrAssetIsDir = errors.New("loadAsset: File is a directory")

ErrAssetIsDir is the error returned if you try and load a directory with LocalAsset

View Source
var GreenText = color.New(color.FgGreen).SprintFunc()

GreenText is a func that wraps a string in green color tags and it will be green when printed out.

View Source
var RedText = color.New(color.FgRed).SprintFunc()

RedText is a func that wraps a string in red color tags and it will be red when printed out.

View Source
var (
	// ThemeKitVersion is the version build of the library
	ThemeKitVersion, _ = version.NewVersion("0.6.5")
)
View Source
var YellowText = color.New(color.FgYellow).SprintFunc()

YellowText is a func that wraps a string in yellow color tags and it will be yellow when printed out.

Functions

func CreateTheme

func CreateTheme(name, zipLocation string) (ThemeClient, Theme, error)

CreateTheme will create a unpublished new theme on your shopify store and then return a new theme client with the configuration of the new client.

func InstallThemeKitVersion

func InstallThemeKitVersion(ver string) error

InstallThemeKitVersion will take a semver string and parse it then check if that update is available and install it. If the string is 'latest' it will install the most current. If the string is latest and there is no update it will return an error. An error will also be returned if the requested version does not exist.

func IsNewUpdateAvailable

func IsNewUpdateAvailable() bool

IsNewUpdateAvailable will check if there is an update to the theme kit command and if there is one it will return true. Otherwise it will return false.

func LibraryInfo

func LibraryInfo() string

LibraryInfo will return a string array with information about the library used for logging.

func LogError

func LogError(args ...interface{})

LogError will output a red message to the output log (default stdout)

func LogErrorf

func LogErrorf(content string, args ...interface{})

LogErrorf will output a formatted red message to the output log (default stdout)

func LogFatal

func LogFatal(args ...interface{})

LogFatal will output a red message to the output log along with the library information. Then it will quit the application.

func LogFatalf

func LogFatalf(content string, args ...interface{})

LogFatalf will output a formatted red message to the output log along with the library information. Then it will quit the application.

func Print

func Print(args ...interface{})

Print will output a message to the output log (default stdout)

func PrintInfo

func PrintInfo()

PrintInfo will output the version banner for the themekit library.

func Printf

func Printf(content string, args ...interface{})

Printf will output a formatted message to the output log (default stdout)

func SetFlagConfig

func SetFlagConfig(config Configuration)

SetFlagConfig will set the configuration that is set by your applications flags. Set the flag config before inializing any theme clients so that the loaded configurations will have the proper config precedence.

Types

type Asset

type Asset struct {
	Key         string `json:"key"`
	Value       string `json:"value,omitempty"`
	Attachment  string `json:"attachment,omitempty"`
	ContentType string `json:"content_type,omitempty"`
	ThemeID     int64  `json:"theme_id,omitempty"`
}

Asset represents an asset from the shopify server.

func (Asset) Contents added in v0.6.4

func (asset Asset) Contents() ([]byte, error)

Contents will return a byte array of data for the asset contents

func (Asset) IsValid

func (asset Asset) IsValid() bool

IsValid verifies that the Asset has a Key, and at least a Value or Attachment

func (Asset) Size

func (asset Asset) Size() int

Size will return the length of the value or attachment depending on which exists.

func (Asset) Write added in v0.6.4

func (asset Asset) Write(directory string) error

Write will write the asset out to the destination directory

type ByAsset

type ByAsset []Asset

ByAsset implements sort.Interface for sorting remote assets

func (ByAsset) Len

func (assets ByAsset) Len() int

Len returns the length of the array.

func (ByAsset) Less

func (assets ByAsset) Less(i, j int) bool

Less is the comparison method. Will return true if the first is less than the second.

func (ByAsset) Swap

func (assets ByAsset) Swap(i, j int)

Swap swaps two values in the slive

type Configuration

type Configuration struct {
	Environment  string        `yaml:"-" json:"-" env:"-"`
	Password     string        `yaml:"password,omitempty" json:"password,omitempty" env:"THEMEKIT_PASSWORD"`
	ThemeID      string        `yaml:"theme_id,omitempty" json:"theme_id,omitempty" env:"THEMEKIT_THEME_ID"`
	Domain       string        `yaml:"store" json:"store" env:"THEMEKIT_STORE"`
	Directory    string        `yaml:"directory,omitempty" json:"directory,omitempty" env:"THEMEKIT_DIRECTORY"`
	IgnoredFiles []string      `yaml:"ignore_files,omitempty" json:"ignore_files,omitempty" env:"THEMEKIT_IGNORE_FILES" envSeparator:":"`
	Proxy        string        `yaml:"proxy,omitempty" json:"proxy,omitempty" env:"THEMEKIT_PROXY"`
	Ignores      []string      `yaml:"ignores,omitempty" json:"ignores,omitempty" env:"THEMEKIT_IGNORES" envSeparator:":"`
	Timeout      time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty" env:"THEMEKIT_TIMEOUT"`
	ReadOnly     bool          `yaml:"readonly,omitempty" json:"readonly,omitempty" env:"-"`
}

Configuration is the structure of a configuration for an environment. This will get loaded into a theme client to dictate it's actions.

func NewConfiguration

func NewConfiguration() (*Configuration, error)

NewConfiguration will format a Configuration that combines the config from env variables, flags. Then it will validate that config. It will return the formatted configuration along with any validation errors. The config precedence is flags, environment variables, then the config file.

func (Configuration) IsLive

func (conf Configuration) IsLive() bool

IsLive will return true if the configurations theme id is set to live

func (Configuration) String

func (conf Configuration) String() string

String will return a formatted string with the information about this configuration

func (Configuration) Validate

func (conf Configuration) Validate() error

Validate will check the configuration for any problems that will cause theme kit to function incorrectly.

type Environments

type Environments map[string]*Configuration

Environments is a map of configurations to their environment name.

func LoadEnvironments

func LoadEnvironments(location string) (env Environments, err error)

LoadEnvironments will read in the file from the location provided and then unmarshal the data into environments.

func (Environments) GetConfiguration

func (e Environments) GetConfiguration(environmentName string) (*Configuration, error)

GetConfiguration will return the configuration for the environment. An error will be returned if the environment does not exist or the configuration is invalid.

func (Environments) Save

func (e Environments) Save(location string) error

Save will write out the environment to a file.

func (Environments) SetConfiguration

func (e Environments) SetConfiguration(environmentName string, conf *Configuration)

SetConfiguration will update a config environment to the provided configuration.

type Error

type Error interface {
	Error() string
	Fatal() bool
}

Error is an error that can be determined if it is fatal to the applications operation.

type EventType

type EventType int

EventType is an enum of event types to compare against event.Type()

const (
	// Create specifies that an AssetEvent is a create event.
	Create EventType = iota
	// Retrieve specifies that an AssetEvent is an update event.
	Retrieve
	// Update specifies that an AssetEvent is an update event.
	Update
	// Remove specifies that an AssetEvent is an delete event.
	Remove
)

func (EventType) String

func (e EventType) String() string

type FileEventCallback

type FileEventCallback func(ThemeClient, Asset, EventType)

FileEventCallback is the callback that is called when there is an event from a file watcher.

type FileWatcher

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

FileWatcher is the object used to watch files for change and notify on any events, these events can then be passed along to kit to be sent to shopify.

func (*FileWatcher) IsWatching

func (watcher *FileWatcher) IsWatching() bool

IsWatching will return true if the watcher is currently watching for file changes. it will return false if it has been stopped

func (*FileWatcher) StopWatching

func (watcher *FileWatcher) StopWatching()

StopWatching will stop the Filewatcher from watching it's directories and clean up any go routines doing work.

func (*FileWatcher) WatchConfig added in v0.6.5

func (watcher *FileWatcher) WatchConfig(configFile string, reloadSignal chan bool) error

WatchConfig adds a priority watcher for the config file. A true will be sent down the channel to notify you about a config file change. This is useful to keep track of version control changes

type ShopifyResponse

type ShopifyResponse struct {
	Type      requestType  `json:"-"`
	Host      string       `json:"host"`
	URL       *url.URL     `json:"url"`
	Code      int          `json:"status_code"`
	Theme     Theme        `json:"theme"`
	Asset     Asset        `json:"asset"`
	Assets    []Asset      `json:"assets"`
	EventType EventType    `json:"event_type"`
	Errors    requestError `json:"errors"`
}

ShopifyResponse is a general response for all server requests. It will format errors from any bad responses from the server. If the response is Successful() then the data item that you requested should be defined. If it was a theme request then Theme will be defined. If you have mad an asset query then Assets will be defined. If you did an action on a single asset then Asset will be defined.

func (ShopifyResponse) Error

func (resp ShopifyResponse) Error() Error

func (ShopifyResponse) String

func (resp ShopifyResponse) String() string

func (ShopifyResponse) Successful

func (resp ShopifyResponse) Successful() bool

Successful will return true if the response code >= 200 and < 300 and if no errors were returned from the server.

type Theme

type Theme struct {
	ID          int64  `json:"id,omitempty"`
	Name        string `json:"name"`
	Source      string `json:"src,omitempty"`
	Role        string `json:"role,omitempty"`
	Previewable bool   `json:"previewable,omitempty"`
	Processing  bool   `json:"processing,omitempty"`
}

Theme represents a shopify theme.

type ThemeClient

type ThemeClient struct {
	Config *Configuration
	// contains filtered or unexported fields
}

ThemeClient is the interactor with the shopify server. All actions are processed with the client.

func NewThemeClient

func NewThemeClient(config *Configuration) (ThemeClient, error)

NewThemeClient will build a new theme client from a configuration and a theme event channel. The channel is used for logging all events. The configuration specifies how the client will behave.

func (ThemeClient) Asset

func (t ThemeClient) Asset(filename string) (Asset, Error)

Asset will load up a single remote asset from the remote shopify servers.

func (ThemeClient) AssetList

func (t ThemeClient) AssetList() ([]Asset, Error)

AssetList will return a slice of remote assets from the shopify servers. The assets are sorted and any ignored files based on your config are filtered out. The assets returned will not have any data, only ID and filenames. This is because fetching all the assets at one time is not a good idea.

func (ThemeClient) CreateAsset

func (t ThemeClient) CreateAsset(asset Asset) (*ShopifyResponse, Error)

CreateAsset will take an asset and will return when the asset has been created. If there was an error, in the request then error will be defined otherwise the response will have the appropropriate data for usage.

func (ThemeClient) DeleteAsset

func (t ThemeClient) DeleteAsset(asset Asset) (*ShopifyResponse, Error)

DeleteAsset will take an asset and will return when the asset has been deleted. If there was an error, in the request then error will be defined otherwise the response will have the appropropriate data for usage.

func (ThemeClient) LocalAsset

func (t ThemeClient) LocalAsset(filename string) (Asset, error)

LocalAsset will load a single local asset on disk. It will return an error if there is a problem loading the asset.

func (ThemeClient) LocalAssets

func (t ThemeClient) LocalAssets(paths ...string) (assets []Asset, err error)

LocalAssets will return a slice of assets from the local disk. The assets are filtered based on your config. If not paths are passed to the function then all the local assets are returned. If you pass file names those assets will be loaded. If any of the file paths are directories, all of the directory's recursive assets will be returned.

func (ThemeClient) NewFileWatcher

func (t ThemeClient) NewFileWatcher(notifyFile string, callback FileEventCallback) (*FileWatcher, error)

NewFileWatcher creates a new filewatcher using the theme clients file filter

func (ThemeClient) Perform

func (t ThemeClient) Perform(asset Asset, event EventType) (*ShopifyResponse, Error)

Perform will take in any asset and event type, and return after the request has taken place If there was an error, in the request then error will be defined otherwise the response will have the appropropriate data for usage.

func (ThemeClient) UpdateAsset

func (t ThemeClient) UpdateAsset(asset Asset) (*ShopifyResponse, Error)

UpdateAsset will take an asset and will return when the asset has been updated. If there was an error, in the request then error will be defined otherwise the response will have the appropropriate data for usage.

Jump to

Keyboard shortcuts

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