Skip to content

Commit aa2a480

Browse files
committed
bug fixes and new task compile
1 parent a8332fd commit aa2a480

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

lib/tasks/vue.rake

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ namespace :vue do
3636
end
3737
puts "Using package manager: #{pm.package_manager}"
3838

39+
# install vue-cli
40+
unless pm.vue?
41+
puts "@vue/cli haven't been installed"
42+
pm.global_add('@vue/cli')
43+
end
44+
3945
src_dir = Pathname.new(__FILE__).dirname.join('..', 'source')
4046
root = ::Rails.root
4147
FileUtils.chdir root
@@ -62,7 +68,7 @@ namespace :vue do
6268
if src.exist? && src.directory?
6369
puts 'Detected `src` folder (should be generated by vue-cli)'
6470
input = get_input.call(' Do you want to delete src folder?')
65-
FileUtils.rm_rf root.join('src') if input == 'y'
71+
FileUtils.rm_rf src if input == 'y'
6672
end
6773

6874
# 5. copy sample codes
@@ -109,6 +115,8 @@ namespace :vue do
109115
end
110116
end
111117
throw(StandardError, '') if pkgs.empty?
118+
119+
pm = VueCli::Rails::Configuration.instance.node_env
112120
pm.add "-D #{pkgs.join(' ')}"
113121
end
114122

@@ -117,4 +125,10 @@ namespace :vue do
117125
config = VueCli::Rails::Configuration.new
118126
puts config.to_json
119127
end
128+
129+
desc 'Bundle assets for production'
130+
task :compile => :environment do
131+
pm = VueCli::Rails::Configuration.instance.node_env
132+
pm.exec('vue-cli-service build', env: { 'RAILS_ENV' => 'production' })
133+
end
120134
end

lib/vue_cli/rails/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def vue_entry(name)
55
@config ||= VueCli::Rails::Configuration.instance
66

77
entry = (@config.manifest_data['entrypoints'] || {})[name]
8-
return nil if entry.blank?
8+
return raise(VueCli::Rails::Error, "Not found vue entry point: #{name}") if entry.blank?
99

1010
assets = []
1111
(entry['css'] || []).each do |css|

lib/vue_cli/rails/node_env.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def package_manager
2828
@pm
2929
end
3030

31-
def exec(command, args = nil, extra = nil)
31+
def exec(command, args = nil, extra = nil, env: {})
3232
cmd = COMMAND_LINE[command.to_sym] || {}
3333
if @pm == :yarn && cmd[:yarn]
3434
cmd = cmd[:yarn]
@@ -43,14 +43,18 @@ def exec(command, args = nil, extra = nil)
4343
cmd = "#{cmd} #{args}" if args.present?
4444
cmd = "#{cmd} #{@pm == :yarn ? '-- ' : ''}#{extra}" if extra.present?
4545
puts "run: #{cmd}"
46-
system(cmd)
46+
system(env, cmd)
4747
end
4848

4949
COMMAND_LINE = {
5050
add: {
5151
yarn: 'yarn add',
5252
npm: 'npm i -S',
53-
}
53+
},
54+
global_add: {
55+
yarn: 'yarn global add',
56+
npm: 'npm i -g'
57+
},
5458
}.freeze
5559

5660
def method_missing(cmd, *args)
@@ -62,7 +66,7 @@ def method_missing(cmd, *args)
6266
def get_version_of(bin)
6367
return @versions[bin] if @versions.key?(bin)
6468

65-
r = `#{bin} --version`.strip.presence
69+
r = `#{bin} --version`.strip.presence rescue nil
6670
@versions[bin] = r && r.start_with?('v') ? r[1..-1] : r
6771
@versions[bin]
6872
end

lib/vue_cli/rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module VueCli
22
module Rails
3-
VERSION = "0.1.3"
3+
VERSION = "0.1.4"
44
end
55
end

0 commit comments

Comments
 (0)