mogu 0.3.1 → 0.5.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: f771a2ccae81801402738371d1bd82433bee4bf09e68d8a73a7c3941fc2e3f07
4
- data.tar.gz: 898998aa11f1c4538c029368e45a8bf70474ddb10ae3e5f12675a2c78be4afca
3
+ metadata.gz: 2db47b44f542a88efc8a2bf123276264957d905fc299bc0fc87662090d139464
4
+ data.tar.gz: 39e544f5a42fcec266d1c410b415382679b1e7d92bafc8fbf8a717b7a80446f2
5
5
  SHA512:
6
- metadata.gz: 548723a2c13a4f984f9e98806a741ea28bc4ea05d24cfab8b622257b05ea1a7796d80360f32be2651a8e6718142fef7319939dac37eb658854acd45740d2de09
7
- data.tar.gz: 32d59b19a3a31bcf44a71862753ef58261f00c1c8b9c44c918a57632a0a0fb8d6a750e1c14b8a0e10a773f90d35b8c2b59dda0a14fce0e15029ba3d70ce5d072
6
+ metadata.gz: ec71aa0276b7f96d7df1720c662cbf704f40c68e11351eb7fda301843be180772be15d48bc454f7002d0a93c4cd61dbfa429b449463017c03afde7f0dc41027c
7
+ data.tar.gz: 8fd8fc23a60b048820dc65a30b1d5da88d87ab47f4a0e40f3f15231f316df835d228582472b2cacfacabfcf83518a9620f06f6b67e71a194286383cf330dfbaf
data/README.md CHANGED
@@ -8,7 +8,11 @@ CLI to create rails projects interactively.
8
8
 
9
9
  ## Features
10
10
 
11
- - Support for rails new option selection.
11
+ - Support in selecting rails new options
12
+ - database
13
+ - javascript
14
+ - css
15
+ - Support in adding gems
12
16
 
13
17
  ## Installation
14
18
 
@@ -26,8 +30,8 @@ mogu
26
30
  Please input app path
27
31
 
28
32
  Choose customizes
29
- > ⬡ database
30
- ⬡ javascript
33
+ > ⬡ database (Default: sqlite3)
34
+ ⬡ javascript (Default: importmap)
31
35
  ⬡ css
32
36
  ⬡ gems
33
37
 
@@ -52,6 +56,7 @@ Choose css
52
56
 
53
57
  Choose gems
54
58
  > ⬡ brakeman
59
+ ⬡ solargraph
55
60
  ⬡ rspec
56
61
  ⬡ rubocop
57
62
  ```
data/docker-compose.yml CHANGED
@@ -5,8 +5,10 @@ services:
5
5
  image: ruby
6
6
  volumes:
7
7
  - .:/workspace
8
+ - gem-credentials-data:/root/.local/share/gem
8
9
  - gem-data:/usr/local/bundle
9
10
  working_dir: /workspace
10
11
 
11
12
  volumes:
13
+ gem-credentials-data:
12
14
  gem-data:
data/lib/mogu/cli.rb CHANGED
@@ -1,15 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'optparse'
3
4
  require 'rails/command'
4
5
 
5
6
  module Mogu
6
7
  class CLI
7
8
  class << self
8
9
  def start
9
- prompt = Mogu::Prompt.new
10
- prompt.run
10
+ params = OptionParser.getopts(ARGV, 'v')
11
11
 
12
- Rails::Command.invoke :application, ['new', *prompt.to_opt]
12
+ if params['v']
13
+ puts "mogu #{Mogu::VERSION}"
14
+ else
15
+ prompt = Mogu::Prompt.new
16
+ prompt.run
17
+
18
+ Rails::Command.invoke :application, ['new', *prompt.to_opt]
19
+ end
13
20
  end
14
21
  end
15
22
  end
data/lib/mogu/prompt.rb CHANGED
@@ -4,102 +4,124 @@ require 'tty-prompt'
4
4
 
5
5
  module Mogu
6
6
  class Prompt
7
- attr_reader :prompt, :result
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
+ )
8
18
 
9
19
  def initialize
10
20
  @prompt = TTY::Prompt.new
11
21
 
12
- result = Struct.new(:app_path, :customizes, :database, :javascript, :css, :gems, :template, keyword_init: true)
13
- @result = result.new(app_path: '', customizes: [], database: '', javascript: '', css: '', gems: [], template: nil)
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
+ )
14
32
  end
15
33
 
16
34
  def run
17
- result.app_path = app_path
18
- result.customizes = customizes
19
-
20
- result.database = database if database?
21
- result.javascript = javascript if javascript?
22
- result.css = css if css?
23
- result.gems = gems if gems?
24
- result.template = Mogu::Template.create result.gems if template?
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?
25
44
  end
26
45
 
27
46
  def to_opt
28
- [result.app_path] + [
29
- database? ? ['-d', result.database] : [],
30
- javascript? ? ['-j', result.javascript] : [],
31
- css? ? ['-c', result.css] : [],
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] : [],
32
53
  rspec? ? %w[-T] : [],
33
- template? ? ['-m', result.template.file.path] : []
54
+ template? ? ['-m', @result.template.path] : []
34
55
  ].flatten
35
56
  end
36
57
 
37
58
  private
38
59
 
39
60
  def database?
40
- result.customizes.include? 'database'
61
+ @result.customizes.include? 'database'
41
62
  end
42
63
 
43
64
  def javascript?
44
- result.customizes.include? 'javascript'
65
+ @result.customizes.include? 'javascript'
45
66
  end
46
67
 
47
68
  def css?
48
- result.customizes.include? 'css'
69
+ @result.customizes.include? 'css'
49
70
  end
50
71
 
51
72
  def gems?
52
- result.customizes.include? 'gems'
53
- end
54
-
55
- def brakeman?
56
- result.gems.include? 'brakeman'
73
+ @result.customizes.include? 'gems'
57
74
  end
58
75
 
59
76
  def rspec?
60
- result.gems.include? 'rspec'
61
- end
62
-
63
- def rubocop?
64
- result.gems.include? 'rubocop'
77
+ @result.gems.include? 'rspec'
65
78
  end
66
79
 
67
80
  def template?
68
- [brakeman?, rspec?, rubocop?].any?
69
- end
70
-
71
- def app_path
72
- prompt.ask 'Please input app path', required: true
81
+ @result.gems.any?
73
82
  end
74
83
 
75
84
  def css
76
85
  choices = %w[tailwind bootstrap bulma postcss sass]
77
86
 
78
- prompt.select 'Choose css', choices
87
+ @prompt.select 'Choose css', choices
79
88
  end
80
89
 
81
90
  def customizes
82
- choices = %w[database javascript css gems]
83
-
84
- prompt.multi_select 'Choose customizes', choices
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
85
107
  end
86
108
 
87
109
  def database
88
110
  choices = %w[sqlite3 mysql postgresql oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc]
89
111
 
90
- prompt.select 'Choose database', choices
112
+ @prompt.select 'Choose database', choices
91
113
  end
92
114
 
93
115
  def gems
94
- choices = %w[brakeman rspec rubocop]
116
+ choices = %w[brakeman solargraph rspec rubocop]
95
117
 
96
- prompt.multi_select 'Choose gems', choices
118
+ @prompt.multi_select 'Choose gems', choices
97
119
  end
98
120
 
99
121
  def javascript
100
122
  choices = %w[importmap webpack esbuild rollup]
101
123
 
102
- prompt.select 'Choose javascript', choices
124
+ @prompt.select 'Choose javascript', choices
103
125
  end
104
126
  end
105
127
  end
data/lib/mogu/template.rb CHANGED
@@ -4,8 +4,6 @@ require 'tempfile'
4
4
 
5
5
  module Mogu
6
6
  class Template
7
- attr_reader :file
8
-
9
7
  class << self
10
8
  def create(gems)
11
9
  template = new
@@ -19,12 +17,17 @@ module Mogu
19
17
  @file = Tempfile.new
20
18
  end
21
19
 
20
+ def path
21
+ @file.path
22
+ end
23
+
22
24
  def write(gems)
23
- file.write brakeman_code if gems.include? 'brakeman'
24
- file.write rspec_code if gems.include? 'rspec'
25
- file.write rubocop_code if gems.include? 'rubocop'
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'
26
29
 
27
- file.rewind
30
+ @file.rewind
28
31
  end
29
32
 
30
33
  private
@@ -35,6 +38,12 @@ module Mogu
35
38
  CODE
36
39
  end
37
40
 
41
+ def solargraph_code
42
+ <<~CODE
43
+ gem 'solargraph', group: :development
44
+ CODE
45
+ end
46
+
38
47
  def rspec_code
39
48
  <<~CODE
40
49
  gem 'factory_bot_rails', group: %i[development test]
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.3.1'
4
+ VERSION = '0.5.0'
5
5
  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.3.1
4
+ version: 0.5.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-03-20 00:00:00.000000000 Z
11
+ date: 2022-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties