mogu 0.6.0 → 0.7.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
2
  SHA256:
3
- metadata.gz: 5043094005d94e801e049d1a6a03689deee2ded40a10703feb2b1dbb5cda5df0
4
- data.tar.gz: 3bc7f43bc271f0a32bbd3cf282020e6dbae6c6970975d3569ca796b379ea0757
3
+ metadata.gz: 997481175fb0e2074d0627ba83fd7fc057d85f3747c550f79c9ff45fd2442108
4
+ data.tar.gz: 8b4463bb1008a206d3c9db2d57ea834be6d631b7c75fc11870711cb18ce67ffc
5
5
  SHA512:
6
- metadata.gz: 07de320e8f7c9c8fdb96f85c78b69a8089711474f0727648701906d2f8e4dcf8959136a063058e835999e2541008c3577a18fee4a1db62a8b148eb3855ca874e
7
- data.tar.gz: 00a5c8bd2bba6b3ad8c75b6df01f0f9088d9ea10807b8798a7d043d5e2553eaee40295ff17405cd5bdf2349c5c549e35ed7c9e12f959b79e37d035d8d912beff
6
+ metadata.gz: e13ab164f9080b1145e0d15f3014d892d67305f12984a8eaa1be04b58f6be367c33f7c02668f09325fd12719218dbcbcd599cfc388f55f1aae7808fa907940ff
7
+ data.tar.gz: a356b500527b00a46c08c9fa6631faa88b4669dc9a8d39bf81d54a9a3c6308ee68ab1f8a4ee1179c82bc9c1f379914a0acff7452bec650210853c9094d4a8947
data/README.md CHANGED
@@ -12,6 +12,7 @@ CLI to create rails projects interactively.
12
12
  - database
13
13
  - javascript
14
14
  - css
15
+ - skips
15
16
  - Support in adding gems
16
17
 
17
18
  ## Installation
@@ -22,8 +23,18 @@ gem install mogu
22
23
 
23
24
  ## Usage
24
25
 
26
+ ### help
27
+
25
28
  ```bash
26
- mogu
29
+ mogu help
30
+ ```
31
+
32
+ ### new
33
+
34
+ Create rails projects interactively.
35
+
36
+ ```bash
37
+ mogu new
27
38
  ```
28
39
 
29
40
  ```bash
@@ -35,7 +46,7 @@ Choose customizes
35
46
  > ⬡ database (Default: sqlite3)
36
47
  ⬡ javascript (Default: importmap)
37
48
  ⬡ css
38
- gems
49
+ skips
39
50
 
40
51
  Choose database
41
52
  > sqlite3
@@ -56,6 +67,19 @@ Choose css
56
67
  postcss
57
68
  sass
58
69
 
70
+ Choose skips
71
+ > ⬡ test
72
+ ```
73
+
74
+ ### gem
75
+
76
+ Add gems to rails projects.
77
+
78
+ ```bash
79
+ mogu gem
80
+ ```
81
+
82
+ ```bash
59
83
  Choose gems
60
84
  > ⬡ brakeman
61
85
  ⬡ solargraph
data/lib/mogu/cli.rb CHANGED
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/command'
4
3
  require 'thor'
5
4
 
6
5
  module Mogu
7
6
  class CLI < Thor
7
+ desc 'gem', 'Add gems to rails projects'
8
+ def gem
9
+ Mogu::GemCommand.new.run
10
+ end
11
+
8
12
  desc 'new', 'Create rails projects interactively'
9
13
  def new
10
- prompt = Mogu::Prompt.new
11
- prompt.run
12
-
13
- Rails::Command.invoke :application, ['new', *prompt.to_opt]
14
+ Mogu::NewCommand.new.run
14
15
  end
15
16
 
16
17
  desc 'version', 'Display mogu version'
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+ require 'rails/command'
5
+ require 'tempfile'
6
+ require 'tty-prompt'
7
+
8
+ module Mogu
9
+ class GemCommand
10
+ def run
11
+ erb = ERB.new File.read(File.expand_path('templates/gem.erb', __dir__))
12
+ prompt = TTY::Prompt.new
13
+ template = Tempfile.new
14
+
15
+ gems = prompt.multi_select 'Choose gems', gem_choices
16
+ template.write erb.result_with_hash(gems: gems)
17
+ template.rewind
18
+
19
+ ENV.store 'LOCATION', template.path
20
+
21
+ Rails::Command.invoke 'app:template'
22
+ end
23
+
24
+ private
25
+
26
+ def gem_choices
27
+ %w[brakeman solargraph rspec rubocop]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/command'
4
+ require 'tty-prompt'
5
+
6
+ module Mogu
7
+ class NewCommand
8
+ def run
9
+ @prompt = TTY::Prompt.new
10
+
11
+ @app_path = @prompt.ask 'Please input app path', required: true
12
+ @is_api = @prompt.yes? 'Do you want api mode?', default: false
13
+ @customizes = @prompt.multi_select 'Choose customizes', customize_choices
14
+
15
+ @database = @prompt.select 'Choose database', database_choices if database?
16
+ @javascript = @prompt.select 'Choose javascript', javascript_choices if javascript?
17
+ @css = @prompt.select 'Choose css', css_choices if css?
18
+ @skips = @prompt.multi_select 'Choose skips', skip_choices if @customizes.include? 'skips'
19
+
20
+ Rails::Command.invoke :application, ['new', *to_opt]
21
+ end
22
+
23
+ private
24
+
25
+ def database?
26
+ @customizes.include? 'database'
27
+ end
28
+
29
+ def javascript?
30
+ @customizes.include? 'javascript'
31
+ end
32
+
33
+ def css?
34
+ @customizes.include? 'css'
35
+ end
36
+
37
+ def css_choices
38
+ %w[tailwind bootstrap bulma postcss sass]
39
+ end
40
+
41
+ def customize_choices
42
+ if @is_api
43
+ [
44
+ { name: 'database (Default: sqlite3)', value: 'database' },
45
+ { name: 'skips', value: 'skips' }
46
+ ]
47
+ else
48
+ [
49
+ { name: 'database (Default: sqlite3)', value: 'database' },
50
+ { name: 'javascript (Default: importmap)', value: 'javascript' },
51
+ { name: 'css', value: 'css' },
52
+ { name: 'skips', value: 'skips' }
53
+ ]
54
+ end
55
+ end
56
+
57
+ def database_choices
58
+ %w[sqlite3 mysql postgresql oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc]
59
+ end
60
+
61
+ def javascript_choices
62
+ %w[importmap webpack esbuild rollup]
63
+ end
64
+
65
+ def skip_choices
66
+ [
67
+ { name: 'test', value: '--skip-test' }
68
+ ]
69
+ end
70
+
71
+ def to_opt
72
+ [
73
+ @app_path,
74
+ @is_api ? ['--api'] : [],
75
+ database? ? ['-d', @database] : [],
76
+ javascript? ? ['-j', @javascript] : [],
77
+ css? ? ['-c', @css] : [],
78
+ @skips.to_a
79
+ ].flatten
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,39 @@
1
+ <% if gems.include? 'brakeman' %>
2
+ gem 'brakeman', group: :development
3
+ <% end %>
4
+
5
+ <% if gems.include? 'rspec' %>
6
+ gem 'factory_bot_rails', group: %i[development test]
7
+ gem 'rspec-rails', group: %i[development test]
8
+ <% end %>
9
+
10
+ <% if gems.include? 'rubocop' %>
11
+ gem 'rubocop-rails', group: :development, require: false
12
+ <% end %>
13
+
14
+ <% if gems.include? 'solargraph' %>
15
+ gem 'solargraph', group: :development
16
+ <% end %>
17
+
18
+ <% if gems.include? 'rubocop' %>
19
+ create_file '.rubocop.yml', <<~YML
20
+ require:
21
+ - rubocop-rails
22
+
23
+ AllCops:
24
+ NewCops: enable
25
+
26
+ Rails:
27
+ Enabled: true
28
+ YML
29
+ <% end %>
30
+
31
+ run 'bundle install'
32
+
33
+ <% if gems.include? 'rspec' %>
34
+ generate 'rspec:install'
35
+ <% end %>
36
+
37
+ <% if gems.include? 'rubocop' %>
38
+ run 'rubocop --auto-gen-config'
39
+ <% end %>
data/lib/mogu/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mogu
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  end
data/lib/mogu.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'mogu/cli'
4
- require_relative 'mogu/prompt'
5
- require_relative 'mogu/template'
4
+ require_relative 'mogu/gem_command'
5
+ require_relative 'mogu/new_command'
6
6
  require_relative 'mogu/version'
7
7
 
8
8
  module Mogu; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mogu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoguraStore
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-03 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -77,8 +77,9 @@ files:
77
77
  - exe/mogu
78
78
  - lib/mogu.rb
79
79
  - lib/mogu/cli.rb
80
- - lib/mogu/prompt.rb
81
- - lib/mogu/template.rb
80
+ - lib/mogu/gem_command.rb
81
+ - lib/mogu/new_command.rb
82
+ - lib/mogu/templates/gem.erb
82
83
  - lib/mogu/version.rb
83
84
  - mogu.gemspec
84
85
  homepage: https://github.com/mogurastore/mogu
data/lib/mogu/prompt.rb DELETED
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tty-prompt'
4
-
5
- module Mogu
6
- class Prompt
7
- Result = Struct.new(
8
- :app_path,
9
- :is_api,
10
- :customizes,
11
- :database,
12
- :javascript,
13
- :css,
14
- :gems,
15
- :template,
16
- keyword_init: true
17
- )
18
-
19
- def initialize
20
- @prompt = TTY::Prompt.new
21
-
22
- @result = Result.new(
23
- app_path: '',
24
- is_api: false,
25
- customizes: [],
26
- database: '',
27
- javascript: '',
28
- css: '',
29
- gems: [],
30
- template: nil
31
- )
32
- end
33
-
34
- def run
35
- @result.app_path = @prompt.ask 'Please input app path', required: true
36
- @result.is_api = @prompt.yes? 'Do you want api mode?', default: false
37
- @result.customizes = customizes
38
-
39
- @result.database = database if database?
40
- @result.javascript = javascript if javascript?
41
- @result.css = css if css?
42
- @result.gems = gems if gems?
43
- @result.template = Mogu::Template.create @result.gems if template?
44
- end
45
-
46
- def to_opt
47
- [
48
- @result.app_path,
49
- @result.is_api ? ['--api'] : [],
50
- database? ? ['-d', @result.database] : [],
51
- javascript? ? ['-j', @result.javascript] : [],
52
- css? ? ['-c', @result.css] : [],
53
- rspec? ? %w[-T] : [],
54
- template? ? ['-m', @result.template.path] : []
55
- ].flatten
56
- end
57
-
58
- private
59
-
60
- def database?
61
- @result.customizes.include? 'database'
62
- end
63
-
64
- def javascript?
65
- @result.customizes.include? 'javascript'
66
- end
67
-
68
- def css?
69
- @result.customizes.include? 'css'
70
- end
71
-
72
- def gems?
73
- @result.customizes.include? 'gems'
74
- end
75
-
76
- def rspec?
77
- @result.gems.include? 'rspec'
78
- end
79
-
80
- def template?
81
- @result.gems.any?
82
- end
83
-
84
- def css
85
- choices = %w[tailwind bootstrap bulma postcss sass]
86
-
87
- @prompt.select 'Choose css', choices
88
- end
89
-
90
- def customizes
91
- choices =
92
- if @result.is_api
93
- [
94
- { name: 'database (Default: sqlite3)', value: 'database' },
95
- { name: 'gems', value: 'gems' }
96
- ]
97
- else
98
- [
99
- { name: 'database (Default: sqlite3)', value: 'database' },
100
- { name: 'javascript (Default: importmap)', value: 'javascript' },
101
- { name: 'css', value: 'css' },
102
- { name: 'gems', value: 'gems' }
103
- ]
104
- end
105
-
106
- @prompt.multi_select 'Choose customizes', choices
107
- end
108
-
109
- def database
110
- choices = %w[sqlite3 mysql postgresql oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc]
111
-
112
- @prompt.select 'Choose database', choices
113
- end
114
-
115
- def gems
116
- choices = %w[brakeman solargraph rspec rubocop]
117
-
118
- @prompt.multi_select 'Choose gems', choices
119
- end
120
-
121
- def javascript
122
- choices = %w[importmap webpack esbuild rollup]
123
-
124
- @prompt.select 'Choose javascript', choices
125
- end
126
- end
127
- end
data/lib/mogu/template.rb DELETED
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tempfile'
4
-
5
- module Mogu
6
- class Template
7
- class << self
8
- def create(gems)
9
- template = new
10
- template.write gems
11
-
12
- template
13
- end
14
- end
15
-
16
- def initialize
17
- @file = Tempfile.new
18
- end
19
-
20
- def path
21
- @file.path
22
- end
23
-
24
- def write(gems)
25
- @file.write brakeman_code if gems.include? 'brakeman'
26
- @file.write solargraph_code if gems.include? 'solargraph'
27
- @file.write rspec_code if gems.include? 'rspec'
28
- @file.write rubocop_code if gems.include? 'rubocop'
29
-
30
- @file.rewind
31
- end
32
-
33
- private
34
-
35
- def brakeman_code
36
- <<~CODE
37
- gem 'brakeman', group: :development
38
- CODE
39
- end
40
-
41
- def solargraph_code
42
- <<~CODE
43
- gem 'solargraph', group: :development
44
- CODE
45
- end
46
-
47
- def rspec_code
48
- <<~CODE
49
- gem 'factory_bot_rails', group: %i[development test]
50
- gem 'rspec-rails', group: %i[development test]
51
-
52
- after_bundle do
53
- generate 'rspec:install'
54
- end
55
- CODE
56
- end
57
-
58
- def rubocop_code
59
- <<~CODE
60
- gem 'rubocop-rails', group: :development, require: false
61
-
62
- create_file '.rubocop.yml', <<~YML
63
- require:
64
- - rubocop-rails
65
-
66
- AllCops:
67
- NewCops: enable
68
-
69
- Rails:
70
- Enabled: true
71
- YML
72
-
73
- after_bundle do
74
- run 'rubocop --auto-gen-config'
75
- end
76
- CODE
77
- end
78
- end
79
- end