magnetize 2.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d8b644b0a8c6dfe892a68db2e9ae1ed86c07eb7
4
- data.tar.gz: cbf056152442454a0316fa56e5912e078e098010
3
+ metadata.gz: 00ff7b00bb1b5c515f9c29bdaaef0a3035b4e152
4
+ data.tar.gz: aa82c320aba75b03924325648911dac54d56941c
5
5
  SHA512:
6
- metadata.gz: 4bbbf8569217b460960001da052650642bf69b96807c33111d314c32d410589eae3e8df7d831fa2648b3c421c9d69cbe30182e270f2c553e6dc1148549960a80
7
- data.tar.gz: e714f703eaf7a62c644f2f32f39c650bec866c40a65c79880ccd070dba088356442331fb1a06a5587ce89996aea4896fa518ac21d63213314e244001a154fad3
6
+ metadata.gz: cca97b3a16b13df03c4bf78e42d5d9392a4128a308cf5ac0f760957426f76ae49e3917bfe7e25c80fee97d0cd3d5335072c689fa62567a19160b43aad2ed1d53
7
+ data.tar.gz: f4a61f916052fa0b46d772d3a985b2b7eaf1e1054bed2f4417cdb7b1daf1f53a3def29243d76aae44b007f3dcb2b2f1d6e0bb4654690347aa9f8fb16b27b9f2d
data/README.md CHANGED
@@ -4,9 +4,9 @@ CLI and library for generating Magento local.xml files.
4
4
  Generates both `app/etc/local.xml` and `errors/local.xml` from the a specified [TOML]() configuration file.
5
5
  Also supports converting an existing Magento XML configuration file into a TOML file.
6
6
 
7
- Prefixes the TOML data with the `type` of Magento configuration file so that multiple Magento `local.xml` files can be stored in a common configuration and then seperate files be generated larter.
7
+ Prefixes the TOML data with the `type` of Magento configuration file so that multiple Magento `local.xml` files can be stored in a common configuration and then separate files be generated later.
8
8
 
9
- Supports arbitrary values in the both the `local.xml` and toml config, so new configration can be added without prior knowlege.
9
+ Supports arbitrary values in the both the `local.xml` and toml config, so new configuration can be added without prior knowledge.
10
10
 
11
11
 
12
12
  ## Installation
@@ -35,11 +35,13 @@ opts = {
35
35
  :types => {
36
36
  'app' => {
37
37
  :magento => 'app/etc/local.xml',
38
- :toml => 'config.toml'
38
+ :toml => 'config.toml',
39
+ :content => nil # optional raw content
39
40
  },
40
41
  'errors' => {
41
42
  :magento => 'errors/local.xml',
42
- :toml => 'config.toml'
43
+ :toml => 'config.toml',
44
+ :content => nil # optional raw content
43
45
  }
44
46
  }
45
47
  }
@@ -55,11 +57,49 @@ Magnetize::Convert.new.to_magento(opts)
55
57
  ```
56
58
 
57
59
 
60
+ ### Capistrano
61
+
62
+ `Capfile`:
63
+ ```ruby
64
+ require 'magnetize/capistrano'
65
+ ```
66
+ This adds two tasks to your Cap:
67
+
68
+ - `magentize:push`: sends your configured local TOML up to the servers as Magento XML.
69
+ - `magnetize:pull`: pulls down a local copy of the configured Magento XML as TOML.
70
+
71
+ And then to deploy every time:
72
+
73
+ `deploy.rb`:
74
+ ```
75
+ before 'deploy:check:linked_files', 'magnetize:push'
76
+
77
+ ```
78
+
79
+
80
+ Configuration and default values
81
+
82
+ ```
83
+ set :magnetize_roles, :app # roles to magnetize on push
84
+ set :magnetize_dir, '.' # local magnento dir, relative to capistrano
85
+ set :magnetize_appxml_path, 'app/etc' # app/etc/local.xml directory relative to cap
86
+ set :magnetize_errorsxml_path, 'errors' # errors/local.xml directory relative to cap
87
+ set :magnetize_toml, 'config.toml' # toml to magnetize
88
+ set :magnetize_force, false # overwrite existing TOML (takes effect on PULL only)
89
+ ```
90
+
91
+ To use a different TOML per stage you could do something like:
92
+
93
+ in deploy/production.rb: `set :magnetize_toml, 'magnetize.production.toml'`
94
+
95
+ in deploy/staging.rb: `set :magnetize_toml, 'magnetize.staging.toml'`
96
+
97
+
58
98
  ## Version 1
59
99
 
60
- Version 1 is functionally equivalent in that it generates `local.xml` files from `ENV`. However it relies on all configuration values being present in the template which it's output to. This means it's inflexible when dealing with new configuration options.
100
+ Version 1 is functionally equivalent in that it generates `local.xml` files from `ENV`. However it relies on all configuration values being present in the template it's output to. This means it's inflexible when dealing with new configuration options.
61
101
 
62
- Version 2 is a complete re-write and as such is API incompatable with V1. V1 is available here on [this branch](https://github.com/rjocoleman/magnetize/tree/v1)
102
+ Version 2 is a complete re-write and is API incompatible with V1. V1 is available here on [this branch](https://github.com/rjocoleman/magnetize/tree/v1)
63
103
 
64
104
 
65
105
  ## Contributing
@@ -0,0 +1,5 @@
1
+ require 'magnetize/convert'
2
+ require 'highline/import'
3
+
4
+ # Load capistrano tasks
5
+ load File.expand_path('../tasks/magnetize.rake', __FILE__)
@@ -3,34 +3,38 @@ require 'thor'
3
3
  module Magnetize
4
4
  class CLI < Thor
5
5
  default_task :help
6
-
6
+
7
7
  desc 'to_magento', 'Write Magento XML from TOML config'
8
8
  method_option :type, :type => :string, :required => false, :desc => 'Type of Magento config (e.g. app, errors). TOML is pulled from this prefix.' # ['app', 'errors']
9
9
  method_option :input, :type => :string, :required => false, :desc => 'Path to input TOML file' # local.toml
10
10
  method_option :output, :type => :string, :required => false, :desc => 'Path to output XML file' # app/etc/local.xml
11
11
  method_option :force, :type => :boolean, :required => false, :desc => 'Overwrite existing output file'
12
+ method_option :dir, :type => :string, :required => false, :desc => 'Magento directory', :default => '.'
12
13
  def to_magento
13
14
  unless options[:type] && options[:input] && options[:output]
14
15
  Magnetize::Convert.new.to_magento write: true
15
16
  else
16
17
  Magnetize::Convert.new.to_magento write: true, types: { options[:type] => { :magento => options[:output], :toml => options[:input] }}
17
18
  end
18
-
19
+
19
20
  end
20
-
21
+
21
22
  desc 'to_toml', 'Write TOML from existing Magento config'
22
23
  method_option :type, :type => :string, :required => false, :desc => 'Type of Magento config (e.g. app, errors). Used as prefix in TOML.' # ['app', 'errors']
23
24
  method_option :input, :type => :string, :required => false, :desc => 'Path to input XML file' # app/etc/local.xml
24
25
  method_option :output, :type => :string, :required => false, :desc => 'Path to output TOML file' # local.toml
25
26
  method_option :force, :type => :boolean, :required => false, :desc => 'Overwrite existing output file'
27
+ method_option :dir, :type => :string, :required => false, :desc => 'Magento directory', :default => '.'
26
28
  def to_toml
27
- unless options[:type] && options[:input] && options[:output]
28
- Magnetize::Convert.new.to_toml write: true
29
- else
30
- Magnetize::Convert.new.to_toml write: true, types: { options[:type] => { :magento => options[:input], :toml => options[:output] }}
29
+ Dir.chdir(options[:dir]) do
30
+ unless options[:type] && options[:input] && options[:output]
31
+ Magnetize::Convert.new.to_toml write: true
32
+ else
33
+ Magnetize::Convert.new.to_toml write: true, types: { options[:type] => { :magento => options[:input], :toml => options[:output] }}
34
+ end
31
35
  end
32
36
  end
33
-
37
+
34
38
  end
35
39
  end
36
40
 
@@ -2,52 +2,66 @@ require 'toml'
2
2
  require 'active_support/core_ext/hash'
3
3
  require 'gyoku'
4
4
  require 'thor'
5
+ require 'deep_merge'
5
6
 
6
7
  module Magnetize
7
8
  class Convert < Thor
8
9
  include Thor::Shell
9
-
10
+
10
11
  DEFAULTS = {
11
12
  :force => false,
12
13
  :write => false,
13
14
  :types => {
14
15
  'app' => {
15
16
  :magento => 'app/etc/local.xml',
16
- :toml => 'config.toml'
17
+ :toml => 'config.toml',
18
+ :content => nil
17
19
  },
18
20
  'errors' => {
19
21
  :magento => 'errors/local.xml',
20
- :toml => 'config.toml'
22
+ :toml => 'config.toml',
23
+ :content => nil
21
24
  }
22
25
  }
23
26
  }
24
-
27
+
25
28
  no_commands do
26
29
  def to_magento(options = {})
27
- options = DEFAULTS.merge(options)
30
+ options = DEFAULTS.deep_merge(options)
28
31
  result = {}
29
32
  options[:types].each do |type, config|
30
33
  input = File.expand_path(config[:toml])
31
34
  output = File.expand_path(config[:magento])
32
- hash = read_toml(input)
33
- xml = make_xml(hash[type.to_sym])
35
+ if config[:content]
36
+ hash = TOML.load(config[:content])
37
+ else
38
+ hash = read_toml(input)
39
+ end
40
+ xml = make_xml(hash[type.to_s])
34
41
  if options[:write]
35
42
  write(output, xml, options[:force])
36
43
  else
37
- result[type] = xml
44
+ result[config[:magento]] = xml
38
45
  end
39
46
  end
40
47
  return result unless options[:write]
41
48
  end
42
-
49
+
43
50
  def to_toml(options = {})
44
- options = DEFAULTS.merge(options)
51
+ options = DEFAULTS.deep_merge(options)
45
52
  result = {}
46
53
  options[:types].each do |type, config|
47
54
  input = File.expand_path(config[:magento])
48
- output = File.expand_path(config[:toml])
49
- hash = { type.to_sym => read_xml(input) }
50
- toml = make_toml(hash)
55
+ output = File.expand_path(config[:toml]) if config[:toml]
56
+ if config[:content]
57
+ xml = config[:content]
58
+ else
59
+ xml = IO.read(input)
60
+ end
61
+ hash = { type.to_s => read_xml(xml) }
62
+ config = read_toml(output)
63
+ config.merge!(hash)
64
+ toml = make_toml(config)
51
65
  if options[:write]
52
66
  write(output, toml, options[:force])
53
67
  else
@@ -56,27 +70,31 @@ module Magnetize
56
70
  end
57
71
  return result unless options[:write]
58
72
  end
59
-
73
+
60
74
  end # no_commands
61
-
75
+
62
76
  private
63
-
77
+
64
78
  def read_toml(path)
65
- TOML.load_file(path, symbolize_keys: true)
79
+ if !path.nil? && File.exists?(path)
80
+ TOML.load_file(path)
81
+ else
82
+ {}
83
+ end
66
84
  end
67
-
85
+
68
86
  def make_toml(hash)
69
- TOML.dump(hash)
87
+ TOML::Generator.new(hash).body
70
88
  end
71
-
72
- def read_xml(path)
73
- Hash.from_xml(IO.read(path))
89
+
90
+ def read_xml(xml)
91
+ replace_nil(Hash.from_xml(xml))
74
92
  end
75
-
93
+
76
94
  def make_xml(hash)
77
95
  Gyoku.xml(hash, { :key_converter => :none, :builder => { :indent => 2 } })
78
96
  end
79
-
97
+
80
98
  def write(path, content, force=false)
81
99
  FileUtils.mkdir_p(File.dirname(path))
82
100
  unless force
@@ -88,22 +106,16 @@ module Magnetize
88
106
  File.open(path, 'w') {|f| f.write(content)}
89
107
  puts "----> Wrote #{File.basename(path)}"
90
108
  end
91
-
92
- end
93
- end
94
109
 
95
- # yuck, bad bad hack
96
- module TOML
97
- class Dumper
98
- def to_toml(obj)
99
- case
100
- when obj.is_a?(Time)
101
- obj.strftime('%Y-%m-%dT%H:%M:%SZ')
102
- when obj.nil?
103
- obj = '""'
104
- else
105
- obj.inspect
110
+ def replace_nil(h)
111
+ h.each_pair do |k,v|
112
+ if v.is_a?(Hash)
113
+ replace_nil(v)
114
+ else
115
+ h[k] = v.to_s if v.nil?
116
+ end
106
117
  end
107
118
  end
119
+
108
120
  end
109
121
  end
@@ -0,0 +1,74 @@
1
+ namespace :magnetize do
2
+ desc 'Push local TOML config to remote Magento installation as Magento config file format'
3
+ task :push do
4
+ Dir.chdir(fetch(:magnetize_dir)) do
5
+ on roles fetch(:magnetize_roles), in: :parallel do
6
+ config = Magnetize::Convert.new.to_magento({
7
+ :write => false,
8
+ :types => {
9
+ 'app' => {
10
+ :magento => "#{fetch(:magnetize_appxml_path)}/local.xml",
11
+ :content => IO.read(fetch(:magnetize_toml))
12
+ },
13
+ 'errors' => {
14
+ :magento => "#{fetch(:magnetize_errorsxml_path)}/local.xml",
15
+ :content => IO.read(fetch(:magnetize_toml))
16
+ }
17
+ }
18
+ })
19
+ config.each do |path, config|
20
+ upload! StringIO.new(config), "#{shared_path}/#{path}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ desc 'Pull remote Magento config to local TOML config'
27
+ task :pull do
28
+ Dir.chdir(fetch(:magnetize_dir)) do
29
+ on primary fetch(:magnetize_roles) do
30
+ within "#{shared_path}" do
31
+ config = Magnetize::Convert.new.to_toml({
32
+ :write => false,
33
+ :types => {
34
+ 'app' => {
35
+ :content => capture(:cat, "#{fetch(:magnetize_localxml_path)}/local.xml"),
36
+ :toml => nil
37
+ },
38
+ 'errors' => {
39
+ :content => capture(:cat, "#{fetch(:magnetize_errorsxml_path)}/local.xml"),
40
+ :toml => nil
41
+ }
42
+ }
43
+ })
44
+ run_locally do
45
+ # yeah sooo, welcome to my nightmare. Capistrano v3's ask method doesn't cut it for this use case.
46
+ if File.exists?(fetch(:magnetize_toml)) && !fetch(:magnetize_force)
47
+ fail "#{fetch(:magnetize_dir)}/#{fetch(:magnetize_toml)} already exists, remove it or set :magnetize_force, true"
48
+ elsif File.exists?(fetch(:magnetize_toml)) && fetch(:magnetize_force)
49
+ info "#{fetch(:magnetize_dir)}/#{fetch(:magnetize_toml)} already exists - Forced overwriting (:magnetize_force is true)"
50
+ end
51
+ if !File.exists?(fetch(:magnetize_toml)) || fetch(:magnetize_force)
52
+ File.open(fetch(:magnetize_toml), 'w') {|f| f.write( config.values.join ) }
53
+ info "#{fetch(:magnetize_dir)}/#{fetch(:magnetize_toml)} has been written"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ namespace :load do
64
+ task :defaults do
65
+
66
+ set :magnetize_roles, :app
67
+ set :magnetize_dir, '.'
68
+ set :magnetize_appxml_path, 'app/etc'
69
+ set :magnetize_errorsxml_path, 'errors'
70
+ set :magnetize_toml, 'config.toml'
71
+ set :magnetize_force, false
72
+
73
+ end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module Magnetize
2
- VERSION = '2.0.0'
2
+ VERSION = '2.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magnetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Coleman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-04 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: pry
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: thor
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +53,7 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0.18'
69
55
  - !ruby/object:Gem::Dependency
70
- name: toml-rb
56
+ name: toml
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - ~>
@@ -108,6 +94,20 @@ dependencies:
108
94
  - - ~>
109
95
  - !ruby/object:Gem::Version
110
96
  version: '1.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: deep_merge
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
111
  description: CLI/library for generating Magento local.xml files
112
112
  email:
113
113
  - github@robert.net.nz
@@ -116,18 +116,15 @@ executables:
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
- - .gitignore
120
- - .ruby-version
121
- - Gemfile
122
- - LICENSE.txt
123
- - README.md
124
- - Rakefile
125
119
  - bin/magnetize
126
- - lib/magnetize.rb
120
+ - lib/magnetize/capistrano.rb
127
121
  - lib/magnetize/cli.rb
128
122
  - lib/magnetize/convert.rb
123
+ - lib/magnetize/tasks/magnetize.rake
129
124
  - lib/magnetize/version.rb
130
- - magnetize.gemspec
125
+ - lib/magnetize.rb
126
+ - LICENSE.txt
127
+ - README.md
131
128
  homepage: https://github.com/rjocoleman/magnetize/
132
129
  licenses:
133
130
  - MIT
@@ -153,3 +150,4 @@ signing_key:
153
150
  specification_version: 4
154
151
  summary: CLI/library for generating Magento local.xml files
155
152
  test_files: []
153
+ has_rdoc:
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
@@ -1 +0,0 @@
1
- ruby-2.0.0
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in magnetize.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require 'bundler/gem_tasks'
@@ -1,29 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'magnetize/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'magnetize'
8
- spec.version = Magnetize::VERSION
9
- spec.authors = ['Robert Coleman']
10
- spec.email = ['github@robert.net.nz']
11
- spec.summary = %q{CLI/library for generating Magento local.xml files}
12
- spec.description = %q{CLI/library for generating Magento local.xml files}
13
- spec.homepage = 'https://github.com/rjocoleman/magnetize/'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ['lib']
20
-
21
- spec.add_development_dependency 'bundler', '~> 1.5'
22
- spec.add_development_dependency 'rake'
23
- spec.add_development_dependency 'pry'
24
-
25
- spec.add_dependency 'thor', '~> 0.18'
26
- spec.add_dependency 'toml-rb', '~> 0.1'
27
- spec.add_dependency 'activesupport', '~> 4.0'
28
- spec.add_dependency 'gyoku', '~> 1.1'
29
- end