vue_cli-rails 0.1.6 → 0.2.0

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
- SHA1:
3
- metadata.gz: 193e3f266fe5df04d06da5ba07e6811bcb95dcff
4
- data.tar.gz: a62e9dbd576de83ab3a41130263b1379c2fbed1a
2
+ SHA256:
3
+ metadata.gz: 0a7ee2779059b83202b6057251b245a50fc3b0e7a803c0a61e113da7aa6b10d1
4
+ data.tar.gz: 8bde5723e1263ec2f0a0063e78c8f7467effe82a661dd6910fc020275b3776fb
5
5
  SHA512:
6
- metadata.gz: 1e61eb0f58518561a57cf3d3602d9eed052460f142b9d4b6f3847827d6d2a15a0503c7ee966c30a5ca9dee2dd58d530571e1f47a8565da7ea40b07470ba156cd
7
- data.tar.gz: b8a32249e7be88fa8eb0c11c351126078d998c77cecd306c322bb4955cbefb3a6290a850db28b2b11094b6226664f6f5b647058732e3f974df7c8ee5a8d74ba0
6
+ metadata.gz: 6b244978b9ca71bd0fff983c1f45db81ed07aee91664830fa53a65ba8e85b98d18479736ad4208979d52e67bff54fcdf389a333e09143e312c7f4684c4076a5b
7
+ data.tar.gz: 30adca9ac7ec73732568e9865666c1035298828893cdecf8c4f92fd14e71d8993ad7638385c428eefc043645e43c37a6543a07da4aaa1b59f0c1349346388298
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  *.gem
13
+ .rubocop-http*
data/.rubocop.yml CHANGED
@@ -1,20 +1,8 @@
1
+ inherit_from:
2
+ - http://shopify.github.io/ruby-style-guide/rubocop.yml
3
+
1
4
  AllCops:
2
5
  TargetRubyVersion: 2.3
3
6
 
4
- Metrics/LineLength:
5
- Max: 99
6
-
7
7
  Style/FrozenStringLiteralComment:
8
8
  Enabled: false
9
-
10
- Style/TrailingCommaInArguments:
11
- EnforcedStyleForMultiline: comma
12
-
13
- Style/TrailingCommaInArrayLiteral:
14
- EnforcedStyleForMultiline: comma
15
-
16
- Style/TrailingCommaInHashLiteral:
17
- EnforcedStyleForMultiline: comma
18
-
19
- Style/Documentation:
20
- Enabled: false
data/.travis.yml CHANGED
@@ -3,18 +3,5 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.3.8
7
6
  - 2.4.5
8
- - 2.5.2
9
- - 2.6.1
10
- env:
11
- - RAILS_VERSION=4 NODE_VERSION=8
12
- - RAILS_VERSION=4 NODE_VERSION=lts
13
- - RAILS_VERSION=5 NODE_VERSION=lts
14
- - RAILS_VERSION=5 NODE_VERSION=latest
15
- matrix:
16
- fast_finish: true
17
- include:
18
- - rvm: ruby-head
19
- env: RAILS_VERSION=beta NODE_VERSION=latest
20
7
  before_install: gem install bundler -v 1.17.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vue_cli-rails (0.1.0)
4
+ vue_cli-rails (0.2.0)
5
5
  activesupport (>= 4.2)
6
6
  rack-proxy (>= 0.6)
7
7
  railties (>= 4.2)
@@ -34,7 +34,7 @@ GEM
34
34
  crass (1.0.4)
35
35
  diff-lcs (1.3)
36
36
  erubi (1.8.0)
37
- i18n (1.5.3)
37
+ i18n (1.6.0)
38
38
  concurrent-ruby (~> 1.0)
39
39
  loofah (2.2.3)
40
40
  crass (~> 1.0.2)
@@ -96,4 +96,4 @@ DEPENDENCIES
96
96
  vue_cli-rails!
97
97
 
98
98
  BUNDLED WITH
99
- 1.17.3
99
+ 1.17.2
data/README.md CHANGED
@@ -58,11 +58,11 @@ Please ONLY puts your entry-point files under `app/assets/vue/views` folder with
58
58
 
59
59
  > Be aware, `.js.erb` and `.vue.erb` are NOT supported. I will explain the reason in [Q&A section](#difference-from-webpacker).
60
60
 
61
- If you are new to modern front-end development, or more specifically with `webpack` in this case, please read [Q&A section](#Q&A) for more information.
61
+ If you are new to modern front-end development, or more specifically with `webpack` in this case, please read [Q&A section](#qa) for more information.
62
62
 
63
63
  #### Helper `vue_entry`
64
64
 
65
- `vue_entry` is like `javascript_include_tag` and `stylesheet_link_tag` which generates relative assets links for your entry point. (It's like a combination of `stylesheet_pack_tag` and `javascript_packs_with_chunks_tag` in Webpacker 4. I will explain why it's different in [Q&A](#Q&A).)
65
+ `vue_entry` is like `javascript_include_tag` and `stylesheet_link_tag` which generates relative assets links for your entry point. (It's like a combination of `stylesheet_pack_tag` and `javascript_packs_with_chunks_tag` in Webpacker 4. I will explain why it's different in [Q&A](#qa).)
66
66
 
67
67
  > You may have interest of path alias in `config/vue.yml`.
68
68
 
@@ -204,7 +204,7 @@ Actually `public_output_path` in `config/vue.yml` is very simple - just a sub pa
204
204
 
205
205
  - `package_manager`
206
206
 
207
- Pretty straightforward, which package manager will be used. Valid value: `npm` or `yarn`. It does NOT support `pnpm` or other package managers. You can find the reason in [Q&A](#Q&A).
207
+ Pretty straightforward, which package manager will be used. Valid value: `npm` or `yarn`. It does NOT support `pnpm` or other package managers. You can find the reason in [Q&A](#qa).
208
208
 
209
209
  - `public_output_path`
210
210
 
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task default: :spec
6
+ task(default: :spec)
@@ -5,7 +5,7 @@ class InputLoop
5
5
  default, list = build_list(list)
6
6
  keys_hint, hint = build_hint(list, hint)
7
7
 
8
- print "#{message} (#{hint}) #{keys_hint}"
8
+ print("#{message} (#{hint}) #{keys_hint}")
9
9
  wait_valid_input(keys_hint, Set.new(list.map(&:downcase)), default)
10
10
  end
11
11
 
@@ -4,8 +4,8 @@ require_relative 'common'
4
4
  ver = ENV['RAILS_VERSION']
5
5
  abort('RAILS_VERSION not found!') if ver.blank?
6
6
 
7
- versions = `gem list -r -a -e rails`.scan(/\b((\d+\.)+\d+)\b/).map { |m| m[0] }
8
- ver = versions.find { |v| v.start_with? ver }
7
+ versions = %x`gem list -r -a -e rails`.scan(/\b((\d+\.)+\d+)\b/).map { |m| m[0] }
8
+ ver = versions.find { |v| v.start_with?(ver) }
9
9
  abort("Version #{ver} not found!") if ver.blank?
10
10
 
11
11
  run("gem install rails -v #{ver}")
@@ -26,9 +26,7 @@ RAILS_NEW_SCRIPT = {
26
26
  skip-bundle
27
27
  ],
28
28
  keep_gems: /^\s*gem\s+['"](rails|puma|bootsnap)/,
29
- append: <<~RUBY
30
- gem 'sqlite3', '~> 1.3.10'
31
- RUBY
29
+ append: "gem 'sqlite3', '~> 1.3.10'",
32
30
  },
33
31
  }
34
32
 
@@ -36,13 +34,12 @@ require 'pathname'
36
34
  require 'fileutils'
37
35
 
38
36
  scirpt = RAILS_NEW_SCRIPT[ver[0]]
39
- run "rails new test_vcr #{scirpt[:args].map { |a| "--#{a}" }.join(' ')}"
40
- FileUtils.chdir 'test_vcr'
37
+ run("rails new test_vcr #{scirpt[:args].map { |a| "--#{a}" }.join(' ')}")
38
+ FileUtils.chdir('test_vcr')
41
39
 
42
40
  root = Pathname.new(FileUtils.pwd)
43
41
  gemfile = root.join('Gemfile').read.split("\n")
44
- .reject(&:empty?).reject { |s| s =~ /^\s*#/ }
45
- .reject { |s| s =~ /^\s*gem/ && s !~ scirpt[:keep_gems] }
42
+ .reject(&:empty?).reject { |s| s =~ /^\s*#/ }
43
+ .reject { |s| s =~ /^\s*gem/ && s !~ scirpt[:keep_gems] }
46
44
  root.join('Gemfile').write("#{(gemfile + [scirpt[:append]]).join("\n")}\n")
47
- run 'bundle install'
48
- # rails new test_vcr --database=sqlite3 --skip-yarn --skip-git --skip-sprockets --skip-spring --skip-listen --skip-turbolinks --skip-javascript --skip-test --skip-bundle
45
+ run('bundle install')
@@ -23,7 +23,7 @@ class VueCommand
23
23
  end
24
24
 
25
25
  STDERR.puts "Unsupported formats #{unknown}" if unknown.any?
26
- @pm.add "-D #{pkgs.join(' ')}"
26
+ @pm.add("-D #{pkgs.join(' ')}")
27
27
  end
28
28
 
29
29
  def install_node_dev
@@ -32,10 +32,10 @@ class VueCommand
32
32
 
33
33
  add_deps(pack_json, %w[cross-env npm-run-all])
34
34
  add_scripts(pack_json,
35
- dev: 'run-p rails-s serve',
36
- prod: 'cross-env RAILS_ENV=production vue-cli-service build',
37
- serve: 'vue-cli-service serve',
38
- 'rails-s' => 'cross-env NO_WEBPACK_DEV_SERVER=1 rails s')
35
+ dev: 'run-p rails-s serve',
36
+ prod: 'cross-env RAILS_ENV=production vue-cli-service build',
37
+ serve: 'vue-cli-service serve',
38
+ 'rails-s' => 'cross-env NO_WEBPACK_DEV_SERVER=1 rails s')
39
39
  puts 'Dependencies and scripts have been installed successfully'
40
40
  cmd = @pm.package_manager == :npm ? 'npm run' : 'yarn'
41
41
  puts " Please use `#{cmd} dev` to start dev server"
@@ -49,14 +49,14 @@ class VueCommand
49
49
  pkgs = [packages].flatten.find_all do |dep|
50
50
  !(dep.blank? || deps.key?(dep))
51
51
  end
52
- @pm.add "#{dev ? '-D ' : ''}#{pkgs.join(' ')}" if pkgs.any?
52
+ @pm.add("#{dev ? '-D ' : ''}#{pkgs.join(' ')}") if pkgs.any?
53
53
  end
54
54
 
55
55
  def add_scripts(package_json, commands = {})
56
56
  json = JSON.parse(package_json.read)
57
57
  scripts = json['scripts']
58
58
  commands.stringify_keys.each do |key, cmd|
59
- scripts[key] = cmd unless scripts.key? key
59
+ scripts[key] = cmd unless scripts.key?(key)
60
60
  end
61
61
  package_json.write(JSON.pretty_generate(json))
62
62
  end
@@ -15,19 +15,22 @@ class VueCreate
15
15
 
16
16
  def start
17
17
  check_node!
18
- FileUtils.chdir @root
18
+ FileUtils.chdir(@root)
19
+ @pending_install = false
19
20
  begin
20
21
  package_manager?
21
22
  install_vue_cli
22
23
  run_vue_create?
23
24
  install_dev_deps
24
- delete_vue_src?
25
+ @pm.install if @pending_install
26
+ delete_vue_sample?
25
27
  copy_demo?
26
28
  copy_config
27
29
  generate_vue_yml
30
+ fix_jest_config!
28
31
  puts 'vue:create finished!'
29
32
  ensure
30
- FileUtils.chdir @pwd
33
+ FileUtils.chdir(@pwd)
31
34
  end
32
35
  end
33
36
 
@@ -43,14 +46,14 @@ class VueCreate
43
46
  npm = @pm.npm_version
44
47
  abort('Cannot find npm or yarn') unless yarn || npm
45
48
 
46
- if yarn && npm
47
- input = @input.gets(
49
+ input = if yarn && npm
50
+ @input.gets(
48
51
  'Which package manager to use?',
49
52
  @root.join('package-lock.json').exist? ? 'yN' : 'Yn',
50
53
  y: 'yarn', n: 'npm',
51
54
  )
52
55
  else
53
- input = npm ? 'n' : 'y'
56
+ npm ? 'n' : 'y'
54
57
  end
55
58
  @pm.use!(input == 'n' ? :npm : :yarn)
56
59
  puts "Using package manager: #{@pm.package_manager}"
@@ -64,27 +67,73 @@ class VueCreate
64
67
  end
65
68
 
66
69
  def run_vue_create?
67
- input = 'y'
70
+ pack_input = 'y'
68
71
  if @pack.exist?
69
72
  puts 'Detected `package.json`!'
70
- input = @input.gets(
73
+ pack_input = @input.gets(
71
74
  ' Do you want `vue create?` to overwrite your package.json',
72
- 'ynAk',
73
- a: 'Auto', k: 'Keep',
75
+ 'yAks',
76
+ a: 'Auto', k: 'Keep', s: 'Skip vue create',
77
+ )
78
+ end
79
+ return if pack_input == 's'
80
+
81
+ gi_input = 'y'
82
+ gi = @root.join('.gitignore')
83
+ if gi.exist?
84
+ puts 'Detected `.gitignore`!'
85
+ gi_input = @input.gets(
86
+ ' Do you want `vue create?` to overwrite your .gitignore',
87
+ 'yMk',
88
+ m: 'Merge', k: 'Keep',
74
89
  )
75
90
  end
76
- return if input == 'n'
77
91
 
78
- src_json = JSON.parse(@pack.read) unless input == 'y'
79
- @pm.exec('vue create', '', "-n -m #{@pm.package_manager} .")
92
+ # backups
93
+ vue_config = @root.join('vue.config.js')
94
+ backup_vue_config = vue_config.exist?
95
+ src_json = JSON.parse(@pack.read) if pack_input != 'y'
96
+ gi_lines = gi.read.split("\n") if gi_input != 'y'
97
+ if backup_vue_config
98
+ FileUtils.mv(vue_config, "#{vue_config}.backup")
99
+ # will be recreated
100
+ FileUtils.rm_f(@root.join('vue.rails.js'))
101
+ end
102
+ pub_dir = @root.join('public')
103
+ FileUtils.mv(pub_dir, "#{pub_dir}.backup")
80
104
 
81
- dst_json = JSON.parse(@pack.read) unless input == 'y'
82
- return if input == 'y' || dst_json == src_json
105
+ begin
106
+ @pm.exec('vue create', '', "-n -m #{@pm.package_manager} .")
107
+ ensure
108
+ # restore backups
109
+ FileUtils.rm_rf(pub_dir) if pub_dir.exist?
110
+ FileUtils.mv("#{pub_dir}.backup", pub_dir)
111
+ FileUtils.mv("#{vue_config}.backup", vue_config) if backup_vue_config
112
+ end
83
113
 
84
- src_json, dst_json = [dst_json, src_json] if input == 'a'
114
+ # merge gitignore
115
+ if gi_input == 'm'
116
+ old_gi_line_count = gi_lines.size
117
+ old_gi = Set.new(gi_lines.map(&:strip))
118
+
119
+ gi.read.split("\n").map(&:strip).find_all(&:present?).each do |ln|
120
+ gi_lines << ln unless old_gi.include?(ln)
121
+ end
122
+ gi.write(gi_lines.map { |ln| "#{ln}\n" }.join('')) if gi_lines.size > old_gi_line_count
123
+ elsif gi_input == 'k'
124
+ gi.write(gi_lines.join(''))
125
+ end
126
+
127
+ # check packages.json
128
+ return if pack_input == 'y'
129
+ dst_json = JSON.parse(@pack.read)
130
+ return if dst_json == src_json
131
+
132
+ # merge packages.json
133
+ src_json, dst_json = [dst_json, src_json] if pack_input == 'a'
85
134
  dst_json.deep_merge!(src_json)
86
135
  @pack.write(JSON.pretty_generate(dst_json))
87
- @pm.install
136
+ @pending_install = true
88
137
  end
89
138
 
90
139
  def install_dev_deps
@@ -93,15 +142,20 @@ class VueCreate
93
142
  dd = %w[webpack-assets-manifest js-yaml].find_all do |dep|
94
143
  !dev_deps.key?(dep)
95
144
  end
96
- @pm.add "-D #{dd.join(' ')}" if dd.any?
145
+ if dd.any?
146
+ @pm.add("-D #{dd.join(' ')}")
147
+ @pending_install = false
148
+ end
97
149
  end
98
150
 
99
- def delete_vue_src?
100
- src = @root.join('src')
101
- return unless src.exist? && src.directory?
151
+ def delete_vue_sample?
152
+ %w[src dist].each do |fn|
153
+ file = @root.join(fn)
154
+ next unless file.exist?
102
155
 
103
- puts 'Detected `src` folder (should be generated by vue-cli)'
104
- FileUtils.rm_rf(src.to_s) if @input.gets(' Do you want to delete src folder?') == 'y'
156
+ puts "Detected `#{fn}` (should be generated by vue-cli)"
157
+ FileUtils.rm_rf(file.to_s) if @input.gets(" Do you want to delete #{file}?") == 'y'
158
+ end
105
159
  end
106
160
 
107
161
  def copy_demo?
@@ -115,8 +169,8 @@ class VueCreate
115
169
  foo = false
116
170
  bar = false
117
171
  route_lines.each do |line|
118
- foo ||= line.include? 'vue#foo'
119
- bar ||= line.include? 'vue#bar'
172
+ foo ||= line.include?('vue#foo')
173
+ bar ||= line.include?('vue#bar')
120
174
  end
121
175
  return if foo && bar
122
176
 
@@ -147,7 +201,28 @@ class VueCreate
147
201
  end
148
202
 
149
203
  yml = @src_dir.join('vue.yml').read
150
- yml = yml.sub('${PACKAGE_MANAGER}', pm.package_manager.to_s)
204
+ yml = yml.sub('${PACKAGE_MANAGER}', @pm.package_manager.to_s)
151
205
  yml_dest.write(yml)
152
206
  end
207
+
208
+ def fix_jest_config!
209
+ jest_file = @root.join('jest.config.js')
210
+ return unless jest_file.exist?
211
+
212
+ jest_config = %x`node -e "console.log(JSON.stringify(require('./jest.config.js')))"`
213
+ jest_config = JSON.parse(jest_config)
214
+ jest_config.delete('moduleNameMapper')
215
+ jest = <<~JS
216
+ const { jestModuleNameMapper: moduleNameMapper } = require('./vue.rails');
217
+
218
+ module.exports = #{JSON.pretty_generate(jest_config)}_MODULE_NAME_MAPPER_;
219
+ JS
220
+ jest_file.write(jest.sub(/\n?}_MODULE_NAME_MAPPER_/, ",\n moduleNameMapper\n}"))
221
+
222
+ dev_deps = JSON.parse(@pack.read)['devDependencies']
223
+ return unless dev_deps['eslint'].present?
224
+ @pm.exec('eslint', jest_file.to_s, '--fix')
225
+ rescue => e
226
+ STDERR.puts e.message
227
+ end
153
228
  end
@@ -55,26 +55,27 @@ module.exports = {
55
55
 
56
56
  /* put your custom code here
57
57
  // Example: npm/yarn add -D compression-webpack-plugin webpack-bundle-analyzer
58
- if (isProd) {
59
- config
60
- .plugin('compression')
61
- .use(CompressionWebpackPlugin)
62
- .init(Plugin => new Plugin({
63
- filename: '[path].gz[query]',
64
- algorithm: 'gzip',
65
- test: new RegExp('\\.(js|css)$'),
66
- // minimum 5K
67
- threshold: 1024 * 5,
58
+ if (!isProd) return;
59
+ config
60
+ .plugin('compression')
61
+ .use(CompressionWebpackPlugin)
62
+ .init(Plugin => new Plugin({
63
+ filename: '[path].gz[query]',
64
+ algorithm: 'gzip',
65
+ test: new RegExp('\\.(js|css)$'),
66
+ threshold: 1024 * 5,
67
+ // minimum 5K
68
68
  // minRatio: 0.6,
69
- }))
70
- .end()
71
- .plugin('analyzer')
72
- .use(BundleAnalyzerPlugin)
73
- .init(Plugin => new Plugin({
74
- reportFilename: resolve(__dirname, 'tmp/bundle-analyzer-report.html'),
75
- analyzerMode: 'static',
76
- }));
77
- }
69
+ }))
70
+ .end()
71
+ .plugin('analyzer')
72
+ .use(BundleAnalyzerPlugin)
73
+ .init(Plugin => new Plugin({
74
+ reportFilename: resolve(__dirname, 'tmp/bundle-analyzer-report.html'),
75
+ analyzerMode: 'static',
76
+ // openAnalyzer: false,
77
+ }))
78
+ .end();
78
79
  // */
79
80
  },
80
81
  };
@@ -48,7 +48,12 @@ module.exports = (() => {
48
48
  }
49
49
  });
50
50
  };
51
- findAllJsFiles(assetRoot);
51
+
52
+ try {
53
+ findAllJsFiles(assetRoot);
54
+ } catch (_e) {
55
+ //
56
+ }
52
57
 
53
58
  settings = {
54
59
  env: railsEnv,
@@ -68,6 +73,13 @@ module.exports = (() => {
68
73
  },
69
74
  },
70
75
 
76
+ jestModuleNameMapper: Object.keys(alias).reduce((obj, key) => ({
77
+ ...obj,
78
+ [`^${key.replace(/[-[{}()+.,^$#/\s\]]/g, '\\$&')}/(.*)$`]: `<rootDir>/${
79
+ alias[key].replace(/^\//, '').replace(/\/$/, '')
80
+ }/$1`,
81
+ }), {}),
82
+
71
83
  devServer,
72
84
  filenameHashing,
73
85
  lintOnSave,
@@ -84,6 +96,7 @@ module.exports = (() => {
84
96
  /* eslint-disable-next-line global-require,import/no-extraneous-dependencies */
85
97
  const { execSync } = require('child_process');
86
98
 
99
+ console.error(e);
87
100
  settings = JSON.parse(execSync('bundle exec rake vue:json_config', {
88
101
  cwd: __dirname,
89
102
  encoding: 'utf8',
@@ -95,6 +108,7 @@ module.exports = (() => {
95
108
  const v = settings[k];
96
109
  return v === undefined ? cfg : { ...cfg, [k]: v };
97
110
  }, {});
111
+ const { jestModuleNameMapper } = settings;
98
112
 
99
113
  return {
100
114
  isProd: settings.env === 'production',
@@ -108,6 +122,7 @@ module.exports = (() => {
108
122
  output: settings.manifestOutput,
109
123
  },
110
124
  },
125
+ jestModuleNameMapper,
111
126
  getSettings: (keys = Object.keys(settings)) => getSettingsFromKeys(keys),
112
127
  pickUpSettings: ([lines]) => getSettingsFromKeys(lines.split('\n').map(s => s.trim())),
113
128
  };
data/lib/tasks/vue.rake CHANGED
@@ -15,7 +15,7 @@ namespace :vue do
15
15
  task :json_config, [:from] => :environment do |_t, args|
16
16
  if args.from == 'js'
17
17
  require_relative '../helpers/lib/cmd'
18
- Cmd.run VueCli::Rails::Configuration::JS_CONFIG_CMD
18
+ Cmd.run(VueCli::Rails::Configuration::JS_CONFIG_CMD)
19
19
  else
20
20
  config = VueCli::Rails::Configuration.new
21
21
  puts config.to_json
@@ -10,7 +10,7 @@ module VueCli
10
10
  raise(Error, 'Incorrect package_manager in config/vue.yml') if @package_manager.blank?
11
11
 
12
12
  @node_env ||= NodeEnv.new do |ne|
13
- ne.use! @package_manager
13
+ ne.use!(@package_manager)
14
14
  end
15
15
  end
16
16
 
@@ -58,9 +58,16 @@ module VueCli
58
58
  pluginOptions
59
59
  ].each { |k| c[k] = config[k] if config.key?(k) }
60
60
 
61
+ jest = {}
62
+ c['jestModuleNameMapper'] = jest
61
63
  resolve_config(c, 'manifestOutput')
62
64
  config['alias']&.tap do |aliases|
63
- aliases.each_key { |k| resolve_config(aliases, k) }
65
+ aliases.each_key do |k|
66
+ key = k.gsub(%r<(?=[-{}()+.,^$#/\s\]])>, '\\')
67
+ path = aliases[k].sub(%r/^\//, '').sub(%r/\/$/, '')
68
+ jest["^#{key}/(.*)$"] = "<rootDir>/#{path}/$1"
69
+ resolve_config(aliases, k)
70
+ end
64
71
  cw['resolve']['alias'] = aliases
65
72
  end
66
73
  dev_server = c['devServer'] || {}
@@ -6,15 +6,15 @@ module VueCli
6
6
  initializer 'vue_cli' do |app|
7
7
  if ::Rails.env.development? && defined?(::Rails::Server)
8
8
  require 'vue_cli/rails/dev_server_proxy'
9
- app.middleware.insert_before 0, DevServerProxy
9
+ app.middleware.insert_before(0, DevServerProxy)
10
10
  Engine.start_wds! if ENV['NO_WEBPACK_DEV_SERVER'].blank?
11
11
  end
12
12
 
13
- ::ActiveSupport.on_load :action_controller do
14
- ::ActionController::Base.helper Helper
13
+ ::ActiveSupport.on_load(:action_controller) do
14
+ ::ActionController::Base.helper(Helper)
15
15
  end
16
16
 
17
- ::ActiveSupport.on_load :action_view do
17
+ ::ActiveSupport.on_load(:action_view) do
18
18
  include Helper
19
19
  end
20
20
  end
@@ -24,7 +24,7 @@ module VueCli
24
24
  config = Configuration.instance
25
25
  port = config['devServer']&.dig('port')
26
26
  if port
27
- running = `lsof -i:#{port} -sTCP:LISTEN -Pn`&.chop.presence&.split("\n")
27
+ running = %x`lsof -i:#{port} -sTCP:LISTEN -Pn`&.chop.presence&.split("\n")
28
28
  pid = running&.dig(1)&.split(/\s+/, 3)&.dig(1)
29
29
  Process.kill('INT', pid.to_i) if pid.present?
30
30
  end
@@ -35,14 +35,14 @@ module VueCli
35
35
  def exec(command, args = nil, extra = nil, env: {})
36
36
  cmd = COMMAND_LINE[command.to_sym] || {}
37
37
  cmd = if @pm == :yarn && cmd[:yarn]
38
- cmd[:yarn]
39
- elsif @pm == :npm && cmd[:npm]
40
- cmd[:npm]
41
- elsif cmd[:npx]
42
- @pm == :yarn ? "yarn exec #{cmd[:npx]}" : "npx #{cmd[:npx]}"
43
- else
44
- @pm == :yarn ? "yarn exec #{command}" : "npx #{command}"
45
- end
38
+ cmd[:yarn]
39
+ elsif @pm == :npm && cmd[:npm]
40
+ cmd[:npm]
41
+ elsif cmd[:npx]
42
+ @pm == :yarn ? "yarn exec #{cmd[:npx]}" : "npx #{cmd[:npx]}"
43
+ else
44
+ @pm == :yarn ? "yarn exec #{command}" : "npx #{command}"
45
+ end
46
46
 
47
47
  cmd = "#{cmd} #{args}" if args.present?
48
48
  cmd = "#{cmd} #{@pm == :yarn ? '-- ' : ''}#{extra}" if extra.present?
@@ -75,7 +75,7 @@ module VueCli
75
75
  return @versions[bin] if @versions.key?(bin)
76
76
 
77
77
  r = begin
78
- `#{bin} --version`.strip.presence
78
+ %x`#{bin} --version`.strip.presence
79
79
  rescue StandardError
80
80
  nil
81
81
  end
@@ -1,5 +1,5 @@
1
1
  module VueCli
2
2
  module Rails
3
- VERSION = '0.1.6'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
@@ -13,18 +13,18 @@ Gem::Specification.new do |spec|
13
13
  spec.license = 'MIT'
14
14
 
15
15
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
16
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ %x`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
17
  end
18
- spec.require_paths = ['lib']
18
+ spec.require_paths = %w[lib]
19
19
 
20
20
  spec.required_ruby_version = '>= 2.3'
21
21
 
22
- spec.add_dependency 'activesupport', '>= 4.2'
23
- spec.add_dependency 'rack-proxy', '>= 0.6'
24
- spec.add_dependency 'railties', '>= 4.2'
22
+ spec.add_dependency('activesupport', '>= 4.2')
23
+ spec.add_dependency('rack-proxy', '>= 0.6')
24
+ spec.add_dependency('railties', '>= 4.2')
25
25
 
26
- spec.add_development_dependency 'bundler', '~> 1.12'
27
- spec.add_development_dependency 'pry-byebug'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency('bundler', '~> 1.12')
27
+ spec.add_development_dependency('pry-byebug')
28
+ spec.add_development_dependency('rake', '~> 10.0')
29
+ spec.add_development_dependency('rspec', '~> 3.0')
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vue_cli-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-03 00:00:00.000000000 Z
11
+ date: 2019-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -124,8 +124,6 @@ files:
124
124
  - LICENSE
125
125
  - README.md
126
126
  - Rakefile
127
- - bin/console
128
- - bin/setup
129
127
  - lib/helpers/lib.rb
130
128
  - lib/helpers/lib/cmd.rb
131
129
  - lib/helpers/lib/common.rb
@@ -176,8 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
174
  - !ruby/object:Gem::Version
177
175
  version: '0'
178
176
  requirements: []
179
- rubyforge_project:
180
- rubygems_version: 2.6.14.3
177
+ rubygems_version: 3.0.2
181
178
  signing_key:
182
179
  specification_version: 4
183
180
  summary: Get vue-cli working with Rails
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'vue_cli/rails'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'pry'
14
- Pry.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here