vite_ruby 2.0.0.beta.3 → 3.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vite_ruby.rb +2 -6
- data/lib/vite_ruby/build.rb +15 -4
- data/lib/vite_ruby/builder.rb +5 -3
- data/lib/vite_ruby/cli.rb +3 -1
- data/lib/vite_ruby/cli/file_utils.rb +16 -7
- data/lib/vite_ruby/cli/install.rb +18 -7
- data/lib/vite_ruby/cli/upgrade.rb +25 -0
- data/lib/vite_ruby/cli/upgrade_packages.rb +11 -0
- data/lib/vite_ruby/version.rb +5 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dd16ba0c6a663008ac6fdf8679db418557dd9a6930dd3e5ef3df70a0e6ac326
|
4
|
+
data.tar.gz: 960ce8db783f8305d8fa5ff41330226ac44e0cfc0feb702a30400c60d4910d08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
}
|
data/lib/vite_ruby/build.rb
CHANGED
@@ -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(
|
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(
|
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.
|
data/lib/vite_ruby/builder.rb
CHANGED
@@ -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
|
-
'
|
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
|
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
|
-
|
35
|
+
content = read_lines(path)
|
36
|
+
return if content.join.include?(contents)
|
36
37
|
|
37
|
-
content
|
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 =
|
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 =
|
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 =
|
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
|
-
|
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
|
data/lib/vite_ruby/version.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class ViteRuby
|
4
|
-
VERSION = '
|
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:
|
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-
|
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@
|
202
|
-
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@
|
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
|