mogu 0.1.0 → 0.2.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: c3f1d263cbdbf9a7a5b6befb9c24c433e49071dfbb1086d933152835d348b552
4
- data.tar.gz: '0938e9d935182f6845362f84a61e5236989f16c6c476cba4866f9a830f22f55b'
3
+ metadata.gz: e882b669b0fb0757b1919c4dd31ce6a27eb60d34c8314e1a09c687afa6c498c7
4
+ data.tar.gz: '08e6fd354a294d446a9725272d5f4bd3d1c70ab1fb4e4049f5cc2d280a601d95'
5
5
  SHA512:
6
- metadata.gz: 53097488534d65b6f1163cead3ab51a331a27eeec4bedb2f00c7c61b182f68eced59ff6fc16de72169482751c87bc0a741968db17a61072202b9a44adf9e6a49
7
- data.tar.gz: b422e0fe1c069ea06e33a755fe98c524c5c27405c9c6fcd7638de046ce16424a09058d519061d475855a652e69a9b006ddf5cd116dc60a02f6f0cb62ba9e46e1
6
+ metadata.gz: ebe98974f88cc22c125d2506c374911327a88f0a5fe84bf7ca07c93b5e17d0c47788ca8d02215d2118098d9105edbfe18ad27fc2e0f6e3416e0878f6468dad60
7
+ data.tar.gz: e890c2635c9d80b8950ff1c903b8a1aa62f5258c76db07eb0f34f989b50e66838d595fc6cbf081df66332d191e882f89396190252ed7780952b46b9bc5cec2d2
@@ -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,22 @@
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
+ ## Features
6
6
 
7
- ## Installation
7
+ - Support for rails new option selection.
8
8
 
9
- Add this line to your application's Gemfile:
9
+ ## Installation
10
10
 
11
- ```ruby
12
- gem 'mogu'
11
+ ```bash
12
+ gem install mogu
13
13
  ```
14
14
 
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install mogu
22
-
23
15
  ## Usage
24
16
 
25
- TODO: Write usage instructions here
17
+ ```bash
18
+ mogu
19
+ ```
26
20
 
27
21
  ## Development
28
22
 
@@ -32,7 +26,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
26
 
33
27
  ## Contributing
34
28
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mogu.
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mogurastore/mogu.
36
30
 
37
31
  ## License
38
32
 
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,97 @@
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 rspec?
56
+ result.gems.include? 'rspec'
57
+ end
58
+
59
+ def template?
60
+ rspec?
61
+ end
62
+
63
+ def app_path
64
+ prompt.ask 'Please input app path', required: true
65
+ end
66
+
67
+ def css
68
+ choices = %w[tailwind bootstrap bulma postcss sass]
69
+
70
+ prompt.select 'Choose css', choices
71
+ end
72
+
73
+ def customizes
74
+ choices = %w[database javascript css gems]
75
+
76
+ prompt.multi_select 'Choose customizes', choices
77
+ end
78
+
79
+ def database
80
+ choices = %w[sqlite3 mysql postgresql oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc]
81
+
82
+ prompt.select 'Choose database', choices
83
+ end
84
+
85
+ def gems
86
+ choices = %w[rspec]
87
+
88
+ prompt.multi_select 'Choose gems', choices
89
+ end
90
+
91
+ def javascript
92
+ choices = %w[importmap webpack esbuild rollup]
93
+
94
+ prompt.select 'Choose javascript', choices
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,43 @@
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 rspec_code if gems.include? 'rspec'
24
+
25
+ file.rewind
26
+ end
27
+
28
+ private
29
+
30
+ def rspec_code
31
+ <<~CODE
32
+ gem_group :development, :test do
33
+ gem 'factory_bot_rails'
34
+ gem 'rspec-rails'
35
+ end
36
+
37
+ after_bundle do
38
+ generate 'rspec:install'
39
+ end
40
+ CODE
41
+ end
42
+ end
43
+ 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.0"
4
+ VERSION = '0.2.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"
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"] = "https://github.com"
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.0
4
+ version: 0.2.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-18 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,14 +61,17 @@ 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
- homepage: https://github.com
68
+ homepage: https://github.com/mogurastore/mogu
65
69
  licenses:
66
70
  - MIT
67
71
  metadata:
68
- homepage_uri: https://github.com
69
- source_code_uri: https://github.com
72
+ homepage_uri: https://github.com/mogurastore/mogu
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