mogu 0.4.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: 83c36d8a3dcfd0d836638de3e3f7cadcdb0ba191014ad43c0284b5fdc5cf3c75
4
- data.tar.gz: e415394242ec7c6dc4f74c9d5319b0bb8b981b31920ff2d3b8d9eea2068e9476
3
+ metadata.gz: 997481175fb0e2074d0627ba83fd7fc057d85f3747c550f79c9ff45fd2442108
4
+ data.tar.gz: 8b4463bb1008a206d3c9db2d57ea834be6d631b7c75fc11870711cb18ce67ffc
5
5
  SHA512:
6
- metadata.gz: debd2684a695d3d2d9dadfd60514e51903e566a576546e7691e681e0a483efc5739388016682f51bccfb1fc1d739d784b8945a79df7b2b6c3dbb7672a77bed19
7
- data.tar.gz: 36140ce40449777bb3a7f55e6d237360b03021629eef4b036aa8f0fcbe4a16b4fb8aed849569b91229af2f55769f7ce908c8f26b29b43e34a6027350b19933c5
6
+ metadata.gz: e13ab164f9080b1145e0d15f3014d892d67305f12984a8eaa1be04b58f6be367c33f7c02668f09325fd12719218dbcbcd599cfc388f55f1aae7808fa907940ff
7
+ data.tar.gz: a356b500527b00a46c08c9fa6631faa88b4669dc9a8d39bf81d54a9a3c6308ee68ab1f8a4ee1179c82bc9c1f379914a0acff7452bec650210853c9094d4a8947
@@ -0,0 +1,39 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
+ // https://github.com/microsoft/vscode-dev-containers/tree/v0.231.2/containers/docker-existing-docker-compose
3
+ // If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
4
+ {
5
+ "name": "Existing Docker Compose (Extend)",
6
+
7
+ // Update the 'dockerComposeFile' list if you have more compose files or use different names.
8
+ // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
9
+ "dockerComposeFile": ["../compose.yaml", "docker-compose.yml"],
10
+
11
+ // The 'service' property is the name of the service for the container that VS Code should
12
+ // use. Update this value and .devcontainer/docker-compose.yml to the real service name.
13
+ "service": "ruby",
14
+
15
+ // The optional 'workspaceFolder' property is the path VS Code should open by default when
16
+ // connected. This is typically a file mount in .devcontainer/docker-compose.yml
17
+ "workspaceFolder": "/workspace",
18
+
19
+ // Set *default* container specific settings.json values on container create.
20
+ "settings": {},
21
+
22
+ // Add the IDs of extensions you want installed when the container is created.
23
+ "extensions": ["castwide.solargraph"]
24
+
25
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
26
+ // "forwardPorts": [],
27
+
28
+ // Uncomment the next line if you want start specific services in your Docker Compose config.
29
+ // "runServices": [],
30
+
31
+ // Uncomment the next line if you want to keep your containers running after VS Code shuts down.
32
+ // "shutdownAction": "none",
33
+
34
+ // Uncomment the next line to run commands after the container is created - for example installing curl.
35
+ // "postCreateCommand": "apt-get update && apt-get install -y curl",
36
+
37
+ // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
38
+ // "remoteUser": "vscode"
39
+ }
@@ -0,0 +1,38 @@
1
+ version: '3.8'
2
+ services:
3
+ # Update this to the name of the service you want to work with in your docker-compose.yml file
4
+ ruby:
5
+ # If you want add a non-root user to your Dockerfile, you can use the "remoteUser"
6
+ # property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks,
7
+ # debugging) to execute as the user. Uncomment the next line if you want the entire
8
+ # container to run as this user instead. Note that, on Linux, you may need to
9
+ # ensure the UID and GID of the container user you create matches your local user.
10
+ # See https://aka.ms/vscode-remote/containers/non-root for details.
11
+ #
12
+ # user: vscode
13
+
14
+ # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
15
+ # folder. Note that the path of the Dockerfile and context is relative to the *primary*
16
+ # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
17
+ # array). The sample below assumes your primary file is in the root of your project.
18
+ #
19
+ # build:
20
+ # context: .
21
+ # dockerfile: .devcontainer/Dockerfile
22
+
23
+ volumes:
24
+ # Update this to wherever you want VS Code to mount the folder of your project
25
+ - .:/workspace:cached
26
+
27
+ # Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details.
28
+ # - /var/run/docker.sock:/var/run/docker.sock
29
+
30
+ # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
31
+ # cap_add:
32
+ # - SYS_PTRACE
33
+ # security_opt:
34
+ # - seccomp:unconfined
35
+
36
+ # Overrides default command so things don't shut down after the process ends.
37
+ command: /bin/sh -c "while sleep 1000; do :; done"
38
+
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
 
13
13
  /Gemfile.lock
14
14
  /*.gem
15
+
16
+ /compose.override.yaml
data/README.md CHANGED
@@ -8,7 +8,12 @@ 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
+ - skips
16
+ - Support in adding gems
12
17
 
13
18
  ## Installation
14
19
 
@@ -18,18 +23,30 @@ gem install mogu
18
23
 
19
24
  ## Usage
20
25
 
26
+ ### help
27
+
28
+ ```bash
29
+ mogu help
30
+ ```
31
+
32
+ ### new
33
+
34
+ Create rails projects interactively.
35
+
21
36
  ```bash
22
- mogu
37
+ mogu new
23
38
  ```
24
39
 
25
40
  ```bash
26
41
  Please input app path
27
42
 
43
+ Do you want api mode? (y/N)
44
+
28
45
  Choose customizes
29
- > ⬡ database
30
- ⬡ javascript
46
+ > ⬡ database (Default: sqlite3)
47
+ ⬡ javascript (Default: importmap)
31
48
  ⬡ css
32
- gems
49
+ skips
33
50
 
34
51
  Choose database
35
52
  > sqlite3
@@ -50,8 +67,22 @@ Choose css
50
67
  postcss
51
68
  sass
52
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
53
83
  Choose gems
54
84
  > ⬡ brakeman
85
+ ⬡ solargraph
55
86
  ⬡ rspec
56
87
  ⬡ rubocop
57
88
  ```
@@ -1,14 +1,10 @@
1
- version: "3.9"
2
-
3
1
  services:
4
2
  ruby:
5
3
  image: ruby
6
4
  volumes:
7
5
  - .:/workspace
8
- - gem-credentials-data:/root/.local/share/gem
9
6
  - gem-data:/usr/local/bundle
10
7
  working_dir: /workspace
11
8
 
12
9
  volumes:
13
- gem-credentials-data:
14
10
  gem-data:
data/lib/mogu/cli.rb CHANGED
@@ -1,23 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'optparse'
4
- require 'rails/command'
3
+ require 'thor'
5
4
 
6
5
  module Mogu
7
- class CLI
8
- class << self
9
- def start
10
- params = OptionParser.getopts(ARGV, 'v')
6
+ class CLI < Thor
7
+ desc 'gem', 'Add gems to rails projects'
8
+ def gem
9
+ Mogu::GemCommand.new.run
10
+ end
11
11
 
12
- if params['v']
13
- puts "mogu #{Mogu::VERSION}"
14
- else
15
- prompt = Mogu::Prompt.new
16
- prompt.run
12
+ desc 'new', 'Create rails projects interactively'
13
+ def new
14
+ Mogu::NewCommand.new.run
15
+ end
17
16
 
18
- Rails::Command.invoke :application, ['new', *prompt.to_opt]
19
- end
20
- end
17
+ desc 'version', 'Display mogu version'
18
+ def version
19
+ puts Mogu::VERSION
21
20
  end
22
21
  end
23
22
  end
@@ -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.4.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
data/mogu.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  # Uncomment to register a new dependency of your gem
35
35
  spec.add_dependency 'railties', '~> 7.0'
36
+ spec.add_dependency 'thor', '~> 1.0'
36
37
  spec.add_dependency 'tty-prompt', '~> 0.23'
37
38
 
38
39
  # For more information and examples about making a new gem, checkout our
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.4.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-03-23 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
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: tty-prompt
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -46,6 +60,8 @@ executables:
46
60
  extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
63
+ - ".devcontainer/devcontainer.json"
64
+ - ".devcontainer/docker-compose.yml"
49
65
  - ".github/workflows/ci.yml"
50
66
  - ".gitignore"
51
67
  - ".rspec"
@@ -57,12 +73,13 @@ files:
57
73
  - Rakefile
58
74
  - bin/console
59
75
  - bin/setup
60
- - docker-compose.yml
76
+ - compose.yaml
61
77
  - exe/mogu
62
78
  - lib/mogu.rb
63
79
  - lib/mogu/cli.rb
64
- - lib/mogu/prompt.rb
65
- - lib/mogu/template.rb
80
+ - lib/mogu/gem_command.rb
81
+ - lib/mogu/new_command.rb
82
+ - lib/mogu/templates/gem.erb
66
83
  - lib/mogu/version.rb
67
84
  - mogu.gemspec
68
85
  homepage: https://github.com/mogurastore/mogu
@@ -87,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
104
  - !ruby/object:Gem::Version
88
105
  version: '0'
89
106
  requirements: []
90
- rubygems_version: 3.2.22
107
+ rubygems_version: 3.3.7
91
108
  signing_key:
92
109
  specification_version: 4
93
110
  summary: CLI to create rails projects interactively.
data/lib/mogu/prompt.rb DELETED
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tty-prompt'
4
-
5
- module Mogu
6
- class Prompt
7
- Result = Struct.new(:app_path, :customizes, :database, :javascript, :css, :gems, :template, keyword_init: true)
8
-
9
- def initialize
10
- @prompt = TTY::Prompt.new
11
- @result = Result.new(app_path: '', customizes: [], database: '', javascript: '', css: '', gems: [], template: nil)
12
- end
13
-
14
- def run
15
- @result.app_path = app_path
16
- @result.customizes = customizes
17
-
18
- @result.database = database if database?
19
- @result.javascript = javascript if javascript?
20
- @result.css = css if css?
21
- @result.gems = gems if gems?
22
- @result.template = Mogu::Template.create @result.gems if template?
23
- end
24
-
25
- def to_opt
26
- [
27
- @result.app_path,
28
- database? ? ['-d', @result.database] : [],
29
- javascript? ? ['-j', @result.javascript] : [],
30
- css? ? ['-c', @result.css] : [],
31
- rspec? ? %w[-T] : [],
32
- template? ? ['-m', @result.template.path] : []
33
- ].flatten
34
- end
35
-
36
- private
37
-
38
- def database?
39
- @result.customizes.include? 'database'
40
- end
41
-
42
- def javascript?
43
- @result.customizes.include? 'javascript'
44
- end
45
-
46
- def css?
47
- @result.customizes.include? 'css'
48
- end
49
-
50
- def gems?
51
- @result.customizes.include? 'gems'
52
- end
53
-
54
- def rspec?
55
- @result.gems.include? 'rspec'
56
- end
57
-
58
- def template?
59
- @result.gems.any?
60
- end
61
-
62
- def app_path
63
- @prompt.ask 'Please input app path', required: true
64
- end
65
-
66
- def css
67
- choices = %w[tailwind bootstrap bulma postcss sass]
68
-
69
- @prompt.select 'Choose css', choices
70
- end
71
-
72
- def customizes
73
- choices = [
74
- { name: 'database (Default: sqlite3)', value: 'database' },
75
- { name: 'javascript (Default: importmap)', value: 'javascript' },
76
- { name: 'css', value: 'css' },
77
- { name: 'gems', value: 'gems' }
78
- ]
79
-
80
- @prompt.multi_select 'Choose customizes', choices
81
- end
82
-
83
- def database
84
- choices = %w[sqlite3 mysql postgresql oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc]
85
-
86
- @prompt.select 'Choose database', choices
87
- end
88
-
89
- def gems
90
- choices = %w[brakeman solargraph rspec rubocop]
91
-
92
- @prompt.multi_select 'Choose gems', choices
93
- end
94
-
95
- def javascript
96
- choices = %w[importmap webpack esbuild rollup]
97
-
98
- @prompt.select 'Choose javascript', choices
99
- end
100
- end
101
- 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