Documentation
¶
Overview ¶
Package kit is all of the tools used to interact with shopify themes.
Index ¶
- Constants
- Variables
- func CreateTheme(name, zipLocation string) (ThemeClient, Theme, error)
- func InstallThemeKitVersion(ver string) error
- func IsNewUpdateAvailable() bool
- func SetFlagConfig(config Configuration)
- type Asset
- type Configuration
- type Environments
- type Error
- type EventType
- type FileEventCallback
- type FileWatcher
- type Platform
- type Release
- type ReleasesList
- type ShopifyResponse
- type Theme
- type ThemeClient
- func (t ThemeClient) Asset(filename string) (Asset, Error)
- func (t ThemeClient) AssetInfo(filename string) (Asset, Error)
- func (t ThemeClient) AssetList() ([]Asset, Error)
- func (t ThemeClient) CreateAsset(asset Asset) (*ShopifyResponse, Error)
- func (t ThemeClient) DeleteAsset(asset Asset) (*ShopifyResponse, Error)
- func (t ThemeClient) LocalAsset(filename string) (Asset, error)
- func (t ThemeClient) LocalAssets(paths ...string) (assets []Asset, err error)
- func (t ThemeClient) NewFileWatcher(notifyFile string, callback FileEventCallback) (*FileWatcher, error)
- func (t ThemeClient) Perform(asset Asset, event EventType) (*ShopifyResponse, Error)
- func (t ThemeClient) PerformStrict(asset Asset, event EventType, version string) (*ShopifyResponse, Error)
- func (t ThemeClient) UpdateAsset(asset Asset) (*ShopifyResponse, Error)
Constants ¶
const DefaultEnvironment string = "development"
DefaultEnvironment is the environment that will be loaded if no environment is specified.
const DefaultTimeout = 30 * time.Second
DefaultTimeout is the default timeout to kill any stalled processes.
Variables ¶
var (
// ThemeKitVersion is the version build of the library
ThemeKitVersion, _ = version.NewVersion("0.7.2")
// 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"
)
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 ¶
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) Contents ¶ added in v0.6.4
Contents will return a byte array of data for the asset contents
func (Asset) IsValid ¶
IsValid verifies that the Asset has a Key, and at least a Value or Attachment
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, active bool) (*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 EventType ¶
type EventType int
EventType is an enum of event types to compare against event.Type()
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
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
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
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
IsApplicable will return true if this release is an update to the current running version of themekit
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.