versacommerce-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f3e6de1645b8f340f9e406ba0bb2d3af03f5eb2
4
+ data.tar.gz: 877c844cd21384c804a9c3a98cad9416dbe488ac
5
+ SHA512:
6
+ metadata.gz: 23117f428585c826764f558529fcd54d925907092bc97fb92652f353094fd074bcf9c57ef4ef55b3f83d8f33e9d8236901456fdfc453363bcb11ac4cded20ed8
7
+ data.tar.gz: afba1ddf5d4f2eb0472c665d024d486eebf1ef2422d8209f371812cdf4b714b9beb6467242fd1f6d49d5e52f349097d348dc1847eb4fd8eeeab92413079b6ec8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 VersaCommerce
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # Versacommerce::CLI
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/versacommerce-cli.svg)](http://badge.fury.io/rb/versacommerce-cli)
4
+
5
+ Versacommerce::CLI is a Command Line Interface tool that interacts with several VersaCommerce-related services.
6
+
7
+ ## Requirements
8
+
9
+ Ruby ≥ 2.0.0
10
+
11
+ ## Installation
12
+
13
+ ```sh
14
+ $ gem install versacommerce-cli
15
+ ```
16
+
17
+ ## Commands
18
+
19
+ ### `vc-theme`
20
+
21
+ The `vc-theme` command has several subcommands that all need an Authorization in order to work. You can get such an Authorization from your shop's admin section.
22
+
23
+ There are 4 ways to provide an Authorization to the CLI, which are checked in order:
24
+
25
+ 1.
26
+ Provide an `authorization` command line option:
27
+
28
+ ```sh
29
+ vc-theme <subcommand> --authorization=YOUR_AUTHORIZATION
30
+ ```
31
+
32
+ 2.
33
+ Provide an explicit config file:
34
+
35
+ ```sh
36
+ vc-theme <subcommand> --config=path/to/config/file.yml
37
+ ```
38
+
39
+ The config file needs to be a YAML file. The value for an `authorization` key will be respected. Example config file:
40
+
41
+ ```yaml
42
+ authorization: YOUR_AUTHORIZATION
43
+ ```
44
+
45
+ 3.
46
+ Provide a `THEME_AUTHORIZATION` environment variable:
47
+
48
+ ```sh
49
+ THEME_AUTHORIZATION=YOUR_AUTHORIZATION vc-theme <subcommand>
50
+ ```
51
+
52
+ 4.
53
+ Provide an implicit config file. Same as 2, but the config file location is fix to `~/.config/versacommerce/cli/config.yml`.
54
+
55
+ The following subcommands are available:
56
+
57
+ #### `vc-theme download`
58
+
59
+ The `vc-theme download` subcommand is used to download a complete Theme from the Theme API. Usage:
60
+
61
+ ```sh
62
+ $ vc-theme download
63
+ ```
64
+
65
+ This will download the Authorization's Theme to a `theme` directory relative to the working directory. If you want to change the path the Theme is downloaded to, provide a `path` command line option:
66
+
67
+ ```sh
68
+ $ vc-theme download --path=path/to/directory
69
+ ```
70
+
71
+ The directory will be created by using `mkdir -p`, so you don't need to worry about its existence too much.
72
+
73
+ #### `vc-theme watch`
74
+
75
+ The `vc-theme watch` subcommand is used to synchronize local files to the Theme API. Usage:
76
+
77
+ ```sh
78
+ $ vc-theme watch
79
+ ```
80
+
81
+ This will watch for file changes made in (and below) the working directory. When a file is changed (created, modified, deleted), the change is also pushed to the Theme API. If you want to change the path that is being watched, provide a `path` command line option:
82
+
83
+ ```sh
84
+ $ vc-theme watch --path=path/to/directory
85
+ ```
86
+
87
+ ## Development
88
+
89
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
90
+
91
+ ## Contributing
92
+
93
+ 1. Fork it (https://github.com/versacommerce/versacommerce-cli/fork)
94
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
95
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
96
+ 4. Push to the branch (`git push origin my-new-feature`)
97
+ 5. Create a new Pull Request
98
+
99
+ ## License
100
+
101
+ [MIT](https://github.com/versacommerce/versacommerce-cli/blob/master/LICENSE.txt "MIT License").
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'versacommerce/cli'
5
+
6
+ require 'pry'
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/vc-theme ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'versacommerce/cli/theme'
4
+
5
+ Versacommerce::CLI::Theme.start
@@ -0,0 +1,39 @@
1
+ require 'colorize'
2
+
3
+ module Versacommerce
4
+ module CLI
5
+ class SimpleLogger
6
+ attr_accessor :verbose
7
+
8
+ def initialize(verbose)
9
+ @verbose = verbose
10
+ end
11
+
12
+ def info(*messages)
13
+ write(*messages)
14
+ end
15
+
16
+ def debug(*messages)
17
+ write(*messages) if verbose
18
+ end
19
+
20
+ def success(*messages)
21
+ colorized_messages = messages.map { |msg| msg.colorize(:green) }
22
+ write(*colorized_messages)
23
+ end
24
+
25
+ def error(*messages)
26
+ colorized_messages = messages.map { |msg| msg.colorize(:red) }
27
+ write(*colorized_messages)
28
+ end
29
+
30
+ private
31
+
32
+ def write(*messages)
33
+ messages.each do |message|
34
+ puts '-- %s' % message
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,117 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+ require 'yaml'
4
+
5
+ require 'thor'
6
+ require 'listen'
7
+
8
+ require 'versacommerce/cli/simple_logger'
9
+ require 'versacommerce/theme_api_client'
10
+
11
+ module Versacommerce
12
+ module CLI
13
+ class Theme < Thor
14
+ class_option :authorization
15
+ class_option :config
16
+ class_option :verbose, type: :boolean
17
+
18
+ desc 'download', 'Downloads a complete Theme from the Theme API.'
19
+ option :path, default: Pathname.pwd.join('theme')
20
+ def download
21
+ ensure_authorization!
22
+
23
+ path = Pathname.new(options[:path]).expand_path
24
+ logger.info('Downloading Theme to %s' % path)
25
+
26
+ client.files(recursive: true).each do |file|
27
+ logger.debug('Downloading %s' % file.path)
28
+ file.reload_content
29
+ file_path = path.join(file.path)
30
+ FileUtils.mkdir_p(file_path.parent)
31
+ File.open(file_path, 'wb') { |f| f.write(file.content) }
32
+ end
33
+
34
+ logger.success('Finished downloading Theme')
35
+ end
36
+
37
+ desc 'watch', 'Watches a directory and pushes file changes to the Theme API.'
38
+ option :path, default: Pathname.pwd
39
+ def watch
40
+ theme_path = Pathname.new(options[:path]).expand_path
41
+ logger.info 'Watching %s' % theme_path
42
+
43
+ listener = Listen.to(theme_path) do |modified, added, removed|
44
+ removed.each { |absolute_path| delete_file(theme_path, absolute_path) }
45
+
46
+ modified.concat(added).each do |absolute_path|
47
+ delete_file(theme_path, absolute_path)
48
+ add_file(theme_path, absolute_path)
49
+ end
50
+ end
51
+
52
+ listener.start
53
+ sleep
54
+ rescue SystemExit, Interrupt
55
+ logger.info('Stopped watching')
56
+ exit
57
+ end
58
+
59
+ private
60
+
61
+ def add_file(theme_path, absolute_path)
62
+ relative_path = Pathname.new(absolute_path).relative_path_from(theme_path)
63
+ file = client.files.build(path: relative_path, content: File.read(absolute_path))
64
+
65
+ if file.valid?
66
+ logger.debug('Trying to add %s' % relative_path)
67
+
68
+ if file.save
69
+ logger.success('Added %s' % relative_path)
70
+ else
71
+ logger.error('Could not add %s:' % relative_path)
72
+ file.errors.full_messages.each { |msg| logger.error(' %s' % msg) }
73
+ end
74
+ else
75
+ logger.error('Could not add %s:' % relative_path)
76
+ file.errors.full_messages.each { |msg| logger.error(' %s' % msg) }
77
+ end
78
+ end
79
+
80
+ def delete_file(theme_path, absolute_path, log: true)
81
+ relative_path = Pathname.new(absolute_path).relative_path_from(theme_path)
82
+ client.files.delete(relative_path)
83
+ rescue Versacommerce::ThemeAPIClient::Fetcher::RecordNotFoundError
84
+ end
85
+
86
+ def client
87
+ @client ||= ThemeAPIClient.new(authorization: authorization)
88
+ end
89
+
90
+ def ensure_authorization!
91
+ unless authorization
92
+ puts 'Could not find authorization.'
93
+ exit 1
94
+ end
95
+ end
96
+
97
+ def authorization
98
+ options[:authorization] || explicit_config['authorization'] || ENV['THEME_AUTHORIZATION'] || implicit_config['authorization']
99
+ end
100
+
101
+ def explicit_config
102
+ @explicit_config ||= options[:config] ? YAML.load_file(options[:config]) : {}
103
+ end
104
+
105
+ def implicit_config
106
+ @implicit_config ||= begin
107
+ config = Pathname.new('~/.config/versacommerce/cli/config.yml').expand_path
108
+ config.file? ? YAML.load_file(config) : {}
109
+ end
110
+ end
111
+
112
+ def logger
113
+ @logger ||= SimpleLogger.new(options[:verbose])
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,5 @@
1
+ module Versacommerce
2
+ module CLI
3
+ VERSION = Gem::Version.new('0.1.0')
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'versacommerce/cli/version'
2
+
3
+ module Versacommerce
4
+ module CLI; end
5
+ end
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'versacommerce/cli/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'versacommerce-cli'
7
+ spec.version = Versacommerce::CLI::VERSION
8
+ spec.authors = ['Tobias Bühlmann']
9
+ spec.email = ['buehlmann@versacommerce.de']
10
+
11
+ spec.summary = 'CLI tool for interacting with several VersaCommerce services.'
12
+ spec.description = 'Versacommerce::CLI is a Command Line Interface tool that interacts with several VersaCommerce-related services.'
13
+ spec.homepage = 'https://github.com/versacommerce/versacommerce-cli'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 2.0.0'
22
+
23
+ spec.add_runtime_dependency 'thor', '0.19.1'
24
+ spec.add_runtime_dependency 'listen', '~> 2.9'
25
+ spec.add_runtime_dependency 'colorize', '0.7.5'
26
+ spec.add_runtime_dependency 'versacommerce-theme_api_client', '0.1.0'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.8'
29
+ spec.add_development_dependency 'rake', '~> 10.4'
30
+ spec.add_development_dependency 'pry', '0.10.1'
31
+ spec.add_development_dependency 'pry-stack_explorer', '0.4.9.2'
32
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: versacommerce-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Bühlmann
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: listen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: versacommerce-theme_api_client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.10.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-stack_explorer
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.4.9.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.4.9.2
125
+ description: Versacommerce::CLI is a Command Line Interface tool that interacts with
126
+ several VersaCommerce-related services.
127
+ email:
128
+ - buehlmann@versacommerce.de
129
+ executables:
130
+ - vc-theme
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - exe/vc-theme
142
+ - lib/versacommerce/cli.rb
143
+ - lib/versacommerce/cli/simple_logger.rb
144
+ - lib/versacommerce/cli/theme.rb
145
+ - lib/versacommerce/cli/version.rb
146
+ - versacommerce-cli.gemspec
147
+ homepage: https://github.com/versacommerce/versacommerce-cli
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 2.0.0
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.4.5
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: CLI tool for interacting with several VersaCommerce services.
171
+ test_files: []