vue_cli-rails 0.4.0 → 0.4.1

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
2
  SHA256:
3
- metadata.gz: 106196baec28c9e822399c81c0aaa74e3ebc975ed6058ab4526bbd7afed75a9f
4
- data.tar.gz: 3759ecd67ae31aac6c0cba11c779e7b2c2b43a3c4a1faa27b751d54b5b7066d3
3
+ metadata.gz: d94627f882ae1d49750c10af029d0198758192e2a1c48a28d3acb03d390191e9
4
+ data.tar.gz: f91614fdaa017c41077bb29fc18990d6032d236ca815fa72bafacac16b8c86de
5
5
  SHA512:
6
- metadata.gz: 1f96e3c8b417e714682deda2cfea327658326d1030ead03cc724b3e7d4544ba9813dcc6652196252cdebceb9a3cf90e1130f004770b9b8a3d8c0c76d97e93cb2
7
- data.tar.gz: 9a161f5257422c9a07b8a86430bcc2d0c3860e43a39925cb100e7fb7f5eb03df85d7e607324efe00fdc02de1b39c96bbc10ff1006e65de65d9a6a2e21ba23450
6
+ metadata.gz: 99c4c3dc1c9141ad7a58879b42a70ebefa9cd53e64c822bbfea7af4d270dc39bebf75065e5977c9e5d2e116042c2e4301c3666b19098a29f36112007cd895c07
7
+ data.tar.gz: 9de90b5be774639d27c19753ffa2d4b0dd1a0dc9a7dd98752ce5700170a47bb8899a49d2525653261d3940cb507fd27e87e9ff12beb17724df561b844aabab66
data/.gitignore CHANGED
@@ -6,6 +6,8 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ node_modules
10
+ /test/vcdr
9
11
 
10
12
  # rspec failure tracking
11
13
  .rspec_status
data/.travis.yml CHANGED
@@ -1,7 +1,49 @@
1
1
  ---
2
2
  sudo: false
3
3
  language: ruby
4
- cache: bundler
4
+ cache:
5
+ bundler: true
6
+ yarn: true
7
+
5
8
  rvm:
6
- - 2.4.5
7
- before_install: gem install bundler -v 1.17.3
9
+ - 2.3
10
+ - 2.4
11
+ - 2.5
12
+
13
+ env:
14
+ - RAILS_VERSION=4.2
15
+ - RAILS_VERSION=5.2
16
+
17
+ matrix:
18
+ exclude:
19
+ - rvm: 2.5
20
+ env: RAILS_VERSION=4.2
21
+
22
+ gemfile:
23
+ - test/Gemfile-rails.$RAILS_VERSION
24
+
25
+ before_install:
26
+ - gem update --system
27
+
28
+ install:
29
+ - nvm install --lts
30
+ - node -v
31
+ - yarn global add @vue/cli
32
+ - gem install rspec
33
+
34
+ before_script:
35
+ - sh -c 'cd test && ./install.rb'
36
+
37
+ script:
38
+ - sh -c 'cd test && rspec ./vcr_spec.rb'
39
+
40
+ jobs:
41
+ include:
42
+ - stage: gem release
43
+ rvm: 2.3
44
+ script: echo "Deploying to rubygems.org ..."
45
+ deploy:
46
+ provider: rubygems
47
+ gem: vue_cli-rails
48
+ api_key: $RUBYGEMS_API_KEY
49
+ on: release
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## [0.4.1] - Released on 2019-03-18
4
+
5
+ - Better hint than crashing when run Rails server with `vue_cli-rails` but `rake vue:create` have not been called
6
+ - Keep settings of `vue.config.js` like `lintOnSave` generated by Vue
7
+ - Added tasks `vue:lint`, `vue:test[unit]` and `vue:test[e2e]`
8
+ - Added travis tests
9
+
3
10
  ## [0.4.0] - Released on 2019-03-17
4
11
 
5
12
  - Breaking change: changed `render_vue(entry_point)` to `render(vue: entry_point)`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vue_cli-rails (0.4.0)
4
+ vue_cli-rails (0.4.1)
5
5
  activesupport (>= 4.2)
6
6
  rack-proxy (>= 0.6)
7
7
  railties (>= 4.2)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # VueCli::Rails
2
2
 
3
+ [![Build Status](https://travis-ci.com/eGust/vue_cli-rails.svg?branch=master)](https://travis-ci.com/eGust/vue_cli-rails)
4
+
3
5
  Let's make cool boy Vue even cooler on Rails!
4
6
 
5
7
  ## Installation
@@ -21,8 +23,6 @@ And then execute:
21
23
  - Node >= [8.9+](https://cli.vuejs.org/guide/installation.html)
22
24
  - Optional: `yarn`
23
25
 
24
- > The auto-testing for CI still WIP. Sorry I can't guarantee it works for now.
25
-
26
26
  ## Features
27
27
 
28
28
  - Feel free to use `yarn` or `npm`.
@@ -357,7 +357,7 @@ You can check the full list on [Vue CLI official website](https://cli.vuejs.org/
357
357
  - [ ] integrity - N/A
358
358
  - [ ] chainWebpack - directly edit `vue.config.js`
359
359
 
360
- ## Trouble-shooting
360
+ ## Trouble Shooting & Known Issues
361
361
 
362
362
  - My dev server can't find assets
363
363
 
@@ -413,6 +413,22 @@ You can check the full list on [Vue CLI official website](https://cli.vuejs.org/
413
413
 
414
414
  Alternatively you can turn off CSRF token and set [SameSite cookie](https://gist.github.com/will/05cb64dc343296dec4d58b1abbab7aaf) if all your clients no longer use IE. [Modern browsers](https://caniuse.com/#feat=same-site-cookie-attribute) can handle `SameSite` flag to [prevent CSRF attacks](http://www.sjoerdlangkemper.nl/2016/04/14/preventing-csrf-with-samesite-cookie-attribute/).
415
415
 
416
+ - Mocha tests not working
417
+
418
+ This is an known issue.
419
+
420
+ - TypeScript can not find my aliases
421
+
422
+ This is an known issue. TS is still using `tsconfig.json` rather than a `.js` or `.ts` file. You must manually update it for now. I will try to find a way out.
423
+
424
+ - My `yarn test:...`/`npm run test:...` not working properly
425
+
426
+ The test requires setting `RAILS_ENV=test`. You can invoke `rake vue:test[unit]` `rake vue:test[e2e]` instead.
427
+
428
+ - Got errors like `command "..." does not exist` for `rake vue:lint/test`
429
+
430
+ This rake task simply invokes `vue-cli-service test:...`. Those commands will be generated by some vue plugins. It won't be available unless you got correct plugin installed.
431
+
416
432
  <details><summary>Q & A</summary>
417
433
 
418
434
  ## Q&A
@@ -17,6 +17,7 @@ class VueCreate
17
17
  check_node!
18
18
  FileUtils.chdir(@root)
19
19
  @pending_install = false
20
+ @pending_fixes = []
20
21
  begin
21
22
  package_manager?
22
23
  install_vue_cli
@@ -29,6 +30,7 @@ class VueCreate
29
30
  generate_vue_yml
30
31
  ensure_entry_point!
31
32
  fix_jest_config!
33
+ eslint_fix!
32
34
  puts 'vue:create finished!'
33
35
  ensure
34
36
  FileUtils.chdir(@pwd)
@@ -195,11 +197,22 @@ class VueCreate
195
197
  def copy_config
196
198
  puts 'Copying configuration files...'
197
199
  FileUtils.cp(@src_dir.join('vue.rails.js'), "#{@root}/")
198
- if @root.join('vue.config.js').exist?
199
- puts 'Detected `vue.config.js`!'
200
- return if @input.gets(' Do you want to overwrite vue.config.js?', 'yN') == 'n'
200
+
201
+ src_cfg = @src_dir.join('vue.config.js')
202
+ dst_cfg = @root.join('vue.config.js')
203
+ config = src_cfg.read
204
+ if dst_cfg.exist?
205
+ if dst_cfg.size > 500
206
+ puts 'Detected `vue.config.js`!'
207
+ return if @input.gets(' Do you want to overwrite vue.config.js?', 'yN') == 'n'
208
+ else
209
+ old_cfg = %x`node -e "console.log(JSON.stringify(require('./vue.config.js'),null,2))"`
210
+ config = config.sub('const oldConfig = {};', "const oldConfig = #{old_cfg};")
211
+ end
201
212
  end
202
- FileUtils.cp(@src_dir.join('vue.config.js'), "#{@root}/")
213
+
214
+ dst_cfg.write(config)
215
+ @pending_fixes << dst_cfg.to_s
203
216
  end
204
217
 
205
218
  def generate_vue_yml
@@ -242,10 +255,15 @@ class VueCreate
242
255
  module.exports = #{JSON.pretty_generate(jest_config)}_MODULE_NAME_MAPPER_;
243
256
  JS
244
257
  jest_file.write(jest.sub(/\n?}_MODULE_NAME_MAPPER_/, ",\n moduleNameMapper\n}"))
258
+ @pending_fixes << jest_file.to_s
259
+ rescue => e
260
+ STDERR.puts e.message
261
+ end
245
262
 
263
+ def eslint_fix!
246
264
  dev_deps = JSON.parse(@pack.read)['devDependencies']
247
265
  return unless dev_deps['eslint'].present?
248
- @pm.exec('eslint', jest_file.to_s, '--fix')
266
+ @pm.exec('eslint', @pending_fixes.map { |fn| "'#{fn}'" }.join(' '), '--fix')
249
267
  rescue => e
250
268
  STDERR.puts e.message
251
269
  end
@@ -5,13 +5,17 @@
5
5
  const railsConfig = require('./vue.rails');
6
6
 
7
7
  const {
8
+ mode,
8
9
  manifest,
9
10
  pickUpSettings,
10
11
  // isProd,
11
12
  // getSettings, // (keys: string[]) => Object. Returns all available settings by default
12
13
  } = railsConfig;
13
14
 
15
+ const oldConfig = {};
16
+
14
17
  module.exports = {
18
+ ...oldConfig,
15
19
  ...pickUpSettings`
16
20
  outputDir
17
21
  publicPath
@@ -35,21 +39,24 @@ module.exports = {
35
39
  // clear entry points if there is any
36
40
  .entryPoints
37
41
  .clear()
38
- .end()
39
- .plugins
40
- // disable copy plugin
41
- .delete('copy')
42
- // disable generating html
43
- .delete('html')
44
- .delete('preload')
45
- .delete('prefetch')
46
42
  .end();
47
- if (manifest) {
43
+ if (mode !== 'test') {
48
44
  config
49
- .plugin('manifest')
50
- .use(manifest.plugin)
51
- .init(Plugin => new Plugin(manifest.options))
45
+ .plugins
46
+ // disable copy plugin
47
+ .delete('copy')
48
+ // disable generating html
49
+ .delete('html')
50
+ .delete('preload')
51
+ .delete('prefetch')
52
52
  .end();
53
+ if (manifest) {
54
+ config
55
+ .plugin('manifest')
56
+ .use(manifest.plugin)
57
+ .init(Plugin => new Plugin(manifest.options))
58
+ .end();
59
+ }
53
60
  }
54
61
  /* [DO NOT EDIT!] end */
55
62
 
@@ -44,14 +44,16 @@ module.exports = (() => {
44
44
  },
45
45
  };
46
46
 
47
+ const mode = env.RAILS_ENV || env.NODE_ENV || 'development';
48
+ env.RAILS_ENV = mode;
49
+ env.NODE_ENV = mode;
47
50
  try {
48
51
  /* eslint-disable global-require,import/no-extraneous-dependencies */
49
52
  const yaml = require('js-yaml');
50
53
  const { readdirSync, lstatSync } = require('fs');
51
54
  /* eslint-enable global-require,import/no-extraneous-dependencies */
52
55
 
53
- const railsEnv = env.RAILS_ENV || 'development';
54
- const config = yaml.safeLoad(readFileSync(resolve('config', 'vue.yml'), 'utf8'))[railsEnv];
56
+ const config = yaml.safeLoad(readFileSync(resolve('config', 'vue.yml'), 'utf8'))[mode];
55
57
  const root = resolve(__dirname);
56
58
  const pop = (config.public_output_path || 'vue_assets').replace(/(^\/+|\/+$)/g, '');
57
59
  const {
@@ -96,7 +98,7 @@ module.exports = (() => {
96
98
  }
97
99
 
98
100
  settings = {
99
- env: railsEnv,
101
+ env: mode,
100
102
  root,
101
103
  manifestOutput: manifestOutput && resolve(root, manifestOutput),
102
104
 
@@ -145,7 +147,7 @@ module.exports = (() => {
145
147
  /* eslint-disable-next-line global-require,import/no-extraneous-dependencies */
146
148
  const { execSync } = require('child_process');
147
149
 
148
- console.error(e);
150
+ console.error(mode, e);
149
151
  settings = JSON.parse(execSync('bundle exec rake vue:json_config', {
150
152
  cwd: __dirname,
151
153
  encoding: 'utf8',
@@ -165,6 +167,7 @@ module.exports = (() => {
165
167
  const isProd = settings.env === 'production';
166
168
 
167
169
  return {
170
+ mode,
168
171
  isProd,
169
172
  manifest: {
170
173
  /* eslint-disable-next-line global-require,import/no-extraneous-dependencies */
data/lib/tasks/vue.rake CHANGED
@@ -29,6 +29,20 @@ namespace :vue do
29
29
  ::Rake::Task['assets:precompile'].invoke if args.with_rails_assets
30
30
  end
31
31
 
32
+ desc 'Run JavaScript Lint: alias of vue-cli-service lint'
33
+ task :lint do
34
+ VueCli::Rails::Configuration.instance.node_env.exec('vue-cli-service lint')
35
+ end
36
+
37
+ desc 'Run JavaScript unit or e2e tests (default unit-test)'
38
+ task :test, [:unit_e2e] => :environment do |_t, args|
39
+ test = (args.unit_e2e || 'unit').downcase
40
+ abort('Only support test[unit] or test[e2e]') unless %w[unit e2e].include?(test)
41
+ STDERR.puts('WARN: Mocha and E2E tests may not work properly.')
42
+ VueCli::Rails::Configuration.instance.node_env
43
+ .exec("vue-cli-service test:#{test}", env: { 'RAILS_ENV' => 'test' })
44
+ end
45
+
32
46
  desc 'Install Node way to run Rails dev server alongside webpack-dev-server'
33
47
  task node_dev: :environment do
34
48
  require_relative '../helpers/scripts/vue_command'
@@ -103,6 +103,16 @@ module VueCli
103
103
  class << self
104
104
  attr_reader :dev_server_url, :entry_points
105
105
 
106
+ def check!
107
+ return if ::Rails.root.join('config/vue.yml').exist?
108
+ abort <<~ERROR
109
+ [ERROR] Failed to load vue_cli-rails!
110
+ Cannot find config file: config/vue.yml
111
+ Please call below command to initialize Vue:
112
+ #{::Rails.version.to_i > 4 ? 'rails' : 'bundle exec rake'} vue:create
113
+ ERROR
114
+ end
115
+
106
116
  def instance
107
117
  @instance ||= new
108
118
  end
@@ -5,6 +5,7 @@ module VueCli
5
5
  class Engine < ::Rails::Engine
6
6
  initializer 'vue_cli' do |app|
7
7
  if defined?(::Rails::Server)
8
+ Configuration.check!
8
9
  is_dev = ::Rails.env.development?
9
10
 
10
11
  if is_dev
@@ -1,5 +1,5 @@
1
1
  module VueCli
2
2
  module Rails
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.4.1'.freeze
4
4
  end
5
5
  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.4.0
4
+ version: 0.4.1
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-16 00:00:00.000000000 Z
11
+ date: 2019-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -129,7 +129,6 @@ files:
129
129
  - lib/helpers/lib/cmd.rb
130
130
  - lib/helpers/lib/common.rb
131
131
  - lib/helpers/lib/input_loop.rb
132
- - lib/helpers/scripts/install_rails.rb
133
132
  - lib/helpers/scripts/vue_command.rb
134
133
  - lib/helpers/scripts/vue_create.rb
135
134
  - lib/source/app/assets/vue/components/HelloWorld.vue
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require_relative 'common'
3
-
4
- ver = ENV['RAILS_VERSION']
5
- abort('RAILS_VERSION not found!') if ver.blank?
6
-
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
- abort("Version #{ver} not found!") if ver.blank?
10
-
11
- run("gem install rails -v #{ver}")
12
-
13
- RAILS_NEW_SCRIPT = {
14
- '5' => {
15
- args: %w[
16
- database=sqlite3
17
- skip-yarn
18
- skip-git
19
- skip-keeps
20
- skip-sprockets
21
- skip-spring
22
- skip-listen
23
- skip-turbolinks
24
- skip-javascript
25
- skip-test
26
- skip-bundle
27
- ],
28
- keep_gems: /^\s*gem\s+['"](rails|puma|bootsnap)/,
29
- append: "gem 'sqlite3', '~> 1.3.10'",
30
- },
31
- }
32
-
33
- require 'pathname'
34
- require 'fileutils'
35
-
36
- scirpt = RAILS_NEW_SCRIPT[ver[0]]
37
- run("rails new test_vcr #{scirpt[:args].map { |a| "--#{a}" }.join(' ')}")
38
- FileUtils.chdir('test_vcr')
39
-
40
- root = Pathname.new(FileUtils.pwd)
41
- gemfile = root.join('Gemfile').read.split("\n")
42
- .reject(&:empty?).reject { |s| s =~ /^\s*#/ }
43
- .reject { |s| s =~ /^\s*gem/ && s !~ scirpt[:keep_gems] }
44
- root.join('Gemfile').write("#{(gemfile + [scirpt[:append]]).join("\n")}\n")
45
- run('bundle install')