vue_cli-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2601878a76dbcdb50c5cffb4264b53269d192cf1
4
+ data.tar.gz: ce5ee501f09e485ad4d37d59af2294261e4102d9
5
+ SHA512:
6
+ metadata.gz: fb4d53c1b1479d8a80a4c27debe0e7bd1c93667d3ef2ed7882a52a682fdd50bd57d2e77e3ef64e4208447e9b8eba14665897cfbbd2e5f29c616217bee287b62b
7
+ data.tar.gz: c72f12ccf709314f4a4e2885b68185d590fdc18a7bc939de2a051389f77d23aaed7133aa61a3d0b360b0f92f06477efd1847014f958c9fb4750c683028c7ae8e
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.5
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in vue_cli-rails.gemspec
6
+ gemspec
7
+
8
+ gem 'pry-byebug'
data/Gemfile.lock ADDED
@@ -0,0 +1,99 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vue_cli-rails (0.1.0)
5
+ activesupport (>= 4.2)
6
+ rack-proxy (>= 0.6)
7
+ railties (>= 4.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionpack (5.2.2)
13
+ actionview (= 5.2.2)
14
+ activesupport (= 5.2.2)
15
+ rack (~> 2.0)
16
+ rack-test (>= 0.6.3)
17
+ rails-dom-testing (~> 2.0)
18
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
+ actionview (5.2.2)
20
+ activesupport (= 5.2.2)
21
+ builder (~> 3.1)
22
+ erubi (~> 1.4)
23
+ rails-dom-testing (~> 2.0)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
25
+ activesupport (5.2.2)
26
+ concurrent-ruby (~> 1.0, >= 1.0.2)
27
+ i18n (>= 0.7, < 2)
28
+ minitest (~> 5.1)
29
+ tzinfo (~> 1.1)
30
+ builder (3.2.3)
31
+ byebug (11.0.0)
32
+ coderay (1.1.2)
33
+ concurrent-ruby (1.1.4)
34
+ crass (1.0.4)
35
+ diff-lcs (1.3)
36
+ erubi (1.8.0)
37
+ i18n (1.5.3)
38
+ concurrent-ruby (~> 1.0)
39
+ loofah (2.2.3)
40
+ crass (~> 1.0.2)
41
+ nokogiri (>= 1.5.9)
42
+ method_source (0.9.2)
43
+ mini_portile2 (2.4.0)
44
+ minitest (5.11.3)
45
+ nokogiri (1.10.1)
46
+ mini_portile2 (~> 2.4.0)
47
+ pry (0.12.2)
48
+ coderay (~> 1.1.0)
49
+ method_source (~> 0.9.0)
50
+ pry-byebug (3.7.0)
51
+ byebug (~> 11.0)
52
+ pry (~> 0.10)
53
+ rack (2.0.6)
54
+ rack-proxy (0.6.5)
55
+ rack
56
+ rack-test (1.1.0)
57
+ rack (>= 1.0, < 3)
58
+ rails-dom-testing (2.0.3)
59
+ activesupport (>= 4.2.0)
60
+ nokogiri (>= 1.6)
61
+ rails-html-sanitizer (1.0.4)
62
+ loofah (~> 2.2, >= 2.2.2)
63
+ railties (5.2.2)
64
+ actionpack (= 5.2.2)
65
+ activesupport (= 5.2.2)
66
+ method_source
67
+ rake (>= 0.8.7)
68
+ thor (>= 0.19.0, < 2.0)
69
+ rake (10.5.0)
70
+ rspec (3.8.0)
71
+ rspec-core (~> 3.8.0)
72
+ rspec-expectations (~> 3.8.0)
73
+ rspec-mocks (~> 3.8.0)
74
+ rspec-core (3.8.0)
75
+ rspec-support (~> 3.8.0)
76
+ rspec-expectations (3.8.2)
77
+ diff-lcs (>= 1.2.0, < 2.0)
78
+ rspec-support (~> 3.8.0)
79
+ rspec-mocks (3.8.0)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.8.0)
82
+ rspec-support (3.8.0)
83
+ thor (0.20.3)
84
+ thread_safe (0.3.6)
85
+ tzinfo (1.2.5)
86
+ thread_safe (~> 0.1)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ bundler (~> 1.16)
93
+ pry-byebug
94
+ rake (~> 10.0)
95
+ rspec (~> 3.0)
96
+ vue_cli-rails!
97
+
98
+ BUNDLED WITH
99
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 James
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # VueCli::Rails
2
+
3
+ Get `vue-cli` working on Rails
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Rails application's `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'vue_cli-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+ $ bundle exec rake vue:create
17
+
18
+ > Currently `rake vue:create` will overwrite all files, please be careful!
19
+
20
+ Add those lines to your `config/routes.rb`:
21
+
22
+ ```ruby
23
+ get 'vue/foo' => 'vue#foo'
24
+ get 'vue/bar' => 'vue#bar'
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ This gem is fully depends on `vue-cli`. You can do everything with [`vue.config.js`](https://cli.vuejs.org/config/) just don't break `manifest` plugin which required by `vue_cli-rails`.
30
+
31
+ When you starting `rails server` with development mode, `vue-cli-service serve` will be running at the same time.
32
+
33
+ Please use `RAILS_ENV=production` to build your production assets. `NODE_ENV` will be ignored!
34
+
35
+ You can put `app/assets/vue/manifest.dev.json` into your VCS ignore list.
36
+
37
+ ## Warning
38
+
39
+ Currently `vue.config.js` is reading configurations via `bundle exec rake vue:json_config`. You may suffer performance issue if your rake tasks are slow.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
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 ADDED
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,21 @@
1
+ <template>
2
+ <div id="app">
3
+ <slot></slot>
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ export default {
9
+ name: 'App',
10
+ };
11
+ </script>
12
+
13
+ <style>
14
+ #app {
15
+ box-sizing: border-box;
16
+ }
17
+
18
+ #app * {
19
+ box-sizing: border-box;
20
+ }
21
+ </style>
@@ -0,0 +1,9 @@
1
+ import Vue from 'vue';
2
+
3
+ import App from './App.vue';
4
+
5
+ Vue.config.productionTip = false;
6
+
7
+ export default Component => new Vue({
8
+ render: h => h(App, { scopedSlots: { default: () => h(Component) } }),
9
+ }).$mount('#app');
@@ -0,0 +1,17 @@
1
+ <template>
2
+ <div id="bar">
3
+ <h1>Bar</h1>
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ export default {
9
+ name: 'Bar',
10
+ };
11
+ </script>
12
+
13
+ <style>
14
+ #bar {
15
+ color: blue;
16
+ }
17
+ </style>
@@ -0,0 +1,17 @@
1
+ <template>
2
+ <div id="foo">
3
+ <h1>Foo</h1>
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ export default {
9
+ name: 'Foo',
10
+ };
11
+ </script>
12
+
13
+ <style>
14
+ #foo {
15
+ color: red
16
+ }
17
+ </style>
@@ -0,0 +1,4 @@
1
+ import launch from '~v-launcher';
2
+ import Bar from '~views/Bar.vue';
3
+
4
+ launch(Bar);
@@ -0,0 +1,4 @@
1
+ import launch from '~v-launcher';
2
+ import Foo from '~views/Foo.vue';
3
+
4
+ launch(Foo);
@@ -0,0 +1,9 @@
1
+ class VueController < ApplicationController
2
+ layout 'vue'
3
+
4
+ def foo
5
+ end
6
+
7
+ def bar
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Vue</title>
5
+ <%= csrf_meta_tags %>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ <%= yield %>
10
+ </body>
11
+ </html>
@@ -0,0 +1 @@
1
+ <%= vue_entry('bar') %>
@@ -0,0 +1 @@
1
+ <%= vue_entry('foo') %>
@@ -0,0 +1,95 @@
1
+ // Please do NOT edit settings required by vue_cli-rails
2
+ /* [DO NOT EDIT!] begin */
3
+ const { execSync } = require('child_process');
4
+ const { env } = require('process');
5
+ const WebpackAssetsManifest = require('webpack-assets-manifest');
6
+ /* [DO NOT EDIT!] end */
7
+
8
+ // const CompressionWebpackPlugin = require('compression-webpack-plugin');
9
+ // const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
10
+
11
+ const settings = JSON.parse(execSync('bundle exec rake vue:json_config', {
12
+ cwd: __dirname,
13
+ encoding: 'utf8',
14
+ }));
15
+ env.NODE_ENV = settings.env;
16
+ const isProd = env.NODE_ENV === 'production';
17
+
18
+ const {
19
+ entry,
20
+ css,
21
+ alias,
22
+ outputDir,
23
+ devServer,
24
+ publicPath,
25
+ manifestOutput,
26
+ } = settings;
27
+
28
+ module.exports = {
29
+ outputDir,
30
+ publicPath,
31
+ devServer,
32
+ chainWebpack: (config) => {
33
+ config
34
+ // clear entry points if there is any
35
+ .entryPoints
36
+ .clear()
37
+ .end()
38
+ /* [DO NOT EDIT!] begin */
39
+ .plugin('manifest')
40
+ .use(WebpackAssetsManifest)
41
+ .init(Plugin => new Plugin({
42
+ integrity: false,
43
+ entrypoints: true,
44
+ writeToDisk: true,
45
+ publicPath: true,
46
+ output: manifestOutput,
47
+ }))
48
+ .end()
49
+ /* [DO NOT EDIT!] end */
50
+ .plugins
51
+ // disable copy plugin
52
+ .delete('copy')
53
+ // disable generating html
54
+ .delete('html')
55
+ .delete('preload')
56
+ .delete('prefetch')
57
+ .end();
58
+ if (isProd) {
59
+ // put your custom code here
60
+ // Example: yarn -D compression-webpack-plugin webpack-bundle-analyzer
61
+ /*
62
+ config
63
+ .plugin('compression')
64
+ .use(CompressionWebpackPlugin)
65
+ .init(Plugin => new Plugin({
66
+ filename: '[path].gz[query]',
67
+ algorithm: 'gzip',
68
+ test: new RegExp('\\.(js|css)$'),
69
+ // minimum 5K
70
+ threshold: 1024 * 5,
71
+ // minRatio: 0.6,
72
+ }))
73
+ .end()
74
+ .plugin('analyzer')
75
+ .use(BundleAnalyzerPlugin)
76
+ .init(Plugin => new Plugin({
77
+ openAnalyzer: true,
78
+ reportFilename: resolve(__dirname, 'tmp/bundle-analyzer-report.html'),
79
+ analyzerMode: 'static',
80
+ }));
81
+ */
82
+ }
83
+ },
84
+ css,
85
+ configureWebpack: {
86
+ entry,
87
+ resolve: {
88
+ alias,
89
+ },
90
+ output: {
91
+ filename: '[name].[hash:8].js',
92
+ chunkFilename: 'js/[name].[hash:8].js',
93
+ },
94
+ },
95
+ };
@@ -0,0 +1,26 @@
1
+ default: &default
2
+ package_manager: #PACKAGE_MANAGER
3
+ manifestOutput: app/assets/vue/manifest.dev.json
4
+ public_output_path: vue_assets
5
+ alias:
6
+ '@': app/assets/vue
7
+ ~views: app/assets/vue/components/views
8
+ ~v-launcher: app/assets/vue/components/layouts
9
+
10
+ development:
11
+ <<: *default
12
+ devServer:
13
+ contentBase: public
14
+ host: localhost
15
+ port: 3033
16
+ compress: true
17
+ launch_node: vue-cli-service serve
18
+
19
+ test:
20
+ <<: *default
21
+
22
+ production:
23
+ <<: *default
24
+ css:
25
+ extract: true
26
+ manifestOutput: app/assets/vue/manifest.json
@@ -0,0 +1,51 @@
1
+ namespace :vue do
2
+ desc 'Run vue-cli create and regenerate configuration'
3
+ task :create, [:package_manager] do |_t, args|
4
+ pm = VueCli::Rails::NodeEnv.new
5
+ pm.use!(args.package_manager)
6
+ root = ::Rails.root
7
+
8
+ # generate config/vue.yml
9
+ FileUtils.chdir root
10
+ # `vue create .` and dependencies
11
+ pm.exec('vue create', "-n -m #{pm.package_manager} .")
12
+ pm.add '-D webpack-assets-manifest cross-env'
13
+ FileUtils.rm_rf root.join('src')
14
+
15
+ # dirs under `app`
16
+ src_dir = Pathname.new(__FILE__).dirname.join('..', 'source')
17
+ FileUtils.cp_r(src_dir.join('app'), root)
18
+ FileUtils.cp(src_dir.join('vue.config.js'), root.join('vue.config.js'))
19
+
20
+ yml = src_dir.join('vue.yml').read
21
+ yml = yml.sub('#PACKAGE_MANAGER', pm.package_manager.to_s)
22
+ root.join('config', 'vue.yml').write(yml)
23
+ end
24
+
25
+ desc 'Add pug template support: formats=pug,sass,less,stylus'
26
+ task :support, [:formats] do |_t, args|
27
+ pkgs = []
28
+ args.formats.split(/\W/).each do |fmt|
29
+ pkgs += case fmt
30
+ when 'pug'
31
+ %w[pug-plain-loader pug]
32
+ when 'sass', 'scss'
33
+ %w[sass-loader node-sass]
34
+ when 'less'
35
+ %w[less-loader less]
36
+ when 'stylus'
37
+ %w[stylus-loader stylus]
38
+ else
39
+ []
40
+ end
41
+ end
42
+ throw(StandardError, '') if pkgs.empty?
43
+ pm.add "-D #{pkgs.join(' ')}"
44
+ end
45
+
46
+ desc 'Dump config/vue.yml to_json'
47
+ task :json_config => :environment do
48
+ config = VueCli::Rails::Configuration.new
49
+ puts config.to_json
50
+ end
51
+ end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Vue</title>
5
+ <%= csrf_meta_tags %>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ <%= yield %>
10
+ </body>
11
+ </html>
@@ -0,0 +1,96 @@
1
+ module VueCli
2
+ module Rails
3
+ class Configuration
4
+ def initialize
5
+ @root = ::Rails.root
6
+ load_config(YAML.load_file(@root.join('config/vue.yml')))
7
+ end
8
+
9
+ def node_env
10
+ @node_env ||= NodeEnv.new do |ne|
11
+ ne.use! @config['package_manager']
12
+ end
13
+ end
14
+
15
+ def load_config(config)
16
+ r_env = ::Rails.env
17
+ config = config[r_env]
18
+ config['env'] = r_env
19
+ config['root'] = @root.to_s
20
+ config['entry'] = entry
21
+
22
+ public_output_path = config['public_output_path'] || 'vue_assets'
23
+ config['outputDir'] = File.join(resolve('public'), public_output_path)
24
+ config['publicPath'] = File.join('/', public_output_path, '/')
25
+ resolve_config(config, 'manifestOutput')
26
+
27
+ cfg_alias = config['alias']
28
+ cfg_alias.keys.each { |k| resolve_config(cfg_alias, k) }
29
+ dev_server = config['devServer'] || {}
30
+ resolve_config(dev_server, 'contentBase')
31
+
32
+ self.class.manifest_file = config['manifestOutput']
33
+ @config = config
34
+ end
35
+
36
+ def [](path)
37
+ @config[path]
38
+ end
39
+
40
+ def output_url_path
41
+ @config['publicPath']
42
+ end
43
+
44
+ def dev_server_host
45
+ dev_server = @config['devServer']
46
+ dev_server ? "#{dev_server['host'] || localhost}:#{dev_server['port'] || 8080}" : nil
47
+ end
48
+
49
+ def to_json
50
+ @config.to_json
51
+ end
52
+
53
+ def manifest_data
54
+ self.class.manifest.data
55
+ end
56
+
57
+ class << self
58
+ def instance
59
+ @instance ||= new
60
+ end
61
+
62
+ def manifest_file=(val)
63
+ @manifest_file = Pathname.new(val)
64
+ end
65
+
66
+ def manifest
67
+ @manifest ||= OpenStruct.new(mtime: nil, data: {})
68
+ if @manifest_file.exist? && @manifest.mtime != @manifest_file.mtime
69
+ @manifest.mtime = @manifest_file.mtime
70
+ @manifest.data = JSON.parse(@manifest_file.read)
71
+ end
72
+ @manifest
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def resolve(*path)
79
+ @root.join(*path).to_s
80
+ end
81
+
82
+ def entry
83
+ base_dir = @root.join('app/assets/vue/views')
84
+ start = base_dir.to_s.size + 1
85
+ Dir[base_dir.join('**/*.js')].each_with_object({}) do |filename, h|
86
+ h[filename[start...-3]] = filename
87
+ end
88
+ end
89
+
90
+ def resolve_config(config, key, default = nil)
91
+ path = config[key] || default
92
+ config[key] = resolve(path) if path.present?
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,25 @@
1
+ require 'rack/proxy'
2
+
3
+ module VueCli
4
+ module Rails
5
+ class DevServerProxy < ::Rack::Proxy
6
+ def initialize(app)
7
+ @app = app
8
+ config = Configuration.instance
9
+ @host = config.dev_server_host
10
+ @assets_path = config.output_url_path
11
+ end
12
+
13
+ def perform_request(env)
14
+ if env['PATH_INFO'].start_with?(@assets_path)
15
+ env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = env["HTTP_X_FORWARDED_SERVER"] = @host
16
+ env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = 'http'
17
+ env["SCRIPT_NAME"] = ''
18
+ super(env)
19
+ else
20
+ @app.call(env)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ module VueCli
2
+ module Rails
3
+ require 'vue_cli/rails/helper'
4
+ USE_PROXY_MIDDLEWARE = ::Rails.env.development? && defined?(::Rails::Server)
5
+ require 'vue_cli/rails/dev_server_proxy' if USE_PROXY_MIDDLEWARE
6
+
7
+ class Engine < ::Rails::Engine
8
+ initializer 'vue_cli' do |app|
9
+ if USE_PROXY_MIDDLEWARE
10
+ app.middleware.insert_before 0, DevServerProxy
11
+ fork do
12
+ config = Configuration.instance
13
+ config.node_env.exec(config['launch_node'] || 'vue-cli-service serve')
14
+ end
15
+ end
16
+
17
+ ::ActiveSupport.on_load :action_controller do
18
+ ::ActionController::Base.helper Helper
19
+ end
20
+
21
+ ::ActiveSupport.on_load :action_view do
22
+ include Helper
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ module VueCli
2
+ module Rails
3
+ module Helper
4
+ def vue_entry(name)
5
+ @config ||= VueCli::Rails::Configuration.instance
6
+
7
+ entry = @config.manifest_data['entrypoints']&.fetch(name)
8
+ return nil if entry.blank?
9
+
10
+ assets = []
11
+ entry['css']&.each do |css|
12
+ assets << stylesheet_link_tag(css)
13
+ end
14
+ entry['js']&.each do |js|
15
+ assets << javascript_include_tag(js)
16
+ end
17
+
18
+ assets.join('').html_safe
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,78 @@
1
+ module VueCli
2
+ module Rails
3
+ class NodeEnv
4
+ NODE_BIN_LIST = %i[node yarn npm npx vue].freeze
5
+
6
+ def initialize
7
+ h = {}
8
+ NODE_BIN_LIST.each do |bin|
9
+ h[bin] = get_version_of(bin)
10
+ end
11
+ @versions = h
12
+ yield(self) if block_given?
13
+ end
14
+
15
+ NODE_BIN_LIST.each do |bin|
16
+ define_method :"#{bin}_version" do
17
+ @versions[bin]
18
+ end
19
+
20
+ define_method :"#{bin}?" do
21
+ @versions[bin].present?
22
+ end
23
+ end
24
+
25
+ def use!(pm)
26
+ @pm = (pm || (yarn? ? 'yarn' : 'npm')).to_sym
27
+ unless (@pm == :npm || @pm == :yarn) && self.try(:"#{@pm}?")
28
+ raise(VueCli::Rails::Error, "Unknown package manager: #{@pm}")
29
+ end
30
+ end
31
+
32
+ def package_manager
33
+ @pm
34
+ end
35
+
36
+ def exec(command, args = nil)
37
+ cmd = COMMAND_LINE[command.to_sym] || {}
38
+ if @pm == :yarn && cmd[:yarn]
39
+ cmd = cmd[:yarn]
40
+ elsif @pm == :npm && cmd[:npm]
41
+ cmd = cmd[:npm]
42
+ elsif cmd[:npx]
43
+ cmd = @pm == :yarn ? "yarn exec #{cmd[:npx]}" : "npx #{cmd[:npx]}"
44
+ else
45
+ cmd = @pm == :yarn ? "yarn exec #{command}" : "npx #{command}"
46
+ end
47
+
48
+ cmd = "#{cmd} #{@pm == :yarn ? '-- ' : ''}#{args}" if args.present?
49
+ puts "run: #{cmd}"
50
+ system(cmd)
51
+ end
52
+
53
+ COMMAND_LINE = {
54
+ add: {
55
+ yarn: 'yarn add',
56
+ npm: 'npm i -S',
57
+ }
58
+ }.freeze
59
+
60
+ def method_missing(cmd, *args)
61
+ exec(cmd, *args)
62
+ end
63
+
64
+ private
65
+
66
+ def get_version_of(bin)
67
+ r = `#{bin} --version`.strip.presence
68
+ return nil if r.nil?
69
+
70
+ r.start_with?('v') ? r[1..-1] : r
71
+ end
72
+
73
+ def version_ge?(v1, v2)
74
+ Gem::Version.new(v1) >= Gem::Version.new(v2)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ module VueCli
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require "vue_cli/rails/version"
2
+ require 'vue_cli/rails/configuration'
3
+ require 'vue_cli/rails/node_env'
4
+
5
+ require 'vue_cli/rails/engine' if defined? Rails
6
+
7
+ module VueCli
8
+ module Rails
9
+ class Error < StandardError; end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "vue_cli/rails/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vue_cli-rails"
8
+ spec.version = VueCli::Rails::VERSION
9
+ spec.authors = ["James Chen"]
10
+ spec.email = ["egustc@gmail.com"]
11
+
12
+ spec.summary = %q{Get vue-cli working with Rails}
13
+ spec.homepage = "https://github.com/eGust/vue_cli-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = ">= 2.2"
22
+
23
+ spec.add_dependency "activesupport", "~> 4.2"
24
+ spec.add_dependency "railties", "~> 4.2"
25
+ spec.add_dependency "rack-proxy", "~> 0.6"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.12"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vue_cli-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Chen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-proxy
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description:
98
+ email:
99
+ - egustc@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/source/app/assets/vue/components/layouts/App.vue
115
+ - lib/source/app/assets/vue/components/layouts/index.js
116
+ - lib/source/app/assets/vue/components/views/Bar.vue
117
+ - lib/source/app/assets/vue/components/views/Foo.vue
118
+ - lib/source/app/assets/vue/views/bar.js
119
+ - lib/source/app/assets/vue/views/foo.js
120
+ - lib/source/app/controllers/vue_controller.rb
121
+ - lib/source/app/views/layouts/vue.html.erb
122
+ - lib/source/app/views/vue/bar.html.erb
123
+ - lib/source/app/views/vue/foo.html.erb
124
+ - lib/source/vue.config.js
125
+ - lib/source/vue.yml
126
+ - lib/tasks/vue.rake
127
+ - lib/views/layouts/vue.erb
128
+ - lib/vue_cli/rails.rb
129
+ - lib/vue_cli/rails/configuration.rb
130
+ - lib/vue_cli/rails/dev_server_proxy.rb
131
+ - lib/vue_cli/rails/engine.rb
132
+ - lib/vue_cli/rails/helper.rb
133
+ - lib/vue_cli/rails/node_env.rb
134
+ - lib/vue_cli/rails/version.rb
135
+ - vue_cli-rails.gemspec
136
+ homepage: https://github.com/eGust/vue_cli-rails
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '2.2'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.6.14.3
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Get vue-cli working with Rails
160
+ test_files: []