vite_ruby 2.0.0.beta.6 → 3.0.0.beta.1

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: '0058a6fc7f925f10e97f390c028abbbecc2c4c9cc5e27f214cbcba826c42fe69'
4
- data.tar.gz: ebc2076502683d817f99c284fc2f6ec7adfa75dfd41f8f623a72e221cd56da5a
3
+ metadata.gz: 0dd16ba0c6a663008ac6fdf8679db418557dd9a6930dd3e5ef3df70a0e6ac326
4
+ data.tar.gz: 960ce8db783f8305d8fa5ff41330226ac44e0cfc0feb702a30400c60d4910d08
5
5
  SHA512:
6
- metadata.gz: 728652c1e4f0884bde8a1823f9a70ffdf12ce509fdb8f7ae898133d8f9084cbcc1a0204da38212c8281f02e4e77f0ec8a481c85ce7e3f74be189965d34fbe791
7
- data.tar.gz: 6ed6080dcb36974a061d974188ede76c700b27e97a63ec5b357225acbd04dc5f555a13bc45f4790c73d9daba20c104181583f3a650a0fd7da6dc544c4b680b10
6
+ metadata.gz: 7f9e9b3727563b7a8c2c81fababf599a0c4158ee3d2e06c2fd16a4643cea8a461f178425d0f044ba467000e468642e3932873f18ac3866cd09f02a7c201c9392
7
+ data.tar.gz: abcd610257b8edaa0b1d8849d35750ad399b250178bcf1f501935e373b85b02465b247ca43918186f20ed37bf8e33bef29852cfa1af9a716c18b089db8de497e
data/lib/vite_ruby.rb CHANGED
@@ -23,9 +23,7 @@ class ViteRuby
23
23
  COMPANION_LIBRARIES = {
24
24
  'vite_rails' => 'rails',
25
25
  'vite_hanami' => 'hanami',
26
- 'vite_roda' => 'roda',
27
26
  'vite_padrino' => 'padrino',
28
- 'vite_sinatra' => 'sinatra',
29
27
  'jekyll-vite' => 'jekyll',
30
28
  'vite_rails_legacy' => 'rails',
31
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
@@ -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.
@@ -114,8 +110,18 @@ private
114
110
  end
115
111
 
116
112
  def run_with_capture(*args, **options)
117
- _, stderr, status = ViteRuby::IO.capture(*args, **options)
118
- say(err) unless status.success? || stderr.to_s.empty?
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'
119
125
  end
120
126
 
121
127
  # Internal: Avoid printing warning about missing vite.json, we will create one.
@@ -5,10 +5,7 @@ class ViteRuby::CLI::UpgradePackages < ViteRuby::CLI::Install
5
5
 
6
6
  def call(**)
7
7
  say 'Upgrading npm packages'
8
-
9
- Dir.chdir(root) do
10
- deps = js_dependencies.join(' ')
11
- run_with_capture("npx --package @antfu/ni -- ni -D #{ deps }")
12
- end
8
+ deps = js_dependencies.join(' ')
9
+ run_with_capture("#{ npm_install } -D #{ deps }")
13
10
  end
14
11
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '2.0.0.beta.6'
4
+ VERSION = '3.0.0.beta.1'
5
5
 
6
6
  # Internal: Versions used by default when running `vite install`.
7
7
  DEFAULT_VITE_VERSION = '^2.5.0-beta.2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vite_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta.6
4
+ version: 3.0.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
@@ -200,8 +200,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
200
200
  licenses:
201
201
  - MIT
202
202
  metadata:
203
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@2.0.0.beta.6/vite_ruby
204
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@2.0.0.beta.6/vite_ruby/CHANGELOG.md
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
205
  post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
206
206
  manually, please run:\n\tbundle exec vite upgrade"
207
207
  rdoc_options: []