kit

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 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 (
	// ThemeKitVersion is the version build of the library
	ThemeKitVersion, _ = version.NewVersion("0.7.5")
	// ThemeKitReleasesURL is the url that fetches all versions of themekit used for.
	// updating themekit. Change this for testing reasons.
	ThemeKitReleasesURL = "https://shopify-themekit.s3.amazonaws.com/releases/all.json"
	// ThemeKitLatestURL is the url that fetches new version of themekit. Change this
	// for testing reasons.
	ThemeKitLatestURL = "https://shopify-themekit.s3.amazonaws.com/releases/latest.json"
)
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

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 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"`
	UpdatedAt   string `json:"updated_at,omitempty"`
}

Asset represents an asset from the shopify server.

func (Asset) CheckSum added in v0.7.1

func (asset Asset) CheckSum() (string, error)

CheckSum will return the checksum of this asset

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 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) 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. The active parameter indicates if the configuration should take configuration values from environment and flags. This is considered active because passive configurations only take configuration from the config file and defaults.

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 Platform added in v0.7.0

type Platform struct {
	Name       string `json:"name"`
	URL        string `json:"url"`
	Digest     string `json:"digest"`
	TargetPath string `json:"TargetPath,omitempty"` // used for testing updating
}

Platform contains information for a release for a single architecture and operating system. It contains all the information needed to fetch it.

Used for internal purposes but exposed for cross package functionality

type Release added in v0.7.0

type Release struct {
	Version   string     `json:"version"`
	Platforms []Platform `json:"platforms"`
}

Release is a version of themekit released to the public.

Used for internal purposes but exposed for cross package functionality

func FetchLatest added in v0.7.0

func FetchLatest() (Release, error)

FetchLatest fetches the most recently released version of themekit.

Used for internal purposes but exposed for cross package functionality

func (Release) ForCurrentPlatform added in v0.7.0

func (r Release) ForCurrentPlatform() Platform

ForCurrentPlatform will return the platform release for the current running operating system and arch

func (Release) GetVersion added in v0.7.0

func (r Release) GetVersion() *version.Version

GetVersion will return the formatted version of this release.

func (Release) IsApplicable added in v0.7.0

func (r Release) IsApplicable() bool

IsApplicable will return true if this release is an update to the current running version of themekit

func (Release) IsValid added in v0.7.0

func (r Release) IsValid() bool

IsValid returns true if there are any platforms for this release

type ReleasesList added in v0.7.0

type ReleasesList []Release

ReleasesList is a list of releases fetched from the server

func FetchReleases added in v0.7.0

func FetchReleases() (ReleasesList, error)

FetchReleases fetches all the versions of themekit ever released.

Used for internal purposes but exposed for cross package functionality

func (ReleasesList) Del added in v0.7.0

func (releases ReleasesList) Del(ver string) ReleasesList

Del will find and remove a version from the list. The altered ReleaseList is returned

func (ReleasesList) Get added in v0.7.0

func (releases ReleasesList) Get(ver string) Release

Get will return the requested release by name. If no release is found, an invalid release will be returned.

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) 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) AssetInfo added in v0.7.0

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

AssetInfo will load up only the info for 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) PerformStrict added in v0.7.0

func (t ThemeClient) PerformStrict(asset Asset, event EventType, version string) (*ShopifyResponse, Error)

PerformStrict 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. It will only update if the we are updating the expected version otherwise it will return and error

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