vite_ruby 2.0.0.beta.3 → 3.0.0.beta.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
  SHA256:
3
- metadata.gz: db7a467c6b97a89c6704a7f94ff6c20b4b1bb39bd49fbb5d5f0fd67ea754fbdb
4
- data.tar.gz: edffb992d9fda5dc7993d620037ba2866b3f1ec8bf1561b4ed4e0a420646c6fb
3
+ metadata.gz: 0dd16ba0c6a663008ac6fdf8679db418557dd9a6930dd3e5ef3df70a0e6ac326
4
+ data.tar.gz: 960ce8db783f8305d8fa5ff41330226ac44e0cfc0feb702a30400c60d4910d08
5
5
  SHA512:
6
- metadata.gz: f2d8967f4ec47d49e4e829dfdf8aa8a087e576852fbdbe1343e1117f5397348ac40220bed5071715619a4395ea8bfc5521df58000d187e68eee69e021ddb23c5
7
- data.tar.gz: f08b6882162c082006f4de9a3e105de5ffe9a2c55a53ffb9ec8c1659963c135c4657d7acf964df6a1e2bf521af6a2bfabbfbbde1e53d579f0620b418813eae9f
6
+ metadata.gz: 7f9e9b3727563b7a8c2c81fababf599a0c4158ee3d2e06c2fd16a4643cea8a461f178425d0f044ba467000e468642e3932873f18ac3866cd09f02a7c201c9392
7
+ data.tar.gz: abcd610257b8edaa0b1d8849d35750ad399b250178bcf1f501935e373b85b02465b247ca43918186f20ed37bf8e33bef29852cfa1af9a716c18b089db8de497e
data/lib/vite_ruby.rb CHANGED
@@ -13,21 +13,17 @@ loader.inflector.inflect('cli' => 'CLI')
13
13
  loader.inflector.inflect('io' => 'IO')
14
14
  loader.setup
15
15
 
16
+ require 'vite_ruby/version'
17
+
16
18
  class ViteRuby
17
19
  # Internal: Prefix used for environment variables that modify the configuration.
18
20
  ENV_PREFIX = 'VITE_RUBY'
19
21
 
20
- # Internal: Versions used by default when running `vite install`.
21
- DEFAULT_VITE_VERSION = '^2.5.0-beta.2'
22
- DEFAULT_PLUGIN_VERSION = '^3.0.0-beta.3'
23
-
24
22
  # Internal: Companion libraries for Vite Ruby, and their target framework.
25
23
  COMPANION_LIBRARIES = {
26
24
  'vite_rails' => 'rails',
27
25
  'vite_hanami' => 'hanami',
28
- 'vite_roda' => 'roda',
29
26
  'vite_padrino' => 'padrino',
30
- 'vite_sinatra' => 'sinatra',
31
27
  'jekyll-vite' => 'jekyll',
32
28
  'vite_rails_legacy' => 'rails',
33
29
  }
@@ -3,16 +3,22 @@
3
3
  require 'time'
4
4
 
5
5
  # Internal: Value object with information about the last build.
6
- ViteRuby::Build = Struct.new(:success, :timestamp, :digest, :current_digest) do
6
+ ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current_digest) do
7
7
  # Internal: Combines information from a previous build with the current digest.
8
8
  def self.from_previous(attrs, current_digest)
9
- new(attrs['success'], attrs['timestamp'] || 'never', attrs['digest'] || 'none', current_digest)
9
+ new(
10
+ attrs['success'],
11
+ attrs['timestamp'] || 'never',
12
+ attrs['vite_ruby'] || 'unknown',
13
+ attrs['digest'] || 'none',
14
+ current_digest,
15
+ )
10
16
  end
11
17
 
12
18
  # Internal: A build is considered stale when watched files have changed since
13
19
  # the last build, or when a certain time has ellapsed in case of failure.
14
20
  def stale?
15
- digest != current_digest || retry_failed?
21
+ digest != current_digest || retry_failed? || vite_ruby != ViteRuby::VERSION
16
22
  end
17
23
 
18
24
  # Internal: A build is considered fresh if watched files have not changed, or
@@ -31,7 +37,12 @@ ViteRuby::Build = Struct.new(:success, :timestamp, :digest, :current_digest) do
31
37
 
32
38
  # Internal: Returns a new build with the specified result.
33
39
  def with_result(success)
34
- self.class.new(success, Time.now.strftime('%F %T'), current_digest)
40
+ self.class.new(
41
+ success,
42
+ Time.now.strftime('%F %T'),
43
+ ViteRuby::VERSION,
44
+ current_digest,
45
+ )
35
46
  end
36
47
 
37
48
  # Internal: Returns a JSON string with the metadata of the build.
@@ -96,13 +96,15 @@ private
96
96
  [
97
97
  *config.watch_additional_paths,
98
98
  "#{ config.source_code_dir }/**/*",
99
- 'yarn.lock',
100
99
  'package-lock.json',
101
- 'pnpm-lock.yaml',
102
100
  'package.json',
103
- 'vite.config.ts',
101
+ 'pnpm-lock.yaml',
102
+ 'postcss.config.js',
103
+ 'tailwind.config.js',
104
104
  'vite.config.js',
105
+ 'vite.config.ts',
105
106
  'windi.config.ts',
107
+ 'yarn.lock',
106
108
  config.config_path,
107
109
  ].freeze
108
110
  end
data/lib/vite_ruby/cli.rb CHANGED
@@ -10,6 +10,8 @@ class ViteRuby::CLI
10
10
  register 'build', Build, aliases: ['b']
11
11
  register 'clobber', Clobber, aliases: %w[clean clear]
12
12
  register 'dev', Dev, aliases: %w[d serve]
13
- register 'install', Install, aliases: %w[setup init]
13
+ register 'install', Install
14
14
  register 'version', Version, aliases: ['v', '-v', '--version', 'info']
15
+ register 'upgrade', Upgrade, aliases: ['update']
16
+ register 'upgrade_packages', UpgradePackages, aliases: ['update_packages']
15
17
  end
@@ -24,7 +24,7 @@ module ViteRuby::CLI::FileUtils
24
24
  # @api private
25
25
  def cp(source, destination)
26
26
  mkdir_p(destination)
27
- FileUtils.cp(source, destination)
27
+ FileUtils.cp(source, destination) unless File.exist?(destination)
28
28
  end
29
29
 
30
30
  # Adds a new line at the bottom of the file.
@@ -32,10 +32,10 @@ module ViteRuby::CLI::FileUtils
32
32
  # @since 1.2.11
33
33
  # @api private
34
34
  def append(path, contents)
35
- mkdir_p(path)
35
+ content = read_lines(path)
36
+ return if content.join.include?(contents)
36
37
 
37
- content = File.readlines(path)
38
- content << "\n" unless content.last.end_with?("\n")
38
+ content << "\n" unless content.last&.end_with?("\n")
39
39
  content << "#{ contents }\n"
40
40
 
41
41
  write(path, content)
@@ -46,7 +46,7 @@ module ViteRuby::CLI::FileUtils
46
46
  # @since 1.2.11
47
47
  # @api private
48
48
  def replace_first_line(path, target, replacement)
49
- content = File.readlines(path)
49
+ content = read_lines(path)
50
50
  content[index(content, path, target)] = "#{ replacement }\n"
51
51
 
52
52
  write(path, content)
@@ -86,6 +86,11 @@ module ViteRuby::CLI::FileUtils
86
86
  Pathname.new(path).dirname.mkpath
87
87
  end
88
88
 
89
+ # Returns an array with lines in the specified file, empty if it doesn't exist.
90
+ def read_lines(path)
91
+ File.exist?(path) ? File.readlines(path) : []
92
+ end
93
+
89
94
  # @since 1.2.11
90
95
  # @api private
91
96
  def index(content, path, target)
@@ -103,7 +108,9 @@ module ViteRuby::CLI::FileUtils
103
108
  # @since 1.2.11
104
109
  # @api private
105
110
  def _inject_line_before(path, target, contents, finder)
106
- content = File.readlines(path)
111
+ content = read_lines(path)
112
+ return if content.join.include?(contents)
113
+
107
114
  i = finder.call(content, path, target)
108
115
 
109
116
  content.insert(i, "#{ contents }\n")
@@ -113,7 +120,9 @@ module ViteRuby::CLI::FileUtils
113
120
  # @since 1.2.11
114
121
  # @api private
115
122
  def _inject_line_after(path, target, contents, finder)
116
- content = File.readlines(path)
123
+ content = read_lines(path)
124
+ return if content.join.include?(contents)
125
+
117
126
  i = finder.call(content, path, target)
118
127
 
119
128
  content.insert(i + 1, "#{ contents }\n")
@@ -71,6 +71,7 @@ private
71
71
  # Internal: Creates the Vite and vite-plugin-ruby configuration files.
72
72
  def create_configuration_files
73
73
  copy_template 'config/vite.config.ts', to: root.join('vite.config.ts')
74
+ append root.join('Procfile.dev'), 'vite: bin/vite dev'
74
75
  setup_app_files
75
76
  ViteRuby.reload_with(config_path: config.config_path)
76
77
  end
@@ -79,13 +80,8 @@ private
79
80
  def install_js_dependencies
80
81
  package_json = root.join('package.json')
81
82
  write(package_json, '{}') unless package_json.exist?
82
-
83
- Dir.chdir(root) do
84
- deps = js_dependencies.join(' ')
85
- _, stderr, status = ViteRuby::IO.capture("npx --package @antfu/ni -- ni -D #{ deps }", stdin_data: "\n")
86
- _, stderr, = ViteRuby::IO.capture("yarn add -D #{ deps }") unless status.success?
87
- say("Could not install JS dependencies.\n", stderr) unless stderr.to_s.empty?
88
- end
83
+ deps = js_dependencies.join(' ')
84
+ run_with_capture("#{ npm_install } -D #{ deps }", stdin_data: "\n")
89
85
  end
90
86
 
91
87
  # Internal: Adds compilation output dirs to git ignore.
@@ -113,6 +109,21 @@ private
113
109
  $stdout.puts(*args)
114
110
  end
115
111
 
112
+ def run_with_capture(*args, **options)
113
+ Dir.chdir(root) do
114
+ _, stderr, status = ViteRuby::IO.capture(*args, **options)
115
+ say(stderr) unless status.success? || stderr.to_s.empty?
116
+ end
117
+ end
118
+
119
+ # Internal: Support all popular package managers.
120
+ def npm_install
121
+ return 'yarn add' if root.join('yarn.lock').exist?
122
+ return 'pnpm install' if root.join('pnpm-lock.yaml').exist?
123
+
124
+ 'npm install'
125
+ end
126
+
116
127
  # Internal: Avoid printing warning about missing vite.json, we will create one.
117
128
  def silent_warnings
118
129
  old_stderr = $stderr
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ViteRuby::CLI::Upgrade < ViteRuby::CLI::Install
4
+ desc 'Updates Vite Ruby related gems and npm packages.'
5
+
6
+ def call(**)
7
+ upgrade_ruby_gems
8
+ upgrade_npm_packages
9
+ end
10
+
11
+ protected
12
+
13
+ def upgrade_ruby_gems
14
+ say 'Updating gems'
15
+
16
+ libraries = ViteRuby.framework_libraries.map { |_f, library| library.name }
17
+
18
+ run_with_capture("bundle update #{ libraries.join(' ') }")
19
+ end
20
+
21
+ # NOTE: Spawn a new process so that it uses the updated vite_ruby.
22
+ def upgrade_npm_packages
23
+ Kernel.exec('bundle exec vite upgrade_packages')
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ViteRuby::CLI::UpgradePackages < ViteRuby::CLI::Install
4
+ desc 'Upgrades the npm packages to the recommended versions.'
5
+
6
+ def call(**)
7
+ say 'Upgrading npm packages'
8
+ deps = js_dependencies.join(' ')
9
+ run_with_capture("#{ npm_install } -D #{ deps }")
10
+ end
11
+ end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '2.0.0.beta.3'
4
+ VERSION = '3.0.0.beta.1'
5
+
6
+ # Internal: Versions used by default when running `vite install`.
7
+ DEFAULT_VITE_VERSION = '^2.5.0-beta.2'
8
+ DEFAULT_PLUGIN_VERSION = '^3.0.0-beta.2'
5
9
  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: 2.0.0.beta.3
4
+ version: 3.0.0.beta.1
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-08-12 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -179,6 +179,8 @@ files:
179
179
  - lib/vite_ruby/cli/dev.rb
180
180
  - lib/vite_ruby/cli/file_utils.rb
181
181
  - lib/vite_ruby/cli/install.rb
182
+ - lib/vite_ruby/cli/upgrade.rb
183
+ - lib/vite_ruby/cli/upgrade_packages.rb
182
184
  - lib/vite_ruby/cli/version.rb
183
185
  - lib/vite_ruby/cli/vite.rb
184
186
  - lib/vite_ruby/commands.rb
@@ -198,9 +200,10 @@ homepage: https://github.com/ElMassimo/vite_ruby
198
200
  licenses:
199
201
  - MIT
200
202
  metadata:
201
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@2.0.0.beta.3/vite_ruby
202
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@2.0.0.beta.3/vite_ruby/CHANGELOG.md
203
- post_install_message:
203
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.0.0.beta.1/vite_ruby
204
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.0.0.beta.1/vite_ruby/CHANGELOG.md
205
+ post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
206
+ manually, please run:\n\tbundle exec vite upgrade"
204
207
  rdoc_options: []
205
208
  require_paths:
206
209
  - lib