vueapp 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +43 -0
  4. data/bin/console +14 -0
  5. data/bin/setup +8 -0
  6. data/bin/vueapp +7 -0
  7. data/lib/vueapp.rb +32 -0
  8. data/lib/vueapp/cli.rb +44 -0
  9. data/lib/vueapp/core/builder.rb +37 -0
  10. data/lib/vueapp/core/builders/js_builder.rb +140 -0
  11. data/lib/vueapp/core/builders/scss_builder.rb +114 -0
  12. data/lib/vueapp/core/builders/slim_builder.rb +94 -0
  13. data/lib/vueapp/core/cli/build_helper.rb +20 -0
  14. data/lib/vueapp/core/cli/generator_helper.rb +23 -0
  15. data/lib/vueapp/core/cli/init_helper.rb +81 -0
  16. data/lib/vueapp/core/helpers/build.rb +22 -0
  17. data/lib/vueapp/core/helpers/env.rb +47 -0
  18. data/lib/vueapp/core/helpers/log.rb +16 -0
  19. data/lib/vueapp/core/helpers/path.rb +49 -0
  20. data/lib/vueapp/core/helpers/timer.rb +19 -0
  21. data/lib/vueapp/core/listener.rb +64 -0
  22. data/lib/vueapp/errors.rb +8 -0
  23. data/lib/vueapp/templates/_core/vendor/vue.dev.js +11965 -0
  24. data/lib/vueapp/templates/_core/vendor/vue.js +6 -0
  25. data/lib/vueapp/templates/_core/vendor/vue_router.js +3061 -0
  26. data/lib/vueapp/templates/api/api.js +3 -0
  27. data/lib/vueapp/templates/api/api_client.js +131 -0
  28. data/lib/vueapp/templates/api/base_api.js +27 -0
  29. data/lib/vueapp/templates/config/app.js +17 -0
  30. data/lib/vueapp/templates/config/router.js +7 -0
  31. data/lib/vueapp/templates/config/routes.js +10 -0
  32. data/lib/vueapp/templates/filters/percentage.js +7 -0
  33. data/lib/vueapp/templates/generators/component/new.js +3 -0
  34. data/lib/vueapp/templates/generators/component/new.scss +0 -0
  35. data/lib/vueapp/templates/generators/component/new.slim +2 -0
  36. data/lib/vueapp/templates/index.slim +24 -0
  37. data/lib/vueapp/templates/mixins/base.js +10 -0
  38. data/lib/vueapp/templates/pages/about_us/about_us.js +3 -0
  39. data/lib/vueapp/templates/pages/about_us/about_us.scss +0 -0
  40. data/lib/vueapp/templates/pages/about_us/about_us.slim +2 -0
  41. data/lib/vueapp/templates/pages/home/home.js +3 -0
  42. data/lib/vueapp/templates/pages/home/home.scss +0 -0
  43. data/lib/vueapp/templates/pages/home/home.slim +2 -0
  44. data/lib/vueapp/templates/styles.scss +1 -0
  45. data/lib/vueapp/version.rb +5 -0
  46. metadata +228 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 89fa66cbadc0079c8a6f213a69e4c40916fbf809e9899ea3ea1fa2d26abf8fb0
4
+ data.tar.gz: 619861d88d86759113150d224597f16c66b85956d0ff8766c12a659349d311c0
5
+ SHA512:
6
+ metadata.gz: af239bb1dc207e051f3d066d100d081e70c9e20140c609d4987c13631e1c307f95ed42def18fac1427fccc1ee86142018bf938a6c0aa299f9a9aa8208de2eca5
7
+ data.tar.gz: 7fee5a1c81e9137de201ef11c9f3cf77283f0f0854f1ee02d68dc58e56cffa15782aa0c1fcbdc47e1c92dc67a5435383bace0cd81c20fd0b0ff7a77285f2389a
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 BitForge
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # VueApp
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/only/vue`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vueapp'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vueapp
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/only-vue. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Only::Vue project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/only-vue/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'vueapp'
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 'irb'
14
+ IRB.start(__FILE__)
@@ -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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require 'vueapp'
6
+
7
+ VueApp::CLI.start(ARGV)
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ require 'thor'
6
+ require 'listen'
7
+ require 'sassc'
8
+ require 'slim'
9
+ require 'uglifier'
10
+ require 'concolor'
11
+
12
+ require 'vueapp/version'
13
+ require 'vueapp/errors'
14
+ require 'vueapp/core/helpers/log'
15
+ require 'vueapp/core/helpers/env'
16
+ require 'vueapp/core/helpers/timer'
17
+ require 'vueapp/core/helpers/path'
18
+ require 'vueapp/core/helpers/build'
19
+ require 'vueapp/core/cli/init_helper'
20
+ require 'vueapp/core/cli/build_helper'
21
+ require 'vueapp/core/cli/generator_helper'
22
+ require 'vueapp/core/builder'
23
+ require 'vueapp/core/builders/js_builder'
24
+ require 'vueapp/core/builders/scss_builder'
25
+ require 'vueapp/core/builders/slim_builder'
26
+ require 'vueapp/core/listener'
27
+ # require 'vueapp/cli'
28
+
29
+ # Base module
30
+ module VueApp
31
+ autoload :CLI, 'vueapp/cli'
32
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VueApp
4
+ # Console client for vueapp
5
+ class CLI < Thor
6
+ include Thor::Actions
7
+ include VueApp::Core::CLI::InitHelper
8
+ include VueApp::Core::CLI::BuildHelper
9
+ include VueApp::Core::CLI::GeneratorHelper
10
+
11
+ no_commands do
12
+ # Define source paths
13
+ def source_paths
14
+ ["#{__dir__}/templates"]
15
+ end
16
+ end
17
+
18
+ desc 'init', 'initialize [VUEAPP] in current folder'
19
+ def init
20
+ run_init
21
+ end
22
+
23
+ desc 'dev', 'run rebuild tool'
24
+ def dev
25
+ VueApp::Core::Builder.build(:development)
26
+ VueApp::Core::Listener.call
27
+ end
28
+
29
+ desc 'build [env]', 'build vueapp'
30
+ def build(env = 'development')
31
+ run_build(env&.to_sym)
32
+ end
33
+
34
+ desc 'g [type] [name]', 'generate'
35
+ def g(type, name)
36
+ case type
37
+ when 'component'
38
+ generate_component(name)
39
+ else
40
+ help
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VueApp
4
+ module Core
5
+ # Base Vue app builder
6
+ class Builder
7
+ include VueApp::Core::Helpers::Env
8
+ include VueApp::Core::Helpers::Log
9
+ include VueApp::Core::Helpers::Timer
10
+
11
+ # Create a builder for a specific environment
12
+ # @param [Symbol] env
13
+ # @raise [VueApp::Errors::InvalidENV]
14
+ def initialize(env = :development)
15
+ init_env(env)
16
+ @js_builder = VueApp::Core::Builders::JsBuilder.new(env)
17
+ @scss_builder = VueApp::Core::Builders::ScssBuilder.new(env)
18
+ @slim_builder = VueApp::Core::Builders::SlimBuilder.new(env)
19
+ end
20
+
21
+ # Build [VUEAPP] use [@env]
22
+ def build
23
+ timer_block "Start [#{@env}] build", 'End build: ' do
24
+ @js_builder.build
25
+ @scss_builder.build
26
+ @slim_builder.build
27
+ end
28
+ end
29
+
30
+ # Base method for build Vue app
31
+ # @param [Symbol] env
32
+ def self.build(env)
33
+ Builder.new(env).build
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VueApp
4
+ module Core
5
+ module Builders
6
+ # Build one javascript file
7
+ class JsBuilder
8
+ include VueApp::Core::Helpers::Env
9
+ include VueApp::Core::Helpers::Log
10
+ include VueApp::Core::Helpers::Timer
11
+ include VueApp::Core::Helpers::Path
12
+ include VueApp::Core::Helpers::Build
13
+
14
+ # Create a JS builder for a specific environment
15
+ # @param [Symbol] env
16
+ # @raise [VueApp::Errors::InvalidENV]
17
+ def initialize(env = :development)
18
+ init_env(env)
19
+ end
20
+
21
+ private
22
+
23
+ # Build dev js file
24
+ def build_dev
25
+ timer_block(
26
+ 'Start [development] build for *.js files',
27
+ 'JS time: ') do
28
+ all_js_into_one_file
29
+ end
30
+ end
31
+
32
+ def build_production
33
+ timer_block(
34
+ 'Start [production] build for *.js files',
35
+ 'JS time: ') do
36
+ all_js_into_one_file
37
+ compress_min_js
38
+ end
39
+ end
40
+
41
+ # Vue.js
42
+ def vue_js
43
+ if development?
44
+ src_vendor_path.join('vue.dev.js').to_s
45
+ else
46
+ src_vendor_path.join('vue.js').to_s
47
+ end
48
+ end
49
+
50
+ # Vue.js and required libs
51
+ # @return [Array<String>]
52
+ def vue_lib_js
53
+ [vue_js, src_vendor_path.join('vue_router.js').to_s]
54
+ end
55
+
56
+ # All *.js files from [mixins] folder
57
+ # @return [Array<String>]
58
+ def mixins_js
59
+ Dir[src_path.join('mixins', '**', '*.js').to_s]
60
+ end
61
+
62
+ # All *.js files from [filters] folder
63
+ # @return [Array<String>]
64
+ def filters_js
65
+ Dir[src_path.join('filters', '**', '*.js').to_s]
66
+ end
67
+
68
+ # All *.js files from [components] folder
69
+ # @return [Array<String>]
70
+ def components_js
71
+ Dir[src_path.join('components', '**', '*.js').to_s]
72
+ end
73
+
74
+ # All *.js files from [pages] folder
75
+ # @return [Array<String>]
76
+ def pages_js
77
+ Dir[src_path.join('pages', '**', '*.js').to_s]
78
+ end
79
+
80
+ # All *.js files from [config] folder
81
+ # @return [Array<String>]
82
+ def config_js
83
+ [
84
+ src_config_path.join('routes.js').to_s,
85
+ src_config_path.join('router.js').to_s,
86
+ src_config_path.join('app.js').to_s
87
+ ]
88
+ end
89
+
90
+ # Get all [*.js] file in the app path (ordered)
91
+ # @return [Array<String>] all [*.js] files
92
+ def js_files
93
+ [
94
+ vue_lib_js, mixins_js, filters_js, components_js,
95
+ pages_js, config_js
96
+ ].flatten!
97
+ end
98
+
99
+ # Base js filename
100
+ # @return [Pathname]
101
+ def base_js_file
102
+ build_path.join('scripts.js')
103
+ end
104
+
105
+ # Minified base js filename
106
+ # @return [Pathname]
107
+ def min_js_file
108
+ build_path.join('scripts.min.js')
109
+ end
110
+
111
+ # Get compressor object
112
+ # @return [Uglifier]
113
+ def compressor
114
+ Uglifier.new(harmony: true)
115
+ end
116
+
117
+ # Merge all *.js files into one file
118
+ def all_js_into_one_file
119
+ File.open(base_js_file, 'w') do |file|
120
+ js_files.each do |js_file|
121
+ file.write('/* file: ' + js_file + " */\n") if development?
122
+ file.write(File.read(js_file))
123
+ end
124
+ end
125
+ end
126
+
127
+ # Compress and minify js file
128
+ def compress_min_js
129
+ File.open(min_js_file, 'w') do |file|
130
+ file.write(
131
+ compressor.compile(File.read(base_js_file))
132
+ )
133
+ end
134
+ FileUtils.mv(min_js_file, base_js_file)
135
+ FileUtils.remove_file(min_js_file, true)
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VueApp
4
+ module Core
5
+ module Builders
6
+ # SCSS builder
7
+ class ScssBuilder < VueApp::Core::Builder
8
+ include VueApp::Core::Helpers::Env
9
+ include VueApp::Core::Helpers::Timer
10
+ include VueApp::Core::Helpers::Path
11
+ include VueApp::Core::Helpers::Build
12
+
13
+ # Create a SCSS builder for a specific environment
14
+ # @param [Symbol] env
15
+ # @raise [VueApp::Errors::InvalidENV]
16
+ def initialize(env = :development)
17
+ init_env(env)
18
+ end
19
+
20
+ private
21
+
22
+ def build_dev
23
+ timer_block(
24
+ 'Start [development] build for *.scss files',
25
+ 'CSS time: ') do
26
+ all_scss_into_one_file
27
+ compress_css
28
+ end
29
+ end
30
+
31
+ def build_production
32
+ timer_block(
33
+ 'Start [production] build for *.scss files',
34
+ 'CSS time: ') do
35
+ all_scss_into_one_file
36
+ compress_min_css
37
+ end
38
+ end
39
+
40
+ # Base css filename
41
+ # @return [Pathname]
42
+ def base_css_file
43
+ build_path.join('styles.css')
44
+ end
45
+
46
+ # Base scss filename
47
+ # @return [Pathname]
48
+ def base_scss_file
49
+ build_path.join('styles.scss')
50
+ end
51
+
52
+ # Base scss file
53
+ # @return [String]
54
+ def styles_scss
55
+ src_path.join('styles.scss').to_s
56
+ end
57
+
58
+ # All *.scss files from [components] folder
59
+ # @return [Array<String>] all [*.scss] files
60
+ def components_scss
61
+ Dir[src_path.join('components', '**', '*.scss').to_s]
62
+ end
63
+
64
+ # All *.scss files from [pages] folder
65
+ # @return [Array<String>] all [*.scss] files
66
+ def pages_scss
67
+ Dir[src_path.join('pages', '**', '*.scss').to_s]
68
+ end
69
+
70
+ # Get all [*.scss] file in the app path
71
+ # @return [Array<String>] all [*.scss] files
72
+ def sass_files
73
+ [
74
+ styles_scss, components_scss, pages_scss
75
+ ].flatten!
76
+ end
77
+
78
+ # Merge all *.scss files into one file
79
+ def all_scss_into_one_file
80
+ File.open(base_scss_file, 'w') do |file|
81
+ sass_files.each do |sass_file|
82
+ file.write("/* file: #{sass_file} */\n") if development?
83
+ file.write(File.read(sass_file))
84
+ end
85
+ end
86
+ end
87
+
88
+ # Compress and minify scss file
89
+ def compress_min_css
90
+ File.open(base_css_file, 'w') do |file|
91
+ file.write(
92
+ SassC::Engine.new(
93
+ File.read(base_scss_file), style: :compressed
94
+ ).render
95
+ )
96
+ end
97
+ FileUtils.remove_file(base_scss_file, true)
98
+ end
99
+
100
+ # Compress scss file
101
+ def compress_css
102
+ File.open(base_css_file, 'w') do |file|
103
+ file.write(
104
+ SassC::Engine.new(
105
+ File.read(base_scss_file), style: :expanded
106
+ ).render
107
+ )
108
+ end
109
+ FileUtils.remove_file(base_scss_file, true)
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end