vue_cli-rails 0.1.2 → 0.1.3
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 +4 -4
- data/README.md +5 -5
- data/lib/source/vue.config.js +4 -15
- data/lib/source/vue.rails.js +15 -0
- data/lib/source/vue.yml +1 -1
- data/lib/tasks/vue.rake +83 -17
- data/lib/vue_cli/rails/helper.rb +3 -3
- data/lib/vue_cli/rails/node_env.rb +10 -14
- data/lib/vue_cli/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a44cb706df2f61b2e5101a4a9573404f02675c9
|
4
|
+
data.tar.gz: a79ae21785870da2ccfed2d6d5a3531eb6e8d311
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9818770c03f196e790c7958ae97275078132863e47c2984d8ae55b1015b2fb220856094a8a11d0d9eba23e6a0a1e70a54deec63d30aff022adbabe6d481281e4
|
7
|
+
data.tar.gz: 490f5bc397ce60f69302a2272bcf516ecdcff0fa639c312d49ce3827bcc6481d930bdd2f10def1e1f21421608899572c8f9e9047eb8d06118640e4ccfcd62627
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# VueCli::Rails
|
2
2
|
|
3
|
-
Get `vue-cli` working on Rails
|
3
|
+
Get `vue-cli` working on Rails.
|
4
|
+
|
5
|
+
Currently, I am still actively developing this gem. It's usable but lacks of documentation. I will update it once the main features are ready and well-tested.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -15,18 +17,16 @@ And then execute:
|
|
15
17
|
$ bundle install
|
16
18
|
$ bundle exec rake vue:create
|
17
19
|
|
18
|
-
|
20
|
+
Follow the steps and copy demo codes, than you can add lines below to your `config/routes.rb`:
|
19
21
|
|
20
22
|
```ruby
|
21
23
|
get 'vue/foo' => 'vue#foo'
|
22
24
|
get 'vue/bar' => 'vue#bar'
|
23
25
|
```
|
24
26
|
|
25
|
-
> Currently `rake vue:create` will overwrite all files, please be careful!
|
26
|
-
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
This gem is fully depends on `vue-cli`. You can do
|
29
|
+
This gem is fully depends on `vue-cli`. You can do anything with [`vue.config.js`](https://cli.vuejs.org/config/) just don't break `manifest` plugin which required by `vue_cli-rails`.
|
30
30
|
|
31
31
|
When you starting `rails server` with development mode, `vue-cli-service serve` will be running at the same time.
|
32
32
|
|
data/lib/source/vue.config.js
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
// Please do NOT edit settings required by vue_cli-rails
|
2
|
-
/* [DO NOT EDIT!] begin */
|
3
|
-
const WebpackAssetsManifest = require('webpack-assets-manifest');
|
4
|
-
/* [DO NOT EDIT!] end */
|
5
|
-
|
6
1
|
// const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
7
2
|
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
8
3
|
|
@@ -13,7 +8,7 @@ const {
|
|
13
8
|
outputDir,
|
14
9
|
devServer,
|
15
10
|
publicPath,
|
16
|
-
|
11
|
+
manifest,
|
17
12
|
isProd,
|
18
13
|
} = require('./vue.rails');
|
19
14
|
|
@@ -21,6 +16,7 @@ module.exports = {
|
|
21
16
|
outputDir,
|
22
17
|
publicPath,
|
23
18
|
devServer,
|
19
|
+
css,
|
24
20
|
chainWebpack: (config) => {
|
25
21
|
config
|
26
22
|
// clear entry points if there is any
|
@@ -29,14 +25,8 @@ module.exports = {
|
|
29
25
|
.end()
|
30
26
|
/* [DO NOT EDIT!] begin */
|
31
27
|
.plugin('manifest')
|
32
|
-
.use(
|
33
|
-
.init(Plugin => new Plugin(
|
34
|
-
integrity: false,
|
35
|
-
entrypoints: true,
|
36
|
-
writeToDisk: true,
|
37
|
-
publicPath: true,
|
38
|
-
output: manifestOutput,
|
39
|
-
}))
|
28
|
+
.use(manifest.plugin)
|
29
|
+
.init(Plugin => new Plugin(manifest.options))
|
40
30
|
.end()
|
41
31
|
/* [DO NOT EDIT!] end */
|
42
32
|
.plugins
|
@@ -73,7 +63,6 @@ module.exports = {
|
|
73
63
|
*/
|
74
64
|
}
|
75
65
|
},
|
76
|
-
css,
|
77
66
|
configureWebpack: {
|
78
67
|
entry,
|
79
68
|
resolve: {
|
data/lib/source/vue.rails.js
CHANGED
@@ -4,6 +4,7 @@ module.exports = (() => {
|
|
4
4
|
let settings = {};
|
5
5
|
|
6
6
|
/* eslint-disable global-require,import/no-extraneous-dependencies */
|
7
|
+
const WebpackAssetsManifest = require('webpack-assets-manifest');
|
7
8
|
try {
|
8
9
|
const yaml = require('js-yaml');
|
9
10
|
const { readFileSync, readdirSync, lstatSync } = require('fs');
|
@@ -56,8 +57,22 @@ module.exports = (() => {
|
|
56
57
|
}
|
57
58
|
/* eslint-enable global-require,import/no-extraneous-dependencies */
|
58
59
|
|
60
|
+
const assets = {};
|
61
|
+
const manifest = {
|
62
|
+
plugin: WebpackAssetsManifest,
|
63
|
+
assets,
|
64
|
+
options: {
|
65
|
+
assets,
|
66
|
+
entrypoints: true,
|
67
|
+
writeToDisk: true,
|
68
|
+
publicPath: true,
|
69
|
+
output: settings.manifestOutput,
|
70
|
+
},
|
71
|
+
};
|
72
|
+
|
59
73
|
return {
|
60
74
|
...settings,
|
75
|
+
manifest,
|
61
76
|
isProd: settings.env === 'production',
|
62
77
|
};
|
63
78
|
})();
|
data/lib/source/vue.yml
CHANGED
data/lib/tasks/vue.rake
CHANGED
@@ -1,28 +1,94 @@
|
|
1
1
|
namespace :vue do
|
2
2
|
desc 'Run vue-cli create and regenerate configuration'
|
3
|
-
task :create
|
3
|
+
task :create do
|
4
4
|
pm = VueCli::Rails::NodeEnv.new
|
5
|
-
|
6
|
-
root = ::Rails.root
|
5
|
+
abort('Cannot find node.js') unless pm.node?
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
get_input = ->(message, list = 'Yn') {
|
8
|
+
list = list.chars
|
9
|
+
default = list.find { |c| c.upcase == c }
|
10
|
+
list = list.map { |c| c == default ? c : c.downcase }.uniq
|
11
|
+
valid = "[#{list.join('')}]"
|
12
|
+
list = list.map(&:downcase)
|
13
|
+
print "#{message} #{valid}"
|
14
|
+
loop do
|
15
|
+
r = STDIN.gets.chop.downcase
|
16
|
+
break default if r == ''
|
17
|
+
break r if list.include?(r)
|
18
|
+
print " [INVALID!] Please retry: #{valid}:"
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
# 1. package manager
|
23
|
+
yarn = pm.yarn_version
|
24
|
+
npm = pm.npm_version
|
25
|
+
if yarn
|
26
|
+
if npm
|
27
|
+
input = get_input.call('Which package manager to use (Y=Yarn, N=npm)?')
|
28
|
+
pm.use!(input == 'n' ? :npm : :yarn)
|
29
|
+
else
|
30
|
+
pm.use!(:yarn)
|
31
|
+
end
|
32
|
+
elsif npm
|
33
|
+
pm.use!(:npm)
|
34
|
+
else
|
35
|
+
abort('Cannot find npm or yarn')
|
36
|
+
end
|
37
|
+
puts "Using package manager: #{pm.package_manager}"
|
14
38
|
|
15
|
-
# dirs under `app`
|
16
39
|
src_dir = Pathname.new(__FILE__).dirname.join('..', 'source')
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
40
|
+
root = ::Rails.root
|
41
|
+
FileUtils.chdir root
|
42
|
+
|
43
|
+
# 2. vue create .
|
44
|
+
input = 'y'
|
45
|
+
pack = root.join('package.json')
|
46
|
+
if pack.exist?
|
47
|
+
puts 'Detected `package.json`!'
|
48
|
+
input = get_input.call(' Do you want to rerun `vue create?`', 'yN')
|
49
|
+
end
|
50
|
+
pm.exec('vue create', '', "-n -m #{pm.package_manager} .") if input == 'y'
|
51
|
+
|
52
|
+
# 3. dev-dependencies
|
53
|
+
package = JSON.parse(pack.read)
|
54
|
+
dev_deps = package['devDependencies']
|
55
|
+
dd = %w[webpack-assets-manifest js-yaml].find_all do |dep|
|
56
|
+
!dev_deps.key?(dep)
|
57
|
+
end
|
58
|
+
pm.add "-D #{dd.join(' ')}" if dd.any?
|
59
|
+
|
60
|
+
# 4. remove `src` folder
|
61
|
+
src = root.join('src')
|
62
|
+
if src.exist? && src.directory?
|
63
|
+
puts 'Detected `src` folder (should be generated by vue-cli)'
|
64
|
+
input = get_input.call(' Do you want to delete src folder?')
|
65
|
+
FileUtils.rm_rf root.join('src') if input == 'y'
|
66
|
+
end
|
67
|
+
|
68
|
+
# 5. copy sample codes
|
69
|
+
input = get_input.call('Do you want to copy demo code?', 'yN')
|
70
|
+
FileUtils.cp_r(src_dir.join('app'), root) if input == 'y'
|
71
|
+
|
72
|
+
# 6. config files
|
73
|
+
FileUtils.cp(src_dir.join('vue.rails.js'), "#{root}/")
|
74
|
+
input = 'y'
|
75
|
+
if root.join('vue.config.js').exist?
|
76
|
+
puts 'Detected `vue.config.js`!'
|
77
|
+
input = get_input.call(' Do you want to overwrite vue.config.js?', 'yN')
|
21
78
|
end
|
79
|
+
FileUtils.cp(src_dir.join('vue.config.js'), "#{root}/") if input == 'y'
|
22
80
|
|
23
|
-
|
24
|
-
|
25
|
-
|
81
|
+
# 7. generate config/vue.yml
|
82
|
+
yml_dest = root.join('config', 'vue.yml')
|
83
|
+
if yml_dest.exist?
|
84
|
+
puts 'Detected `config/vue.yml`!'
|
85
|
+
input = get_input.call(' Do you want to overwrite config/vue.yml?')
|
86
|
+
end
|
87
|
+
if input == 'y'
|
88
|
+
yml = src_dir.join('vue.yml').read
|
89
|
+
yml = yml.sub('#PACKAGE_MANAGER', pm.package_manager.to_s)
|
90
|
+
yml_dest.write(yml)
|
91
|
+
end
|
26
92
|
end
|
27
93
|
|
28
94
|
desc 'Add pug template support: formats=pug,sass,less,stylus'
|
data/lib/vue_cli/rails/helper.rb
CHANGED
@@ -4,14 +4,14 @@ module VueCli
|
|
4
4
|
def vue_entry(name)
|
5
5
|
@config ||= VueCli::Rails::Configuration.instance
|
6
6
|
|
7
|
-
entry = @config.manifest_data['entrypoints']
|
7
|
+
entry = (@config.manifest_data['entrypoints'] || {})[name]
|
8
8
|
return nil if entry.blank?
|
9
9
|
|
10
10
|
assets = []
|
11
|
-
entry['css']
|
11
|
+
(entry['css'] || []).each do |css|
|
12
12
|
assets << stylesheet_link_tag(css)
|
13
13
|
end
|
14
|
-
entry['js']
|
14
|
+
(entry['js'] || []).each do |js|
|
15
15
|
assets << javascript_include_tag(js)
|
16
16
|
end
|
17
17
|
|
@@ -4,29 +4,24 @@ module VueCli
|
|
4
4
|
NODE_BIN_LIST = %i[node yarn npm npx vue].freeze
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
|
8
|
-
NODE_BIN_LIST.each do |bin|
|
9
|
-
h[bin] = get_version_of(bin)
|
10
|
-
end
|
11
|
-
@versions = h
|
7
|
+
@versions = {}
|
12
8
|
yield(self) if block_given?
|
13
9
|
end
|
14
10
|
|
15
11
|
NODE_BIN_LIST.each do |bin|
|
16
12
|
define_method :"#{bin}_version" do
|
17
|
-
|
13
|
+
get_version_of(bin)
|
18
14
|
end
|
19
15
|
|
20
16
|
define_method :"#{bin}?" do
|
21
|
-
|
17
|
+
get_version_of(bin).present?
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
25
21
|
def use!(pm)
|
26
|
-
@pm =
|
27
|
-
|
28
|
-
|
29
|
-
end
|
22
|
+
@pm = pm.to_sym
|
23
|
+
raise(ArgumentError, "Unsupported manager: #{@pm}") unless %i[npm yarn].include?(@pm)
|
24
|
+
raise(VueCli::Rails::Error, "Not installed: #{@pm}") unless self.try(:"#{@pm}?")
|
30
25
|
end
|
31
26
|
|
32
27
|
def package_manager
|
@@ -65,10 +60,11 @@ module VueCli
|
|
65
60
|
private
|
66
61
|
|
67
62
|
def get_version_of(bin)
|
68
|
-
|
69
|
-
return nil if r.nil?
|
63
|
+
return @versions[bin] if @versions.key?(bin)
|
70
64
|
|
71
|
-
r
|
65
|
+
r = `#{bin} --version`.strip.presence
|
66
|
+
@versions[bin] = r && r.start_with?('v') ? r[1..-1] : r
|
67
|
+
@versions[bin]
|
72
68
|
end
|
73
69
|
|
74
70
|
def version_ge?(v1, v2)
|
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.
|
4
|
+
version: 0.1.3
|
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-02-
|
11
|
+
date: 2019-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|