Skip to content

Commit 8046066

Browse files
committed
support npm + pre
1 parent 482074c commit 8046066

File tree

10 files changed

+140
-30
lines changed

10 files changed

+140
-30
lines changed

.travis.yml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ cache:
55
bundler: true
66
yarn: true
77

8-
rvm:
9-
- 2.3
10-
- 2.4
11-
- 2.5
12-
13-
env:
14-
- RAILS_VERSION=4.2
15-
- RAILS_VERSION=5.2
16-
178
matrix:
18-
exclude:
9+
allow_failures:
10+
- env: RAILS_VERSION=pre
11+
include:
12+
- rvm: 2.3
13+
env: RAILS_VERSION=4.2 PACKAGE_MANAGER=npm
14+
- rvm: 2.3
15+
env: RAILS_VERSION=5.2 PACKAGE_MANAGER=yarn
16+
- rvm: 2.4
17+
env: RAILS_VERSION=5.2 PACKAGE_MANAGER=npm
18+
- rvm: 2.5
19+
env: RAILS_VERSION=5.2 PACKAGE_MANAGER=yarn
20+
- rvm: 2.6
21+
env: RAILS_VERSION=5.2 PACKAGE_MANAGER=npm
1922
- rvm: 2.5
20-
env: RAILS_VERSION=4.2
23+
env: RAILS_VERSION=pre PACKAGE_MANAGER=npm
24+
- rvm: 2.6
25+
env: RAILS_VERSION=pre PACKAGE_MANAGER=yarn
2126

2227
gemfile:
2328
- test/Gemfile-rails.$RAILS_VERSION
@@ -28,19 +33,18 @@ before_install:
2833
install:
2934
- nvm install --lts
3035
- node -v
31-
- yarn global add @vue/cli
36+
- sh -c 'if test "$PACKAGE_MANAGER" = "npm"; then npm i -g @vue/cli; else yarn global add @vue/cli fi'
3237
- gem install rspec
3338

34-
before_script:
35-
- sh -c 'cd test && ./install.rb'
36-
3739
script:
38-
- sh -c 'cd test && rspec ./vcr_spec.rb'
40+
- sh -c 'cd test && ./install.rb'
41+
- sh -c 'cd test && rspec ./vcr_specs.rb'
3942

4043
jobs:
4144
include:
4245
- stage: gem release
4346
rvm: 2.3
47+
env: RAILS_VERSION=4.2 PACKAGE_MANAGER=yarn
4448
script: echo "Deploying to rubygems.org ..."
4549
deploy:
4650
provider: rubygems

lib/helpers/lib/common.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@ class Object
33
def blank?
44
respond_to?(:empty?) ? !!empty? : !self
55
end
6+
7+
def presence
8+
blank? ? nil : self
9+
end
10+
11+
def present?
12+
!blank?
13+
end
614
end
715
end

lib/helpers/scripts/vue_create.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def run_vue_create?
7474
if @pack.exist?
7575
puts 'Detected `package.json`!'
7676
pack_input = @input.gets(
77-
' Do you want `vue create?` to overwrite your package.json',
77+
' Do you want vue-cli to overwrite your package.json',
7878
'yAks',
7979
a: 'Auto', k: 'Keep', s: 'Skip vue create',
8080
)
@@ -86,7 +86,7 @@ def run_vue_create?
8686
if gi.exist?
8787
puts 'Detected `.gitignore`!'
8888
gi_input = @input.gets(
89-
' Do you want `vue create?` to overwrite your .gitignore',
89+
' Do you want vue-cli to overwrite your .gitignore',
9090
'yMk',
9191
m: 'Merge', k: 'Keep',
9292
)

lib/source/vue.rails.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module.exports = (() => {
5757
const root = resolve(__dirname);
5858
const pop = (config.public_output_path || 'vue_assets').replace(/(^\/+|\/+$)/g, '');
5959
const {
60+
package_manager: packageManager,
6061
manifest_output: manifestOutput,
6162
js_output: output,
6263
alias = {},
@@ -100,6 +101,7 @@ module.exports = (() => {
100101
settings = {
101102
env: mode,
102103
root,
104+
packageManager,
103105
manifestOutput: manifestOutput && resolve(root, manifestOutput),
104106

105107
outputDir: resolve(root, 'public', pop),

lib/vue_cli/rails/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def load_config(config)
3737
},
3838
}
3939
@package_manager = config['package_manager']
40+
c['packageManger'] = @package_manager
4041
cw = c['configureWebpack']
4142

4243
c['env'] = ::Rails.env

test/Gemfile-rails.5.2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source 'https://rubygems.org'
22

3-
gem 'rails', '~> 5.2.2', '>= 5.2.2.1'
3+
gem 'rails', '~> 5.2.0'
44
gem 'puma', '~> 3.11'
55
gem 'sass-rails', '~> 5.0'
66
gem 'uglifier', '>= 1.3.0'

test/Gemfile-rails.pre

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rails', '~> 6.0.0'
4+
gem 'puma', '~> 3.11'
5+
gem 'sass-rails', '~> 5.0'
6+
7+
gem 'bootsnap', '>= 1.4.1', require: false
8+
9+
group :development do
10+
gem 'spring'
11+
end
12+
13+
gem 'vue_cli-rails', path: '../../'
14+
gem 'sqlite3', '~> 1.3.0'

test/install.rb

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ def yield_args_by_rails(ver)
147147
spring
148148
spring-watcher-listen
149149
]
150+
elsif ver.start_with?('6')
151+
args = %w[
152+
--database=sqlite3
153+
--skip-git
154+
--skip-keeps
155+
--skip-bundle
156+
--skip-yarn
157+
--skip-turbolinks
158+
--skip-listen
159+
--skip-coffee
160+
--skip-test
161+
]
162+
white_list = %w[
163+
rails
164+
puma
165+
sass-rails
166+
uglifier
167+
bootsnap
168+
jquery-rails
169+
spring
170+
spring-watcher-listen
171+
]
150172
else
151173
abort("Unsupported Rails version: #{ver}!\n#{USAGE}")
152174
end
@@ -173,20 +195,25 @@ def rails_ver
173195
ver = ENV['RAILS_VERSION']
174196
abort("RAILS_VERSION not found!\n#{USAGE}") if ver.blank?
175197

176-
versions = %x`gem list -r -a -e rails`.scan(/\b((\d+\.)+\d+)\b/).map { |m| m[0] }
177-
ver = ver.upcase == 'LATEST' ? versions.first : versions.find { |v| v.start_with?(ver) }
198+
if ver.upcase == 'PRE'
199+
ver = %x`gem list -r -e --pre rails`.scan(/\b((\d+\.)+\w+)\b/).map { |m| m[0] }.first
200+
else
201+
versions = %x`gem list -r -e -a rails`.scan(/\b((\d+\.)+\d+)\b/).map { |m| m[0] }
202+
ver = ver.upcase == 'LATEST' ? versions.first : versions.find { |v| v.start_with?(ver) }
203+
end
178204
abort("Can not find matched Rails version!\n#{USAGE}") if ver.blank?
179205
ver
180206
end
181207

182-
def auto_install(pm = 'yarn')
208+
def auto_install(pm = nil)
183209
PTY.spawn('bundle exec rake vue:create 2>&1') do |r, w, _pid|
184210
STDERR.puts '--'
185211
STDERR.puts 'bundle exec rake vue:create'
186212
STDERR.puts 'AUTO FILL-UP'
187213
STDERR.puts ''
188214

189-
simple_answer(r, w, 'Which package manager', pm == 'yarn' ? 'y' : 'n')
215+
simple_answer(r, w, 'Which package manager', pm == 'npm' ? 'n' : 'y')
216+
simple_answer(r, w, 'Do you want vue-cli to overwrite your package.json')
190217
wait_answer(r, w, 'Generate project in current directory')
191218

192219
ln = select_single(r, w, 'Please pick a preset', 'Manually select features')
@@ -222,7 +249,7 @@ def main
222249

223250
update_gemfile(dest_dir, white_list, append_lines)
224251
Cmd.run('bundle install')
225-
auto_install
252+
auto_install(ENV['PACKAGE_MANAGER'])
226253
end
227254

228255
main

test/uninstall_rails.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env ruby
2+
3+
require_relative '../lib/helpers/lib/common'
4+
5+
def get_rails_version
6+
ver = ARGV[0].presence || ENV['RAILS_VERSION']
7+
versions = %x`gem list -e activesupport`.scan(/\b((\d+\.)+\w+)\b/).map { |m| m[0] }
8+
if ver.blank?
9+
abort <<~TEXT
10+
Must specify a Rails version!
11+
Installed versions: #{versions.join(' ')}
12+
TEXT
13+
end
14+
15+
unless versions.include?(ver)
16+
abort <<~TEXT
17+
Version (#{ver}) does not exist in the system
18+
available versions: #{versions.join(' ')}
19+
TEXT
20+
end
21+
ver
22+
end
23+
24+
KNOWN_GEMS = %w[
25+
rails
26+
railties
27+
28+
actioncable
29+
actionmailbox
30+
actionmailer
31+
actiontext
32+
activejob
33+
34+
activestorage
35+
activerecord
36+
activemodel
37+
actionpack
38+
actionview
39+
activesupport
40+
]
41+
42+
def main
43+
ver = get_rails_version
44+
re = %r{\b#{ver.tr('.', '\.')}\b}
45+
KNOWN_GEMS.each do |gem|
46+
next unless %x[gem list -e #{gem}] =~ re
47+
puts %x[gem uninstall #{gem} -v #{ver}]
48+
end
49+
puts "Done! - Rails #{ver} should be uninstalled"
50+
end
51+
52+
main

test/vcr_spec.rb renamed to test/vcr_specs.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'rspec'
44
require 'fileutils'
55
require 'pathname'
6+
require 'json'
67

78
RSpec.configure do |config|
89
# Enable flags like --only-failures and --next-failure
@@ -21,6 +22,7 @@
2122
@cwd = Pathname.new(__dir__).join('vcdr')
2223
Dir.chdir(@cwd)
2324
@env = %x`which env`.chomp
25+
@pm = JSON.parse(%x`bundle exec rake vue:json_config`)['packageManger']
2426
end
2527

2628
it 'can invoke vue:lint' do
@@ -44,24 +46,24 @@
4446
}.not_to raise_error
4547
end
4648

47-
it 'can run yarn lint' do
49+
it 'can run npm run / yarn lint' do
4850
expect {
49-
%x(#{@env} RAILS_ENV=test yarn lint)
51+
%x(#{@env} RAILS_ENV=test #{@pm} lint)
5052
}.not_to raise_error
5153
end
5254

53-
it 'can run yarn test:unit' do
55+
it 'can run npm run / yarn test:unit' do
5456
expect {
55-
%x(#{@env} RAILS_ENV=test yarn test:unit)
57+
%x(#{@env} RAILS_ENV=test #{@pm} test:unit)
5658
}.not_to raise_error
5759
end
5860

59-
it 'can add vue:node_dev and run yarn prod' do
61+
it 'can add vue:node_dev and run npm run / yarn prod' do
6062
expect {
6163
%x(#{@env} bundle exec rake vue:node_dev)
6264
}.not_to raise_error
6365
expect {
64-
%x(#{@env} yarn prod)
66+
%x(#{@env} #{@pm} prod)
6567
}.not_to raise_error
6668
end
6769
end

0 commit comments

Comments
 (0)