zapnito-cli 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1df975bf83ac9b353ff15a52da5e9640b5d61b1
4
- data.tar.gz: 2384fe2b3a648593099f3b8dc5ba5e5b5dcefaef
3
+ metadata.gz: 169fd8403f72defe4f3cebee0e9d77918fc9ca13
4
+ data.tar.gz: af38f52b665d4c62c1270db7309ec276de3d0dee
5
5
  SHA512:
6
- metadata.gz: 6009e072865c6b6b3c589cac4de45f6d1eff86ad653565c77d2b26c243b224ad94d42ec2862bf784d6b61629d37dc6fd4bfbd1841ad7fd923c274065de2d4f50
7
- data.tar.gz: c71b9d5e3fd55f4827ae2a583d89b1b579e470da6832b8287281fd3052d2301532c4b51dda46debce14d22adf5cca0dd42efa7e367727b5d1576526f3d1d8677
6
+ metadata.gz: e105c1892608df4ad4df0e58c92d566c1e3b4d0c74c491906b68ad68f784f30e58c2251b956ca4044f48445434e45c70f1eaaed9b0f5c7d90629db193d7a6a33
7
+ data.tar.gz: a78c68658e6b98dae590a0520a6928e189baba01fec51f92b880576c2566566715c286e0bb933cf93b79895a43a3f7e55b48c980cd012f9cc327d42ed112d41c
data/README.md CHANGED
@@ -4,33 +4,73 @@
4
4
 
5
5
  $ gem install zapnito-cli
6
6
 
7
- Add your api token to `~/.zapnito`
8
7
 
9
- {
10
- "apiToken": "yourZapnitoApiToken"
8
+ ## Configure
9
+ Add the following configuration to `~/.zapnito`
10
+ ```JSON
11
+ {
12
+ "environments": {
13
+ "development": {
14
+ "basepath": "http://zapnito.localhost",
15
+ "token": "your dev API token"
16
+ },
17
+ "stage": {
18
+ "basepath": "https://staging-zapnito.com",
19
+ "token": "your stage API token"
20
+ },
21
+ "production": {
22
+ "basepath": "https://zapnito.com",
23
+ "token": "your production API token"
11
24
  }
25
+ },
26
+ "debug": false
27
+ }
28
+ ```
29
+ Your api_token is generated automatically and is available on your account (`user.api_token`).
30
+
31
+ The environments are all optional, commands will be shown for a particular environment if the configuration is provided.
32
+
12
33
 
13
34
  ## Usage
14
35
 
15
36
  ### Create a theme for a tenant
37
+ This will create a new directory for the tenant with the basic folder structure for a theme.
16
38
 
17
39
  $ zapnito theme add
18
40
 
19
41
  ### Publish a theme
42
+ To upload the theme to s3.
20
43
 
21
- $ zapnito theme publish
44
+ $ zapnito theme production:publish
22
45
 
23
46
  ### Preview in browser
47
+ This will open a preview in the browser. Note, you need to publish a theme before previewing.
24
48
 
25
- $ zapnito theme preview
49
+ $ zapnito theme production:preview
26
50
 
27
51
  ### Generate a preview link to share
28
52
 
29
- $ zapnito theme preview_link
53
+ $ zapnito theme production:preview_link
30
54
 
31
- ## Development options
55
+ ## Development
32
56
 
57
+ ### Options
58
+ The following may be adding to your `~/.zapnito` config. `developmentThemeDir` is required if you want to run the executable.
59
+ ```
33
60
  {
61
+ "environments": ...
34
62
  "proxy": "http://localhost:8888",
35
- "debug": true
63
+ "debug": true,
64
+ "developmentThemeDir: "path/to/local/theme/used/when/developing"
36
65
  }
66
+ ```
67
+
68
+ ### Running the cli
69
+ To run the cli during development use
70
+ ```
71
+ bundle exec ./exe/zapnito
72
+ ```
73
+
74
+
75
+ ### Gem tasks
76
+ See `rake -T` for a list of tasks
@@ -1,5 +1,6 @@
1
1
  require "pry"
2
2
 
3
+ require 'ruby-try'
3
4
  require "zapnito/cli/version"
4
5
  require "zapnito/cli/utils"
5
6
  require "zapnito/cli/initializers/configatron"
@@ -13,6 +14,7 @@ require "zapnito/cli/services"
13
14
  require "zapnito/cli/questions"
14
15
  require "thor"
15
16
  require "zapnito/cli/commands/theme"
17
+ require "zapnito/cli/commands/environment"
16
18
  require "zapnito/cli/commands/development_theme"
17
19
  require "zapnito/cli/commands/stage_theme"
18
20
  require "zapnito/cli/commands/production_theme"
@@ -20,14 +22,23 @@ require "zapnito/cli/commands/production_theme"
20
22
  module Zapnito
21
23
  module Cli
22
24
  class Main < Thor
23
- desc "development:theme COMMANDS", "Development Theme control"
24
- subcommand "development:theme", Zapnito::Cli::Commands::DevelopmentTheme
25
+ desc "theme COMMANDS", "General theme commands"
26
+ subcommand "theme", Zapnito::Cli::Commands::Theme
25
27
 
26
- desc "stage:theme COMMANDS", "Stage theme control"
27
- subcommand "stage:theme", Zapnito::Cli::Commands::StageTheme
28
+ if configatron.environments.has_key?(:development)
29
+ desc "development:theme COMMANDS", "Development Theme control"
30
+ subcommand "development:theme", Zapnito::Cli::Commands::DevelopmentTheme
31
+ end
28
32
 
29
- desc "production:theme COMMANDS", "Production Theme control"
30
- subcommand "production:theme", Zapnito::Cli::Commands::ProductionTheme
33
+ if configatron.environments.has_key?(:stage)
34
+ desc "stage:theme COMMANDS", "Stage theme control"
35
+ subcommand "stage:theme", Zapnito::Cli::Commands::StageTheme
36
+ end
37
+
38
+ if configatron.environments.has_key?(:production)
39
+ desc "production:theme COMMANDS", "Production Theme control"
40
+ subcommand "production:theme", Zapnito::Cli::Commands::ProductionTheme
41
+ end
31
42
  end
32
43
  end
33
44
  end
@@ -6,7 +6,7 @@ require "highline"
6
6
  module Zapnito
7
7
  module Cli
8
8
  module Commands
9
- class DevelopmentTheme < Theme
9
+ class DevelopmentTheme < Environment
10
10
  def environment
11
11
  :development
12
12
  end
@@ -0,0 +1,70 @@
1
+ require "rest-client"
2
+ require "json"
3
+ require "launchy"
4
+ require "highline"
5
+
6
+ module Zapnito
7
+ module Cli
8
+ module Commands
9
+ class Environment < Thor
10
+ desc "publish", "publishes the theme in the current directory"
11
+ def publish
12
+ theme = Services.local.load
13
+ puts "---> Publishing #{theme.tenant_slug}"
14
+
15
+ release_config = zapnito.s3_upload_urls_for_theme(theme)
16
+ Services.s3.upload_theme(theme, release_config)
17
+ zapnito.build_release(theme)
18
+
19
+ puts "---> Published #{theme.tenant_slug}/#{theme.revision}"
20
+ rescue Exception => e
21
+ if e.try(:response).try(:code) == 406
22
+ show_sass_error(e)
23
+ else
24
+ raise e
25
+ end
26
+ end
27
+
28
+ desc "preview_link", "show preview link for current theme"
29
+ def preview_link
30
+ theme = Services.local.load
31
+ link = zapnito.preview_link(theme)
32
+ puts "---> #{link}"
33
+ end
34
+
35
+ desc "preview", "preview current theme in browser"
36
+ def preview
37
+ theme = Services.local.load
38
+ link = zapnito.preview_link(theme)
39
+ puts "link: #{link}"
40
+ Launchy.open(link)
41
+ end
42
+
43
+ private
44
+
45
+ def zapnito
46
+ Services.zapnito(api_token, basepath)
47
+ end
48
+
49
+ def show_sass_error(e)
50
+ error = JSON.parse(e.response)["error"]
51
+ puts "---! #{error["message"]}"
52
+ puts "=========================="
53
+ puts "---! #{error["sass_backtrace"]}"
54
+ end
55
+
56
+ def api_token
57
+ configatron.environments[environment].api_token!
58
+ end
59
+
60
+ def basepath
61
+ configatron.environments[environment].basepath!
62
+ end
63
+
64
+ def environment
65
+ raise "not implemented"
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -6,7 +6,7 @@ require "highline"
6
6
  module Zapnito
7
7
  module Cli
8
8
  module Commands
9
- class ProductionTheme < Theme
9
+ class ProductionTheme < Environment
10
10
  def environment
11
11
  :production
12
12
  end
@@ -6,7 +6,7 @@ require "highline"
6
6
  module Zapnito
7
7
  module Cli
8
8
  module Commands
9
- class StageTheme < Theme
9
+ class StageTheme < Environment
10
10
  def environment
11
11
  :stage
12
12
  end
@@ -3,6 +3,7 @@ require "json"
3
3
  require "launchy"
4
4
  require "highline"
5
5
 
6
+
6
7
  module Zapnito
7
8
  module Cli
8
9
  module Commands
@@ -12,64 +13,6 @@ module Zapnito
12
13
  tenant_slug = Questions.which_slug?(api_token)
13
14
  Services.local.create_theme!(tenant_slug)
14
15
  end
15
-
16
- desc "publish", "publishes the theme in the current directory"
17
- def publish
18
- theme = Services.local.load
19
- puts "---> Publishing #{theme.tenant_slug}"
20
-
21
- release_config = zapnito.s3_upload_urls_for_theme(theme)
22
- Services.s3.upload_theme(theme, release_config)
23
- zapnito.build_release(theme)
24
-
25
- puts "---> Published #{theme.tenant_slug}/#{theme.revision}"
26
- rescue Exception => e
27
- if e.response.code == 406
28
- show_sass_error(e)
29
- else
30
- raise e
31
- end
32
- end
33
-
34
- desc "preview_link", "show preview link for current theme"
35
- def preview_link
36
- theme = Services.local.load
37
- link = zapnito.preview_link(theme)
38
- puts "---> #{link}"
39
- end
40
-
41
- desc "preview", "preview current theme in browser"
42
- def preview
43
- theme = Services.local.load
44
- link = zapnito.preview_link(theme)
45
- puts "link: #{link}"
46
- Launchy.open(link)
47
- end
48
-
49
- private
50
-
51
- def zapnito
52
- Services.zapnito(api_token, basepath)
53
- end
54
-
55
- def show_sass_error(e)
56
- error = JSON.parse(e.response)["error"]
57
- puts "---! #{error["message"]}"
58
- puts "=========================="
59
- puts "---! #{error["sass_backtrace"]}"
60
- end
61
-
62
- def api_token
63
- configatron.environments[environment].api_token!
64
- end
65
-
66
- def basepath
67
- configatron.environments[environment].basepath!
68
- end
69
-
70
- def environment
71
- raise "not implemented"
72
- end
73
16
  end
74
17
  end
75
18
  end
@@ -1,15 +1,23 @@
1
1
  require "configatron"
2
2
  require "json"
3
3
 
4
+ def assign_environment_config!(json_config)
5
+ puts json_config.inspect
6
+ if json_config
7
+ configatron_environment = yield
8
+ configatron_environment.basepath = json_config["basepath"]
9
+ configatron_environment.api_token = json_config["apiToken"]
10
+ end
11
+ end
12
+
4
13
  begin
5
14
  config = JSON.parse(File.read(File.expand_path("~/.zapnito")))
15
+ environments = config["environments"]
16
+ raise "Invalid json structure, see README for details" unless environments
6
17
 
7
- configatron.environments.development.basepath = config["environments"]["development"]["basepath"]
8
- configatron.environments.development.api_token = config["environments"]["development"]["apiToken"]
9
- configatron.environments.stage.basepath = config["environments"]["stage"]["basepath"]
10
- configatron.environments.stage.api_token = config["environments"]["stage"]["apiToken"]
11
- configatron.environments.production.basepath = config["environments"]["production"]["basepath"]
12
- configatron.environments.production.api_token = config["environments"]["production"]["apiToken"]
18
+ assign_environment_config!(environments["development"]) { configatron.environments.development }
19
+ assign_environment_config!(environments["stage"]) { configatron.environments.stage }
20
+ assign_environment_config!(environments["production"]) { configatron.environments.production }
13
21
 
14
22
  configatron.working_dir = begin
15
23
  dir_name = Dir.getwd
@@ -1,5 +1,5 @@
1
1
  module Zapnito
2
2
  module Cli
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency "json", "1.8.3"
35
35
  spec.add_dependency "thread_safe", "0.3.4"
36
36
  spec.add_dependency "minitest", "5.1"
37
+ spec.add_dependency "ruby-try", "1.1.1"
37
38
 
38
39
  spec.add_development_dependency "bundler", "~> 1.11"
39
40
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zapnito-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - opsb
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -220,6 +220,20 @@ dependencies:
220
220
  - - '='
221
221
  - !ruby/object:Gem::Version
222
222
  version: '5.1'
223
+ - !ruby/object:Gem::Dependency
224
+ name: ruby-try
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - '='
228
+ - !ruby/object:Gem::Version
229
+ version: 1.1.1
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - '='
235
+ - !ruby/object:Gem::Version
236
+ version: 1.1.1
223
237
  - !ruby/object:Gem::Dependency
224
238
  name: bundler
225
239
  requirement: !ruby/object:Gem::Requirement
@@ -281,6 +295,7 @@ files:
281
295
  - exe/zapnito
282
296
  - lib/zapnito/cli.rb
283
297
  - lib/zapnito/cli/commands/development_theme.rb
298
+ - lib/zapnito/cli/commands/environment.rb
284
299
  - lib/zapnito/cli/commands/production_theme.rb
285
300
  - lib/zapnito/cli/commands/stage_theme.rb
286
301
  - lib/zapnito/cli/commands/theme.rb
@@ -316,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
331
  version: '0'
317
332
  requirements: []
318
333
  rubyforge_project:
319
- rubygems_version: 2.6.3
334
+ rubygems_version: 2.6.12
320
335
  signing_key:
321
336
  specification_version: 4
322
337
  summary: Command line tools for Zapnito