mogu 0.1.1 → 0.3.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: ca2282c20b2376502cd9922dca18a5b5b564e2c2803579da46f0382288fe55fb
4
- data.tar.gz: 964e3fcacf9183f6790ccd743db33dd3d0b92a27124ac39e8bb7f885b6f0b7ce
3
+ metadata.gz: 1b6b652ea5e6c6cff5a7afea1a7001739c1037b999574e11010c24eb56f12a4a
4
+ data.tar.gz: 8d6d194add2fff01d83ed36568940892e4f915b8b1093df8d904e3a9227c93f8
5
5
  SHA512:
6
- metadata.gz: 9530247fa7c99bafd307993699d702c0bb5f095cba85331c62c53fcca07c24fd52ac1ff742f14b74ad8a9235fef0ff63ca299af1c705c8b9eb14155da7bd9518
7
- data.tar.gz: d0b5e6f2a03a5f59d64244411733bc2f875832add1ff55426070066cb0c563ae960567f651debf707255f77fb47992697d1575447e2260777b2c492ea5df93b7
6
+ metadata.gz: eb5b43087c23d0cb37565a73aff07563fcf3fcc597e5c572c7619cca1df8d92e37892e28a1370abc5e09ed1b380222290fab16e14979859db3eb58ac7a8a5fa3
7
+ data.tar.gz: a91fdab847dd718b44f017e1f149949a8fee092d150452eb63d2c84db74e2261d502cb7c31e7ec4faffeeac3595faab3a2c94aea43c8db34cc647f5c4648677c
@@ -0,0 +1,20 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: 2.7
18
+ bundler-cache: true
19
+ - name: Run rubocop and spec
20
+ run: bundle exec rake rubocop spec
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+
5
+ Metrics/AbcSize:
6
+ Max: 30
7
+
8
+ Metrics/BlockLength:
9
+ Exclude:
10
+ - spec/**/*
11
+
12
+ Metrics/MethodLength:
13
+ Max: 30
14
+
15
+ Style/Documentation:
16
+ Enabled: false
@@ -0,0 +1,8 @@
1
+ {
2
+ "[ruby]": {
3
+ "editor.defaultFormatter": "castwide.solargraph"
4
+ },
5
+ "solargraph.diagnostics": true,
6
+ "solargraph.formatting": true,
7
+ "solargraph.useBundler": true
8
+ }
data/Gemfile CHANGED
@@ -1,10 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in mogu.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
8
+ gem 'rake', '~> 13.0'
9
9
 
10
- gem "rspec", "~> 3.0"
10
+ gem 'rspec', '~> 3.0'
11
+
12
+ gem 'rubocop', '~> 1.26'
13
+
14
+ gem 'rubocop-rake', '~> 0.6.0'
15
+
16
+ gem 'rubocop-rspec', '~> 2.9'
17
+
18
+ gem 'solargraph', '~> 0.44.3'
data/README.md CHANGED
@@ -1,28 +1,58 @@
1
1
  # Mogu
2
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/mogu`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ CLI to create rails projects interactively.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Prerequisites
6
6
 
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
7
+ - Rails 7+
10
8
 
11
- ```ruby
12
- gem 'mogu'
13
- ```
9
+ ## Features
14
10
 
15
- And then execute:
11
+ - Support for rails new option selection.
16
12
 
17
- $ bundle install
18
-
19
- Or install it yourself as:
13
+ ## Installation
20
14
 
21
- $ gem install mogu
15
+ ```bash
16
+ gem install mogu
17
+ ```
22
18
 
23
19
  ## Usage
24
20
 
25
- TODO: Write usage instructions here
21
+ ```bash
22
+ mogu
23
+ ```
24
+
25
+ ```bash
26
+ Please input app path
27
+
28
+ Choose customizes
29
+ > ⬡ database
30
+ ⬡ javascript
31
+ ⬡ css
32
+ ⬡ gems
33
+
34
+ Choose database
35
+ > sqlite3
36
+ mysql
37
+ postgresql
38
+ ...
39
+
40
+ Choose javascript
41
+ > importmap
42
+ webpack
43
+ esbuild
44
+ rollup
45
+
46
+ Choose css
47
+ > tailwind
48
+ bootstrap
49
+ bulma
50
+ postcss
51
+ sass
52
+
53
+ Choose gems
54
+ > ⬡ rspec
55
+ ```
26
56
 
27
57
  ## Development
28
58
 
@@ -32,7 +62,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
62
 
33
63
  ## Contributing
34
64
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mogu.
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mogurastore/mogu.
36
66
 
37
67
  ## License
38
68
 
data/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new(:rubocop)
7
9
 
8
- task default: :spec
10
+ task default: %i[rubocop spec]
data/bin/console CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "mogu"
4
+ require 'bundler/setup'
5
+ require 'mogu'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -11,5 +11,5 @@ require "mogu"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- require "irb"
14
+ require 'irb'
15
15
  IRB.start(__FILE__)
data/exe/mogu CHANGED
@@ -1,3 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "mogu"
4
+ require 'mogu'
5
+
6
+ begin
7
+ Mogu::CLI.start
8
+ rescue Interrupt
9
+ puts
10
+ end
data/lib/mogu/cli.rb CHANGED
@@ -1,73 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rails/command"
4
- require "tty-prompt"
3
+ require 'rails/command'
5
4
 
6
5
  module Mogu
7
6
  class CLI
8
- attr_reader :prompt
7
+ class << self
8
+ def start
9
+ prompt = Mogu::Prompt.new
10
+ prompt.run
9
11
 
10
- def start
11
- @prompt = TTY::Prompt.new
12
-
13
- app_path = prompt.ask("Please input app path", required: true)
14
-
15
- customizes = choose_customizes
16
- database = customizes.include?("database") ? choose_database : ""
17
- javascript = customizes.include?("javascript") ? choose_javascript : ""
18
- css = customizes.include?("css") ? choose_css : ""
19
-
20
- args = [
21
- "new",
22
- app_path,
23
- database.empty? ? "" : "-d #{database}",
24
- javascript.empty? ? "" : "-j #{javascript}",
25
- css.empty? ? "" : "-c #{css}",
26
- ].reject(&:empty?)
27
-
28
- Rails::Command.invoke :application, args
29
- end
30
-
31
- private
32
-
33
- def choose_customizes
34
- prompt.multi_select "Choose customizes" do |menu|
35
- menu.choice "database"
36
- menu.choice "javascript"
37
- menu.choice "css"
38
- end
39
- end
40
-
41
- def choose_database
42
- prompt.select "Choose database" do |menu|
43
- menu.choice "sqlite3"
44
- menu.choice "mysql"
45
- menu.choice "postgresql"
46
- menu.choice "oracle"
47
- menu.choice "sqlserver"
48
- menu.choice "jdbcmysql"
49
- menu.choice "jdbcsqlite3"
50
- menu.choice "jdbcpostgresql"
51
- menu.choice "jdbc"
52
- end
53
- end
54
-
55
- def choose_javascript
56
- prompt.select "Choose javascript" do |menu|
57
- menu.choice "importmap"
58
- menu.choice "webpack"
59
- menu.choice "esbuild"
60
- menu.choice "rollup"
61
- end
62
- end
63
-
64
- def choose_css
65
- prompt.select "Choose css" do |menu|
66
- menu.choice "tailwind"
67
- menu.choice "bootstrap"
68
- menu.choice "bulma"
69
- menu.choice "postcss"
70
- menu.choice "sass"
12
+ Rails::Command.invoke :application, ['new', *prompt.to_opt]
71
13
  end
72
14
  end
73
15
  end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty-prompt'
4
+
5
+ module Mogu
6
+ class Prompt
7
+ attr_reader :prompt, :result
8
+
9
+ def initialize
10
+ @prompt = TTY::Prompt.new
11
+
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)
14
+ end
15
+
16
+ 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?
25
+ end
26
+
27
+ def to_opt
28
+ [result.app_path] + [
29
+ database? ? ['-d', result.database] : [],
30
+ javascript? ? ['-j', result.javascript] : [],
31
+ css? ? ['-c', result.css] : [],
32
+ rspec? ? %w[-T] : [],
33
+ template? ? ['-m', result.template.file.path] : []
34
+ ].flatten
35
+ end
36
+
37
+ private
38
+
39
+ def database?
40
+ result.customizes.include? 'database'
41
+ end
42
+
43
+ def javascript?
44
+ result.customizes.include? 'javascript'
45
+ end
46
+
47
+ def css?
48
+ result.customizes.include? 'css'
49
+ end
50
+
51
+ def gems?
52
+ result.customizes.include? 'gems'
53
+ end
54
+
55
+ def brakeman?
56
+ result.gems.include? 'brakeman'
57
+ end
58
+
59
+ def rspec?
60
+ result.gems.include? 'rspec'
61
+ end
62
+
63
+ def rubocop?
64
+ result.gems.include? 'rubocop'
65
+ end
66
+
67
+ def template?
68
+ [brakeman?, rspec?, rubocop?].any?
69
+ end
70
+
71
+ def app_path
72
+ prompt.ask 'Please input app path', required: true
73
+ end
74
+
75
+ def css
76
+ choices = %w[tailwind bootstrap bulma postcss sass]
77
+
78
+ prompt.select 'Choose css', choices
79
+ end
80
+
81
+ def customizes
82
+ choices = %w[database javascript css gems]
83
+
84
+ prompt.multi_select 'Choose customizes', choices
85
+ end
86
+
87
+ def database
88
+ choices = %w[sqlite3 mysql postgresql oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc]
89
+
90
+ prompt.select 'Choose database', choices
91
+ end
92
+
93
+ def gems
94
+ choices = %w[brakeman rspec rubocop]
95
+
96
+ prompt.multi_select 'Choose gems', choices
97
+ end
98
+
99
+ def javascript
100
+ choices = %w[importmap webpack esbuild rollup]
101
+
102
+ prompt.select 'Choose javascript', choices
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+
5
+ module Mogu
6
+ class Template
7
+ attr_reader :file
8
+
9
+ class << self
10
+ def create(gems)
11
+ template = new
12
+ template.write gems
13
+
14
+ template
15
+ end
16
+ end
17
+
18
+ def initialize
19
+ @file = Tempfile.new
20
+ end
21
+
22
+ 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'
26
+
27
+ file.rewind
28
+ end
29
+
30
+ private
31
+
32
+ def brakeman_code
33
+ <<~CODE
34
+ gem 'brakeman', group: :development
35
+ CODE
36
+ end
37
+
38
+ def rspec_code
39
+ <<~CODE
40
+ gem 'factory_bot_rails', group: %i[development test]
41
+ gem 'rspec-rails', group: %i[development test]
42
+
43
+ after_bundle do
44
+ generate 'rspec:install'
45
+ end
46
+ CODE
47
+ end
48
+
49
+ def rubocop_code
50
+ <<~CODE
51
+ gem 'rubocop-rails', group: :development, require: false
52
+
53
+ create_file '.rubocop.yml', #{rubocop_yml}
54
+
55
+ after_bundle do
56
+ run 'rubocop --auto-gen-config'
57
+ end
58
+ CODE
59
+ end
60
+
61
+ def rubocop_yml
62
+ <<~CODE
63
+ require:
64
+ - rubocop-rails
65
+
66
+ AllCops:
67
+ NewCops: enable
68
+
69
+ Rails:
70
+ Enabled: true
71
+ CODE
72
+ end
73
+ end
74
+ 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.1.1"
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/mogu.rb CHANGED
@@ -1,12 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "mogu/cli"
4
- require_relative "mogu/version"
3
+ require_relative 'mogu/cli'
4
+ require_relative 'mogu/prompt'
5
+ require_relative 'mogu/template'
6
+ require_relative 'mogu/version'
5
7
 
6
8
  module Mogu; end
7
-
8
- begin
9
- Mogu::CLI.new.start
10
- rescue Interrupt
11
- puts
12
- end
data/mogu.gemspec CHANGED
@@ -1,37 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/mogu/version"
3
+ require_relative 'lib/mogu/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "mogu"
6
+ spec.name = 'mogu'
7
7
  spec.version = Mogu::VERSION
8
- spec.authors = %w(lisp719)
9
- spec.email = %w(368034+lisp719@users.noreply.github.com)
8
+ spec.authors = %w[MoguraStore]
9
+ spec.email = %w[368034+lisp719@users.noreply.github.com]
10
10
 
11
- spec.summary = "CLI to create rails projects interactively."
11
+ spec.summary = 'CLI to create rails projects interactively.'
12
12
  spec.description = spec.summary
13
- spec.homepage = "https://github.com/mogurastore/mogu"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.7.0"
13
+ spec.homepage = 'https://github.com/mogurastore/mogu'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.7.0'
16
16
 
17
17
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
18
18
 
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
21
  # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
22
 
23
+ spec.metadata['rubygems_mfa_required'] = 'true'
24
+
23
25
  # Specify which files should be added to the gem when it is released.
24
26
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
27
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
28
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
29
  end
28
- spec.bindir = "exe"
30
+ spec.bindir = 'exe'
29
31
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
32
+ spec.require_paths = ['lib']
31
33
 
32
34
  # Uncomment to register a new dependency of your gem
33
- spec.add_dependency "railties", "~> 7.0"
34
- spec.add_dependency "tty-prompt", "~> 0.23"
35
+ spec.add_dependency 'railties', '~> 7.0'
36
+ spec.add_dependency 'tty-prompt', '~> 0.23'
35
37
 
36
38
  # For more information and examples about making a new gem, checkout our
37
39
  # guide at: https://bundler.io/guides/creating_gem.html
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.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - lisp719
7
+ - MoguraStore
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-12 00:00:00.000000000 Z
11
+ date: 2022-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -46,9 +46,11 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - ".github/workflows/main.yml"
49
+ - ".github/workflows/ci.yml"
50
50
  - ".gitignore"
51
51
  - ".rspec"
52
+ - ".rubocop.yml"
53
+ - ".vscode/settings.json"
52
54
  - Gemfile
53
55
  - LICENSE.txt
54
56
  - README.md
@@ -59,6 +61,8 @@ files:
59
61
  - exe/mogu
60
62
  - lib/mogu.rb
61
63
  - lib/mogu/cli.rb
64
+ - lib/mogu/prompt.rb
65
+ - lib/mogu/template.rb
62
66
  - lib/mogu/version.rb
63
67
  - mogu.gemspec
64
68
  homepage: https://github.com/mogurastore/mogu
@@ -67,6 +71,7 @@ licenses:
67
71
  metadata:
68
72
  homepage_uri: https://github.com/mogurastore/mogu
69
73
  source_code_uri: https://github.com/mogurastore/mogu
74
+ rubygems_mfa_required: 'true'
70
75
  post_install_message:
71
76
  rdoc_options: []
72
77
  require_paths:
@@ -1,16 +0,0 @@
1
- name: Ruby
2
-
3
- on: [push,pull_request]
4
-
5
- jobs:
6
- build:
7
- runs-on: ubuntu-latest
8
- steps:
9
- - uses: actions/checkout@v2
10
- - name: Set up Ruby
11
- uses: ruby/setup-ruby@v1
12
- with:
13
- ruby-version: 3.0.2
14
- bundler-cache: true
15
- - name: Run the default task
16
- run: bundle exec rake