playwright-cli 0.1.16 → 0.1.17

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
  SHA256:
3
- metadata.gz: 368e6d76fcbddcc447c51c1aa01f2b026db700402fcc1bfa548a18968e1ffa35
4
- data.tar.gz: 49222ff68b9e74a729f4e2992407b2c9eba996345b1e9649a064c4d456985c39
3
+ metadata.gz: bafee08c8b0e24f2b0882a4859f4914ce06c387b2571b32df27046102e9f1e67
4
+ data.tar.gz: 7eb962bd323173ebd00bc1fa40cbac7c5048efae7a8888155a6c0735e77583f8
5
5
  SHA512:
6
- metadata.gz: dbb18e3e1632c70d251650d6c5c0c7f159b457948537824fef5af96908b0f64ab77056c361fb54408c81e98203db5bdda9aaa4c850b519b06849019d50b5e5cf
7
- data.tar.gz: 4dfaa28467dfdd1f5e0a82ec6494c899e79ae22a50d58f33dcbb0e803aa67a1e1ff36694189c3e70ba3736295866f45abc3704372c15d0f2adc4abccaa25138e
6
+ metadata.gz: b4fc801b23ae330ae6c5d91770d19003c11fa59fec1bec20f6f32866874493dc840df87daebeedc1fd9f00d403447149ad02a9eeccd45de8a66dcffc8b005647
7
+ data.tar.gz: c023870ec50ea8a86a520f2ccf1fdfffbca1ff8c320e2d89b9e8b49045a6cbc2651f3a995c8e9765d5a3f965ce46ad205f7d2f228110bfd19ac5e9fb28d38a4e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- playwright-cli (0.1.16)
4
+ playwright-cli (0.1.17)
5
5
  colorize (~> 0.1)
6
6
  git (~> 1.3)
7
7
  hanami-cli (~> 0.1)
@@ -0,0 +1,28 @@
1
+ function install_bundler {
2
+ echo "\033[0;32mYou don't have bundler???\nInstalling now...\033[0m" && gem install bundler
3
+ }
4
+
5
+ # Install bundler if they don't have it
6
+ bundle -v &> /dev/null || install_bundler
7
+
8
+ # Get ruby version
9
+ PLAYWRIGHT_<%= val[:script_name].to_snake_case.upcase %>_RUBY_VERSION=$(ruby -ryaml -e " puts (YAML.load_file(\"#{ENV['HOME']}/.playwright/plays/<%= val[:script_name] %>/config.yml\")[:ruby_version] || '').gsub('.', '')")
10
+
11
+ # command to run proper ruby version
12
+ PLAYWRIGHT_RUBY_COMMAND="$HOME/.playwright/rubies/ruby$PLAYWRIGHT_<%= val[:script_name].to_snake_case.upcase %>_RUBY_VERSION"
13
+
14
+ # Remember current gem env vars
15
+ OLD_GEM_PATH=$GEM_PATH
16
+ OLD_GEM_HOME=$GEM_HOME
17
+
18
+ # Set gem home so that any new gems are installed to local folder
19
+ GEM_HOME="$HOME/.playwright/plays/<%= val[:script_name] %>/gems"
20
+ # Set gem path to use gems from local folder, as well as normal paths
21
+ GEM_PATH="$GEM_HOME:$GEM_PATH"
22
+
23
+ # Run play
24
+ $PLAYWRIGHT_RUBY_COMMAND -W0 $HOME/.playwright/plays/<%= val[:script_name] %>/<%= val[:script_name] %> "$@"
25
+
26
+ # Set gem env vars back to previous values
27
+ GEM_HOME=$OLD_GEM_HOME
28
+ GEM_PATH=$OLD_GEM_PATH
data/lib/ext/string.rb ADDED
@@ -0,0 +1,10 @@
1
+ class String
2
+ # From ActiveSupport
3
+ def to_snake_case
4
+ gsub(/::/, '/').
5
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
6
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
7
+ tr("-", "_").
8
+ downcase
9
+ end
10
+ end
@@ -3,8 +3,11 @@ require 'playwright/cli/utils/file_manager'
3
3
  module Playwright
4
4
  class CLI < Hanami::CLI
5
5
  class Template
6
+ include Utils::Display
6
7
 
7
- attr_reader :script_name, :out_file, :type
8
+ InvalidTemplate = Class.new(StandardError)
9
+
10
+ attr_reader :script_name, :out_file, :type, :values
8
11
 
9
12
  SIMPLE_TYPE = :simple
10
13
  SIMPLE_TEMPLATE = 'simple_script_template.erb'
@@ -14,19 +17,27 @@ module Playwright
14
17
  SUBCOMMAND_TEMPLATE = 'version_subcommand_template.erb'
15
18
  README_TYPE = :readme
16
19
  README_TEMPLATE = 'script_readme_template.erb'
20
+ SHELL_SCRIPT_TYPE = :shell_script,
21
+ SHELL_SCRIPT_TEMPLATE = 'launch_script_template.erb'
17
22
 
18
23
  TEMPLATE_MAP = {
19
24
  SIMPLE_TYPE => SIMPLE_TEMPLATE,
20
25
  EXPANDED_TYPE => EXPANDED_TEMPLATE,
21
26
  SUBCOMMAND_TYPE => SUBCOMMAND_TEMPLATE,
22
- README_TYPE => README_TEMPLATE
27
+ README_TYPE => README_TEMPLATE,
28
+ SHELL_SCRIPT_TYPE => SHELL_SCRIPT_TEMPLATE
23
29
  }
24
30
 
25
- def initialize(name:, out_file:, type: SIMPLE_TYPE, klass_name: nil)
31
+ def render(*args)
32
+ new(*args).render
33
+ end
34
+
35
+ def initialize(name:, out_file:, type: SIMPLE_TYPE, klass_name: nil, values: {})
26
36
  @script_name = name
27
37
  @out_file = out_file
28
38
  @template_file = Playwright::CLI::TEMPLATES_PATH.join TEMPLATE_MAP[type]
29
39
  @klass_name = klass_name
40
+ @values = values
30
41
  end
31
42
 
32
43
  def klass_name
@@ -37,6 +48,11 @@ module Playwright
37
48
  contents = File.read(@template_file)
38
49
  text = ERB.new(contents).result(binding)
39
50
  File.write(out_file, text)
51
+ display.print "Rendered File Contents: #{out_file}"
52
+ end
53
+
54
+ def val
55
+ values
40
56
  end
41
57
 
42
58
  end
@@ -19,8 +19,7 @@ module Playwright
19
19
 
20
20
  def boolean_question user_question
21
21
  response = question "#{user_question} [yn]"
22
- sanitized_response = response.chomp.strip.downcase.to_sym if response && response.length > 0
23
- boolean_response_map[response]
22
+ map_boolean_response response
24
23
  end
25
24
 
26
25
  def url_question user_question
@@ -39,8 +38,12 @@ module Playwright
39
38
 
40
39
  private
41
40
 
42
- def boolean_response_map
43
- { TRUE_RESPONSE => true, FALSE_RESPONSE => false }
41
+ def map_boolean_response value
42
+ { TRUE_RESPONSE => true, FALSE_RESPONSE => false }[sanitize_boolean_response value]
43
+ end
44
+
45
+ def sanitize_boolean_response value
46
+ value&.strip&.downcase&.to_sym
44
47
  end
45
48
 
46
49
  end
@@ -33,7 +33,7 @@ module Playwright
33
33
  def print msg, method: :puts, color: DEFAULT_COLOR, indent: false
34
34
  msg = stringify msg, indent: indent
35
35
  validate_print_method!(method)
36
- msg = msg.send(color) if defined?(Colorize)
36
+ msg = msg.send(color) if defined?(Colorize) && msg
37
37
  send(method, msg)
38
38
  end
39
39
 
@@ -51,6 +51,8 @@ module Playwright
51
51
  when Array
52
52
  msg = msg.map { |ln| indentify(ln, count: indent) } if indent
53
53
  msg.join("\n")
54
+ else
55
+ msg.to_s
54
56
  end
55
57
  end
56
58
 
@@ -21,6 +21,9 @@ module Playwright
21
21
  attr_reader :script_name, :type
22
22
 
23
23
  GITIGNORE = []
24
+ CONFIG_YML = {
25
+ ruby_version: RUBY_VERSION
26
+ }
24
27
 
25
28
  def initialize script_name: nil, type: nil
26
29
  @script_name = script_name
@@ -31,9 +34,11 @@ module Playwright
31
34
  @script_name = script_name
32
35
  @type = type
33
36
  create_script_files
37
+ symlink_ruby_version
34
38
  set_permissions
35
- write_template
36
- create_symlink
39
+ write_templates
40
+ create_symlinks
41
+ create_config_yml
37
42
  create_gitignore
38
43
  create_readme
39
44
  git_init
@@ -51,7 +56,11 @@ module Playwright
51
56
  end
52
57
 
53
58
  def script_name_rb
54
- "#{script_name}.rb"
59
+ "#{script_name.to_snake_case}.rb"
60
+ end
61
+
62
+ def script_name_sh
63
+ "#{script_name}.sh"
55
64
  end
56
65
 
57
66
  def list_scripts
@@ -64,11 +73,11 @@ module Playwright
64
73
  private
65
74
 
66
75
  def self.playwright_parent_dir
67
- Pathname.new(Playwright::CLI.configuration.home_dir)
76
+ Pathname.new Playwright::CLI.configuration.home_dir
68
77
  end
69
78
 
70
79
  def self.executable_path_dir
71
- Pathname.new(Playwright::CLI.configuration.executable_path_dir)
80
+ Pathname.new Playwright::CLI.configuration.executable_path_dir
72
81
  end
73
82
 
74
83
  def self.dot_playwright_dir
@@ -79,17 +88,22 @@ module Playwright
79
88
  dot_playwright_dir.join 'plays'
80
89
  end
81
90
 
82
- def self.config_file
91
+ def self.root_config_file
83
92
  dot_playwright_dir.join 'config.rb'
84
93
  end
85
94
 
95
+ def self.rubies_dir
96
+ dot_playwright_dir.join 'rubies'
97
+ end
98
+
86
99
  def self.create_file_structure
87
- FileUtils.mkdir_p(plays_dir)
88
- FileUtils.touch(config_file)
100
+ FileUtils.mkdir_p plays_dir
101
+ FileUtils.touch root_config_file
102
+ FileUtils.mkdir_p rubies_dir
89
103
  end
90
104
 
91
105
  def self.path
92
- ENV['PATH'].split(':')
106
+ ENV['PATH'].split ':'
93
107
  end
94
108
 
95
109
  def self.all_commands_in_path
@@ -102,7 +116,7 @@ module Playwright
102
116
  # ==============================================================================
103
117
 
104
118
  def template
105
- @template ||= Template.new(name: script_name_rb, out_file: executable_file, type: type)
119
+ @template ||= Template.new name: script_name, out_file: root_ruby_file, type: type
106
120
  end
107
121
 
108
122
  # ==============================================================================
@@ -113,16 +127,40 @@ module Playwright
113
127
  self.class.plays_dir.join script_name
114
128
  end
115
129
 
130
+ def bin_dir
131
+ root_dir.join 'bin'
132
+ end
133
+
134
+ def gems_dir
135
+ root_dir.join 'gems'
136
+ end
137
+
116
138
  def root_dir_exists?
117
139
  File.exists? root_dir
118
140
  end
119
141
 
120
- def executable_file
142
+ def root_ruby_file
121
143
  root_dir.join script_name_rb
122
144
  end
123
145
 
124
- def executable_file_exists?
125
- File.exists? executable_file
146
+ def root_ruby_file_exists?
147
+ File.exists? root_ruby_file
148
+ end
149
+
150
+ def launch_script_file
151
+ bin_dir.join script_name_sh
152
+ end
153
+
154
+ def launch_script_file_exists?
155
+ File.exists? launch_script_file
156
+ end
157
+
158
+ def config_yml_file
159
+ root_dir.join 'config.yml'
160
+ end
161
+
162
+ def config_yml_file_exists?
163
+ File.exists? config_yml_file
126
164
  end
127
165
 
128
166
  def symlink_file
@@ -133,6 +171,22 @@ module Playwright
133
171
  File.symlink? symlink_file
134
172
  end
135
173
 
174
+ def local_symlink_file
175
+ root_dir.join script_name
176
+ end
177
+
178
+ def local_symlink_file_exists?
179
+ File.symlink? symlink_file
180
+ end
181
+
182
+ def ruby_version_symlink_file
183
+ self.class.rubies_dir.join "ruby#{ RUBY_VERSION.gsub '.', '' }"
184
+ end
185
+
186
+ def ruby_version_symlink_file_exists?
187
+ File.symlink? ruby_version_symlink_file
188
+ end
189
+
136
190
  def script_lib_dir
137
191
  root_dir.join 'lib'
138
192
  end
@@ -145,13 +199,31 @@ module Playwright
145
199
  # CREATE METHODS
146
200
  # ==============================================================================
147
201
 
202
+ def symlink_ruby_version
203
+ current_ruby = `which ruby`.chomp
204
+ FileUtils.symlink current_ruby, ruby_version_symlink_file unless ruby_version_symlink_file_exists?
205
+ display.print "New Symlink Created: #{ruby_version_symlink_file} from #{current_ruby}"
206
+ end
207
+
148
208
  def create_script_files
149
209
  validate_before_create_script_files!
150
210
  self.class.create_file_structure
211
+
151
212
  FileUtils.mkdir_p root_dir
152
213
  display.print "New Directory Created: #{root_dir}"
153
- FileUtils.touch executable_file
154
- display.print "New File Created: #{executable_file}"
214
+
215
+ FileUtils.mkdir_p gems_dir
216
+ display.print "New Directory Created: #{gems_dir}"
217
+
218
+ FileUtils.mkdir_p bin_dir
219
+ display.print "New Directory Created: #{bin_dir}"
220
+
221
+ FileUtils.touch root_ruby_file
222
+ display.print "New File Created: #{root_ruby_file}"
223
+
224
+ FileUtils.touch launch_script_file
225
+ display.print "New File Created: #{launch_script_file}"
226
+
155
227
  create_expanded_files if type == :expanded
156
228
  end
157
229
 
@@ -161,11 +233,13 @@ module Playwright
161
233
  end
162
234
 
163
235
  def set_permissions
164
- FileUtils.chmod "u+x", executable_file
165
- display.print "Executable Permissions Set: #{executable_file}"
236
+ FileUtils.chmod "u+x", root_ruby_file
237
+ display.print "Executable Permissions Set: #{root_ruby_file}"
238
+ FileUtils.chmod "u+x", launch_script_file
239
+ display.print "Executable Permissions Set: #{launch_script_file}"
166
240
  end
167
241
 
168
- def write_template
242
+ def write_templates
169
243
  template.render
170
244
  if type == Template::EXPANDED_TYPE
171
245
  new_template = Template.new(
@@ -176,19 +250,31 @@ module Playwright
176
250
  )
177
251
  new_template.render
178
252
  end
253
+ launch_script_file_template = Template.new(
254
+ name: script_name_sh,
255
+ out_file: launch_script_file,
256
+ type: Template::SHELL_SCRIPT_TYPE,
257
+ values: {
258
+ script_name: script_name
259
+ }
260
+ )
261
+ launch_script_file_template.render
179
262
  end
180
263
 
181
- def create_symlink
182
- FileUtils.symlink(executable_file, symlink_file)
183
- display.print "New Symlink Created: #{symlink_file} from #{executable_file}"
264
+ def create_symlinks
265
+ FileUtils.symlink launch_script_file, symlink_file
266
+ display.print "New Symlink Created: #{symlink_file} from #{launch_script_file}"
267
+
268
+ FileUtils.symlink root_ruby_file, local_symlink_file
269
+ display.print "New Symlink Created: #{local_symlink_file} from #{root_ruby_file}"
184
270
  end
185
271
 
186
272
  def validate_before_create_script_files!
187
- if self.class.all_commands_in_path.include?(script_name)
273
+ if self.class.all_commands_in_path.include? script_name
188
274
  display.error "There is already a script in your $PATH with that name!"
189
- elsif executable_file_exists?
275
+ elsif root_ruby_file_exists?
190
276
  if ask.boolean_question "This playwright script already exists! Overwrite it?"
191
- delete_playwright_script
277
+ delete_script_files
192
278
  else
193
279
  display.abort "Aborting Operation."
194
280
  end
@@ -198,7 +284,7 @@ module Playwright
198
284
  def git_init
199
285
  git = Git.init root_dir.to_s
200
286
  git.add all: true
201
- git.commit('initial commit')
287
+ git.commit 'initial commit'
202
288
  end
203
289
 
204
290
  def create_gitignore
@@ -207,6 +293,12 @@ module Playwright
207
293
  end
208
294
  end
209
295
 
296
+ def create_config_yml
297
+ File.open config_yml_file, "w+" do |file|
298
+ file.write CONFIG_YML.to_yaml
299
+ end
300
+ end
301
+
210
302
  def create_readme
211
303
  FileUtils.touch root_dir.join("README.md")
212
304
  new_template = Template.new(
@@ -223,8 +315,8 @@ module Playwright
223
315
 
224
316
  def delete_script_files
225
317
  validate_before_delete_script_files!
226
- FileUtils.rm_rf root_dir
227
- FileUtils.rm symlink_file
318
+ FileUtils.rm_rf root_dir if Dir.exists? root_dir
319
+ FileUtils.rm symlink_file if File.symlink? symlink_file
228
320
  display.print "Playwright script '#{script_name}' destroyed!"
229
321
  end
230
322
 
@@ -2,6 +2,6 @@ require 'hanami/cli'
2
2
 
3
3
  module Playwright
4
4
  class CLI < Hanami::CLI
5
- VERSION = "0.1.16"
5
+ VERSION = "0.1.17"
6
6
  end
7
7
  end
@@ -2,11 +2,14 @@ require 'hanami/cli'
2
2
  require 'colorize'
3
3
  require 'git'
4
4
 
5
- require 'fileutils'
6
5
  require 'erb'
6
+ require 'fileutils'
7
7
  require 'os'
8
- require 'uri'
9
8
  require 'pathname'
9
+ require 'uri'
10
+ require 'yaml'
11
+
12
+ require_relative '../ext/string'
10
13
 
11
14
  require_relative '../ext/hanami.rb'
12
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playwright-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Gregory
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-04 00:00:00.000000000 Z
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,12 +170,14 @@ files:
170
170
  - bin/setup
171
171
  - exe/playwright
172
172
  - lib/assets/templates/expanded_script_template.erb
173
+ - lib/assets/templates/launch_script_template.erb
173
174
  - lib/assets/templates/script_readme_template.erb
174
175
  - lib/assets/templates/simple_script_template.erb
175
176
  - lib/assets/templates/version_subcommand_template.erb
176
177
  - lib/ext/hanami.rb
177
178
  - lib/ext/hanami/option.rb
178
179
  - lib/ext/hanami/parser.rb
180
+ - lib/ext/string.rb
179
181
  - lib/playwright/cli.rb
180
182
  - lib/playwright/cli/command.rb
181
183
  - lib/playwright/cli/commands.rb