vite_ruby 1.2.10 → 1.2.15

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
  SHA256:
3
- metadata.gz: 434e2c4bccc4557134c3ef317342b499cb57a70e3f441778d6fd94d4c2debf8b
4
- data.tar.gz: 0456b70d36df278b46ded52dab70c3f098c9b31aa072b9d0cddd96652546e386
3
+ metadata.gz: 2cc7ebe04b31db44eb45cc8c61275d09035b9496e2bb9b818909d101088b304f
4
+ data.tar.gz: e5318e9fc71a89e68e707e0edf2a679b31163566f7a61478cf95b18698289b54
5
5
  SHA512:
6
- metadata.gz: 46d5df8aee43d5c3965bc58a479b76e332ca2f025159a06371b10163ec127d9cf37a5f696165ef06b62ca35f5d9d93cf5df14256b83dba902387b2dfa5931a17
7
- data.tar.gz: 40900cb76780ddc98239d39b40d1633ec0593b9e7040d9c5ca5a4d99aab91a54a17313ce681b4aae457b1c762809c74eaf87ab88a12b56c5c44525a930239053
6
+ metadata.gz: f187d6b794b600e55ca88d1068900afdddd14652bd2b65661ce0478ed01a296c81348cea83d7a8a049a500107be431d0c6d22c781f9be9062bfe085090295ea9
7
+ data.tar.gz: df568548b57a23881f41c54388c41c46cb3da6f174463adc26e82c5998f9f76e552c3dfbd5b361345469b65ef03dbd465ed49297fa1c09c0f0783c16db6a3f1a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ ## [1.2.15](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.14...vite_ruby@1.2.15) (2021-07-01)
2
+
3
+
4
+
5
+ ## [1.2.14](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.13...vite_ruby@1.2.14) (2021-07-01)
6
+
7
+
8
+ ### Features
9
+
10
+ * Add support for Jekyll installer ([7b942ec](https://github.com/ElMassimo/vite_ruby/commit/7b942ec745eb28092d684056b02df675ad6ececa))
11
+
12
+
13
+
14
+ ## [1.2.13](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.12...vite_ruby@1.2.13) (2021-06-30)
15
+
16
+
17
+ ### Features
18
+
19
+ * Improve the error message when npm packages are missing ([9159557](https://github.com/ElMassimo/vite_ruby/commit/9159557e5152547554cfe519fae8dbefe26686fb))
20
+
21
+
22
+
23
+ ## [1.2.12](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.11...vite_ruby@1.2.12) (2021-06-08)
24
+
25
+
26
+ ### Features
27
+
28
+ * Support Ruby 2.4 ([#87](https://github.com/ElMassimo/vite_ruby/issues/87)) ([8fc4d49](https://github.com/ElMassimo/vite_ruby/commit/8fc4d49c82817623df81d6f9f94654ea726eb050))
29
+
30
+
31
+
32
+ ## [1.2.11](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.10...vite_ruby@1.2.11) (2021-05-10)
33
+
34
+ ### Refactor
35
+
36
+ * Upgrade to dry-cli 0.7 while avoiding dependency on `dry-files` ([f5b87e](https://github.com/ElMassimo/vite_ruby/commit/f5b87e69790e48397d15e609b44118e399c9493d))
37
+
38
+
1
39
  ## [1.2.10](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.9...vite_ruby@1.2.10) (2021-05-09)
2
40
 
3
41
 
data/lib/vite_ruby.rb CHANGED
@@ -18,11 +18,19 @@ class ViteRuby
18
18
  ENV_PREFIX = 'VITE_RUBY'
19
19
 
20
20
  # Internal: Versions used by default when running `vite install`.
21
- DEFAULT_VITE_VERSION = '^2.2.3'
22
- DEFAULT_PLUGIN_VERSION = '^2.0.2'
23
-
24
- # Internal: Ruby Frameworks that have a companion library for Vite Ruby.
25
- SUPPORTED_FRAMEWORKS = %w[rails hanami roda padrino sinatra].freeze
21
+ DEFAULT_VITE_VERSION = '^2.3.8'
22
+ DEFAULT_PLUGIN_VERSION = '^2.0.4'
23
+
24
+ # Internal: Companion libraries for Vite Ruby, and their target framework.
25
+ COMPANION_LIBRARIES = {
26
+ 'vite_rails' => 'rails',
27
+ 'vite_hanami' => 'hanami',
28
+ 'vite_roda' => 'roda',
29
+ 'vite_padrino' => 'padrino',
30
+ 'vite_sinatra' => 'sinatra',
31
+ 'jekyll-vite' => 'jekyll',
32
+ 'vite_rails_legacy' => 'rails',
33
+ }
26
34
 
27
35
  class << self
28
36
  extend Forwardable
@@ -72,8 +80,8 @@ class ViteRuby
72
80
  # Internal: Detects if the application has installed a framework-specific
73
81
  # variant of Vite Ruby.
74
82
  def framework_libraries
75
- SUPPORTED_FRAMEWORKS.map { |framework|
76
- if library = Gem.loaded_specs["vite_#{ framework }"]
83
+ COMPANION_LIBRARIES.map { |name, framework|
84
+ if library = Gem.loaded_specs[name]
77
85
  [framework, library]
78
86
  end
79
87
  }.compact
@@ -1,25 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class ViteRuby::CLI::Build < Dry::CLI::Command
4
- CURRENT_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV']
3
+ class ViteRuby::CLI::Build < ViteRuby::CLI::Vite
5
4
  DEFAULT_ENV = CURRENT_ENV || 'production'
6
5
 
7
- def self.shared_options
8
- option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ['m'], desc: 'The build mode for Vite')
9
- option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
10
- option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
11
- option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
12
- option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
13
- end
14
-
15
6
  desc 'Bundle all entrypoints using Vite.'
16
7
  shared_options
17
8
  option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
18
9
 
19
- def call(mode:, args: [], clobber: false, **boolean_opts)
20
- ViteRuby.env['VITE_RUBY_MODE'] = mode
21
- ViteRuby.commands.clobber if clobber
22
- boolean_opts.map { |name, value| args << "--#{ name }" if value }
23
- block_given? ? yield(args) : ViteRuby.commands.build_from_task(*args)
10
+ def call(**options)
11
+ super { |args| ViteRuby.commands.build_from_task(*args) }
24
12
  end
25
13
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class ViteRuby::CLI::Dev < ViteRuby::CLI::Build
3
+ class ViteRuby::CLI::Dev < ViteRuby::CLI::Vite
4
4
  DEFAULT_ENV = CURRENT_ENV || 'development'
5
5
 
6
6
  desc 'Start the Vite development server.'
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'fileutils'
5
+
6
+ # NOTE: Extracted from dry-cli version 0.6.0, which later removed this file as
7
+ # it was refactored and extracted into the more complete (and complex) dry-files.
8
+ module ViteRuby::CLI::FileUtils
9
+ class << self
10
+ # Creates a new file or rewrites the contents of an existing file.
11
+ #
12
+ # @since 1.2.11
13
+ # @api private
14
+ def write(path, *content)
15
+ mkdir_p(path)
16
+ File.open(path, File::CREAT | File::WRONLY | File::TRUNC) do |file|
17
+ file.write(Array(content).flatten.join)
18
+ end
19
+ end
20
+
21
+ # Copies source into destination.
22
+ #
23
+ # @since 1.2.11
24
+ # @api private
25
+ def cp(source, destination)
26
+ mkdir_p(destination)
27
+ FileUtils.cp(source, destination)
28
+ end
29
+
30
+ # Adds a new line at the bottom of the file.
31
+ #
32
+ # @since 1.2.11
33
+ # @api private
34
+ def append(path, contents)
35
+ mkdir_p(path)
36
+
37
+ content = File.readlines(path)
38
+ content << "\n" unless content.last.end_with?("\n")
39
+ content << "#{ contents }\n"
40
+
41
+ write(path, content)
42
+ end
43
+
44
+ # Replace first line in `path` that contains `target` with `replacement`.
45
+ #
46
+ # @since 1.2.11
47
+ # @api private
48
+ def replace_first_line(path, target, replacement)
49
+ content = File.readlines(path)
50
+ content[index(content, path, target)] = "#{ replacement }\n"
51
+
52
+ write(path, content)
53
+ end
54
+
55
+ # Inject `contents` in `path` before `target`.
56
+ #
57
+ # @since 1.2.11
58
+ # @api private
59
+ def inject_line_before(path, target, contents)
60
+ _inject_line_before(path, target, contents, method(:index))
61
+ end
62
+
63
+ # Inject `contents` in `path` after `target`.
64
+ #
65
+ # @since 1.2.11
66
+ # @api private
67
+ def inject_line_after(path, target, contents)
68
+ _inject_line_after(path, target, contents, method(:index))
69
+ end
70
+
71
+ # Inject `contents` in `path` after last `target`.
72
+ #
73
+ # @since 1.2.11
74
+ # @api private
75
+ def inject_line_after_last(path, target, contents)
76
+ _inject_line_after(path, target, contents, method(:rindex))
77
+ end
78
+
79
+ private
80
+
81
+ # Creates all parent directories for the given file path.
82
+ #
83
+ # @since 1.2.11
84
+ # @api private
85
+ def mkdir_p(path)
86
+ Pathname.new(path).dirname.mkpath
87
+ end
88
+
89
+ # @since 1.2.11
90
+ # @api private
91
+ def index(content, path, target)
92
+ content.index { |line| line.include?(target) } ||
93
+ raise(ArgumentError, "Cannot find `#{ target }' inside `#{ path }'.")
94
+ end
95
+
96
+ # @since 1.2.11
97
+ # @api private
98
+ def rindex(content, path, target)
99
+ content.rindex { |line| line.include?(target) } ||
100
+ raise(ArgumentError, "Cannot find `#{ target }' inside `#{ path }'.")
101
+ end
102
+
103
+ # @since 1.2.11
104
+ # @api private
105
+ def _inject_line_before(path, target, contents, finder)
106
+ content = File.readlines(path)
107
+ i = finder.call(content, path, target)
108
+
109
+ content.insert(i, "#{ contents }\n")
110
+ write(path, content)
111
+ end
112
+
113
+ # @since 1.2.11
114
+ # @api private
115
+ def _inject_line_after(path, target, contents, finder)
116
+ content = File.readlines(path)
117
+ i = finder.call(content, path, target)
118
+
119
+ content.insert(i + 1, "#{ contents }\n")
120
+ write(path, content)
121
+ end
122
+ end
123
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/cli/utils/files'
4
3
  require 'stringio'
5
4
 
6
5
  class ViteRuby::CLI::Install < Dry::CLI::Command
@@ -29,6 +28,14 @@ class ViteRuby::CLI::Install < Dry::CLI::Command
29
28
 
30
29
  protected
31
30
 
31
+ # Internal: The JS packages that should be added to the app.
32
+ def js_dependencies
33
+ [
34
+ "vite@#{ ViteRuby::DEFAULT_VITE_VERSION }",
35
+ "vite-plugin-ruby@#{ ViteRuby::DEFAULT_PLUGIN_VERSION }",
36
+ ]
37
+ end
38
+
32
39
  # Internal: Setup for a plain Rack application.
33
40
  def setup_app_files
34
41
  copy_template 'config/vite.json', to: config.config_path
@@ -49,9 +56,9 @@ private
49
56
 
50
57
  def_delegators 'ViteRuby', :config
51
58
 
52
- %i[append cp inject_line_after inject_line_after_last inject_line_before write].each do |util|
59
+ %i[append cp inject_line_after inject_line_after_last inject_line_before replace_first_line write].each do |util|
53
60
  define_method(util) { |*args|
54
- Dry::CLI::Utils::Files.send(util, *args) rescue nil
61
+ ViteRuby::CLI::FileUtils.send(util, *args) rescue nil
55
62
  }
56
63
  end
57
64
 
@@ -74,7 +81,7 @@ private
74
81
  write(package_json, '{}') unless package_json.exist?
75
82
 
76
83
  Dir.chdir(root) do
77
- deps = "vite@#{ ViteRuby::DEFAULT_VITE_VERSION } vite-plugin-ruby@#{ ViteRuby::DEFAULT_PLUGIN_VERSION }"
84
+ deps = js_dependencies.join(' ')
78
85
  _, stderr, status = ViteRuby::IO.capture("npx --package @antfu/ni -- ni -D #{ deps }", stdin_data: "\n")
79
86
  _, stderr, = ViteRuby::IO.capture("yarn add -D #{ deps }") unless status.success?
80
87
  say("Could not install JS dependencies.\n", stderr) unless stderr.to_s.empty?
@@ -118,5 +125,5 @@ end
118
125
 
119
126
  # NOTE: This allows framework-specific variants to extend the installation.
120
127
  ViteRuby.framework_libraries.each do |_framework, library|
121
- require "#{ library.name }/installation"
128
+ require "#{ library.name.tr('-', '/') }/installation"
122
129
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ViteRuby::CLI::Vite < Dry::CLI::Command
4
+ CURRENT_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV']
5
+
6
+ def self.shared_options
7
+ option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ['m'], desc: 'The build mode for Vite')
8
+ option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
9
+ option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
10
+ option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
11
+ option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
12
+ end
13
+
14
+ def call(mode:, args: [], clobber: false, **boolean_opts)
15
+ ViteRuby.env['VITE_RUBY_MODE'] = mode
16
+ ViteRuby.commands.clobber if clobber
17
+ boolean_opts.map { |name, value| args << "--#{ name }" if value }
18
+ yield(args)
19
+ end
20
+ end
@@ -4,7 +4,7 @@
4
4
  class ViteRuby::MissingExecutableError < ViteRuby::Error
5
5
  def initialize(error = nil)
6
6
  super <<~MSG
7
- ❌ The vite binary is not available. Have you installed Vite?
7
+ ❌ The vite binary is not available. Have you installed the npm packages?
8
8
 
9
9
  :troubleshooting:
10
10
  #{ error }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '1.2.10'
4
+ VERSION = '1.2.15'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vite_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.10
4
+ version: 1.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-09 00:00:00.000000000 Z
11
+ date: 2021-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
19
+ version: 0.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.0
26
+ version: 0.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack-proxy
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -142,48 +142,6 @@ dependencies:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
144
  version: '13.0'
145
- - !ruby/object:Gem::Dependency
146
- name: rubocop
147
- requirement: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - "~>"
150
- - !ruby/object:Gem::Version
151
- version: '1.9'
152
- type: :development
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - "~>"
157
- - !ruby/object:Gem::Version
158
- version: '1.9'
159
- - !ruby/object:Gem::Dependency
160
- name: rubocop-minitest
161
- requirement: !ruby/object:Gem::Requirement
162
- requirements:
163
- - - "~>"
164
- - !ruby/object:Gem::Version
165
- version: '0.10'
166
- type: :development
167
- prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- requirements:
170
- - - "~>"
171
- - !ruby/object:Gem::Version
172
- version: '0.10'
173
- - !ruby/object:Gem::Dependency
174
- name: rubocop-performance
175
- requirement: !ruby/object:Gem::Requirement
176
- requirements:
177
- - - "~>"
178
- - !ruby/object:Gem::Version
179
- version: '1.9'
180
- type: :development
181
- prerelease: false
182
- version_requirements: !ruby/object:Gem::Requirement
183
- requirements:
184
- - - "~>"
185
- - !ruby/object:Gem::Version
186
- version: '1.9'
187
145
  - !ruby/object:Gem::Dependency
188
146
  name: simplecov
189
147
  requirement: !ruby/object:Gem::Requirement
@@ -219,8 +177,10 @@ files:
219
177
  - lib/vite_ruby/cli/build.rb
220
178
  - lib/vite_ruby/cli/clobber.rb
221
179
  - lib/vite_ruby/cli/dev.rb
180
+ - lib/vite_ruby/cli/file_utils.rb
222
181
  - lib/vite_ruby/cli/install.rb
223
182
  - lib/vite_ruby/cli/version.rb
183
+ - lib/vite_ruby/cli/vite.rb
224
184
  - lib/vite_ruby/commands.rb
225
185
  - lib/vite_ruby/config.rb
226
186
  - lib/vite_ruby/dev_server_proxy.rb
@@ -238,8 +198,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
238
198
  licenses:
239
199
  - MIT
240
200
  metadata:
241
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.2.10/vite_ruby
242
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.2.10/vite_ruby/CHANGELOG.md
201
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.2.15/vite_ruby
202
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.2.15/vite_ruby/CHANGELOG.md
243
203
  post_install_message:
244
204
  rdoc_options: []
245
205
  require_paths:
@@ -248,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
208
  requirements:
249
209
  - - ">="
250
210
  - !ruby/object:Gem::Version
251
- version: '2.5'
211
+ version: '2.4'
252
212
  required_rubygems_version: !ruby/object:Gem::Requirement
253
213
  requirements:
254
214
  - - ">="