rails_app 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82dcc08138eb02ce0aafb95ddd5ac1122f2ed79d4510262c3991bc8c2a5eaeb4
4
- data.tar.gz: 47207c80b368ed13984db09d55f437332c9ea97d64d105582f6ef4b95ca27cf7
3
+ metadata.gz: 58716cd225034bd8c2deecc05e99d82b58d05ffbbdeadc3b721a526d249a4b1e
4
+ data.tar.gz: 531c6ecd9e5a5910d0170a53a2cf50e31f294037ae2deeb21908eb2de626f45b
5
5
  SHA512:
6
- metadata.gz: a12f159b7870cc8036d68fa1547de18420292166df000b4e8f72f4d78bff6207020081f264602afe0e9da164dc37d6a25ab0d094b6c577ddcad09c4000a99772
7
- data.tar.gz: 8bd93c9bec6c3b2542d58d288b93e57c55f3c87e68d0a3f82fdabf0cc377c83efa3afac28a806b262ee54f245cf7276fe11de122ecfb0adda77e83fb0dcaa26c
6
+ metadata.gz: 0be667225b33a863c11cd13a0a9f1fa5cf52b70983d6cd3c549c89f3e1012942a0bb44dd1de6f695db48dca5275e23512a5e053541439bfa73480ba73b6ccc68
7
+ data.tar.gz: 420dc812fc3fb540a55b072c4a4ec18635862efbdb2bdf751de64890dc279b33b76cbbb4840a81cc296bf06d1ba72d068439311e1a5e57d13d361b126e09461f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.0](https://github.com/eclectic-coding/rails_app/tree/0.8.0) (2024-04-05)
4
+
5
+ [Full Changelog](https://github.com/eclectic-coding/rails_app/compare/0.7.0...0.8.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - setup `tty-config` to save a new config [\#24](https://github.com/eclectic-coding/rails_app/issues/24)
10
+ - Add more tests [\#4](https://github.com/eclectic-coding/rails_app/issues/4)
11
+ - Setup tty config to save a new config [\#25](https://github.com/eclectic-coding/rails_app/pull/25) ([eclectic-coding](https://github.com/eclectic-coding))
12
+ - 4 add more tests [\#23](https://github.com/eclectic-coding/rails_app/pull/23) ([eclectic-coding](https://github.com/eclectic-coding))
13
+
14
+ ## [0.7.0](https://github.com/eclectic-coding/rails_app/tree/0.7.0) (2024-04-04)
15
+
16
+ [Full Changelog](https://github.com/eclectic-coding/rails_app/compare/0.6.0...0.7.0)
17
+
18
+ **Implemented enhancements:**
19
+
20
+ - handle optional CLI ARGV [\#21](https://github.com/eclectic-coding/rails_app/issues/21)
21
+ - Add user option to select other styling systems [\#2](https://github.com/eclectic-coding/rails_app/issues/2)
22
+ - Handle optional cli argv [\#22](https://github.com/eclectic-coding/rails_app/pull/22) ([eclectic-coding](https://github.com/eclectic-coding))
23
+
3
24
  ## [0.6.0](https://github.com/eclectic-coding/rails_app/tree/0.6.0) (2024-04-04)
4
25
 
5
26
  [Full Changelog](https://github.com/eclectic-coding/rails_app/compare/0.5.0...0.6.0)
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ![GitHub License](https://img.shields.io/github/license/eclectic-coding/rails_app)
2
2
  [![Tests](https://github.com/eclectic-coding/rails_app/actions/workflows/ci.yml/badge.svg)](https://github.com/eclectic-coding/rails_app/actions/workflows/ci.yml)
3
+ [![Gem Version](https://badge.fury.io/rb/rails_app.svg)](https://badge.fury.io/rb/rails_app)
3
4
  # RailsApp
4
5
 
5
6
  RailsApp is a gem that provides a simple way to create a new Rails application with a pre-configured set of gems and settings, utilizing the Rails application templates feature.
@@ -23,15 +24,46 @@ To bootstrap a new Rails application: `rails_app`
23
24
 
24
25
  The user will be prompted to enter the name of the new Rails application, and the select the assets pipeline to use (propshaft or sprockets), and a styling option:
25
26
 
26
- ![](./screenshot_cli.png)
27
+ ![](assets/screenshot_cli.png)
27
28
 
28
29
  Also, you can select your database of choice:
29
30
 
30
- ![](./screenshot_cli_db.png)
31
+ ![](assets/screenshot_cli_db.png)
31
32
 
32
33
  The template will then create a new Rails application with the selected options.
33
34
 
34
- ### Testing
35
+ ### Optional CLI Syntax
36
+
37
+ There is an additional syntax, available starting with release `v. 0.7.0`, which allows you to use `rails_app` very similarly to the `rails new` command:
38
+
39
+
40
+ ```bash
41
+ rails_app new my_app -a propshaft --css bootstrap -d postgresql
42
+ ```
43
+ I few things to note:
44
+ - the `app_name` must be first, just like with `rails new`
45
+ - the following arguments and flags must be separated by a space `-a propshaft`. Since, the parser ignores the flag and checks for the specific keywords only, you technically can use the follow: `rails_app my_app propshaft bootstrap postgresql`.
46
+
47
+ If you use this syntax, the template will not prompt you the application name, and subsequent options will be preselected for you.
48
+
49
+ Right not this syntax only supports the following options:
50
+ - app name
51
+ - assets pipeline
52
+ - styling
53
+ - database
54
+
55
+ More options will be added in future releases.
56
+
57
+ ## Configuration
58
+ **NEW** Starting with release `v. 0.8.0`, you can save your preferred defaults to you users home directory (`rails_aap-config.yml`).
59
+ If a file has been previously saved, you will be prompted if you want to use:
60
+ ![](assets/screenshot_cli_readconfig.png)
61
+
62
+
63
+ Then your options will be pre-selected:
64
+ ![](assets/screenshot_cli_useconfig.png)
65
+
66
+ ## Testing
35
67
  The template includes RSpec for testing, which includes pre configured:
36
68
  - FactoryBot
37
69
  - Faker
Binary file
data/bin/rails_app CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "rails_app"
4
4
 
5
- RailsApp::App.rails_app
5
+ RailsApp::App.rails_app(ARGV)
data/lib/rails_app/cli.rb CHANGED
@@ -4,22 +4,46 @@ require "tty-prompt"
4
4
 
5
5
  module RailsApp
6
6
  class CLI
7
- def self.start
7
+ def self.start(args)
8
8
  prompt = TTY::Prompt.new
9
9
 
10
- app_name = prompt.ask("What is the name of your application?", required: true)
11
- assets = prompt.select("How would you like to manage assets?", %w[propshaft sprockets])
12
- styling_choices = [
13
- {name: "Bootstrap", value: "bootstrap"},
14
- {name: "Tailwind CSS", value: "tailwind"},
15
- {name: "Bulma", value: "bulma"},
16
- {name: "PostCSS", value: "postcss"},
17
- {name: "SASS", value: "sass"}
18
- ]
19
- styling = prompt.select("How would you like to manage styling?", styling_choices)
20
- database = prompt.select("Which database would you like to use?", %w[postgresql sqlite3 mysql trilogy oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc])
21
-
22
- Command.new(app_name: app_name, assets: assets, styling: styling, database: database).run
10
+ options_data = OptionsData.new(args)
11
+ config_file = ConfigFile.new
12
+
13
+ app_name = options_data.app_name || prompt.ask("What is the name of your application?", required: true)
14
+
15
+ # Read the configuration and ask the user if they want to use it
16
+ config_options = config_file.read
17
+ if config_options && prompt.yes?("Do you want to use this configuration? #{config_options}")
18
+ options_data = OptionsData.from_config(config_options)
19
+ end
20
+
21
+ assets = prompt.select("How would you like to manage assets?", %w[propshaft sprockets], default: options_data.default_assets)
22
+ styling = prompt.select("How would you like to manage styling?", %w[bootstrap tailwind bulma postcss sass], default: options_data.default_styling)
23
+ database = prompt.select("Which database would you like to use?",
24
+ %w[postgresql sqlite3 mysql trilogy oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc],
25
+ default: options_data.default_database)
26
+
27
+ # Collect all configuration options into a hash
28
+ config_options = {
29
+ app_name: app_name,
30
+ assets: assets,
31
+ styling: styling,
32
+ database: database
33
+ }
34
+
35
+ # Ask the user if they wish to save their configuration
36
+ if prompt.yes?("Do you wish to save your configuration?")
37
+ # Iterate over the hash and set the configuration
38
+ config_options.each do |key, value|
39
+ next if key == :app_name
40
+ config_file.set(key, value)
41
+ end
42
+ config_file.write(force: true)
43
+ puts "Configuration saved successfully @ #{config_file.full_path}"
44
+ end
45
+
46
+ Command.new(config_options).run
23
47
  end
24
48
  end
25
49
  end
@@ -1,14 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
1
  module RailsApp
4
2
  class Command
5
3
  attr_reader :app_name, :assets, :styling, :database
6
4
 
7
- def initialize(app_name:, assets:, styling:, database:)
8
- @app_name = app_name
9
- @assets = assets
10
- @styling = styling
11
- @database = database
5
+ def initialize(args)
6
+ @app_name = args[:app_name]
7
+ @assets = args[:assets]
8
+ @styling = args[:styling]
9
+ @database = args[:database]
12
10
  end
13
11
 
14
12
  def template
@@ -17,6 +15,7 @@ module RailsApp
17
15
 
18
16
  def run
19
17
  command = "rails new #{@app_name} --no-rc #{skip_spring} #{database_adapter} #{asset_management} #{javascript_bundling} #{styling_framework} #{testing_framework} -m #{template}"
18
+ command.squeeze!(" ")
20
19
  puts command
21
20
  system(command)
22
21
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-config"
4
+
5
+ module RailsApp
6
+ class ConfigFile
7
+ def initialize
8
+ @config = TTY::Config.new
9
+ @config.append_path(Dir.home)
10
+ @config.filename = "rails_app-config"
11
+ @config.extname = ".yml"
12
+ end
13
+
14
+ def exist?
15
+ @config.exist?
16
+ end
17
+
18
+ def set(key, value)
19
+ @config.set(key, value: value)
20
+ end
21
+
22
+ def write(force: false)
23
+ @config.write(force: force)
24
+ end
25
+
26
+ def full_path
27
+ File.join(@config.location_paths[0] + "/" + @config.filename + @config.extname)
28
+ end
29
+
30
+ def read
31
+ @config.read if exist?
32
+ @config.to_h
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsApp
4
+ class OptionsData
5
+ attr_reader :options
6
+
7
+ def initialize(args)
8
+ @options = args
9
+ end
10
+
11
+ def self.from_config(config_hash)
12
+ new_args = config_hash.map { |key, value| value.to_s }
13
+ new(new_args)
14
+ end
15
+
16
+ def app_name
17
+ @options[0]
18
+ end
19
+
20
+ def default_assets
21
+ @options.include?("sprockets") ? "sprockets" : "propshaft"
22
+ end
23
+
24
+ def default_styling
25
+ if @options.any? { |option| option.end_with?("tailwind") }
26
+ "tailwind".strip
27
+ elsif @options.any? { |option| option.end_with?("bulma") }
28
+ "bulma".strip
29
+ elsif @options.any? { |option| option.end_with?("postcss") }
30
+ "postcss".strip
31
+ elsif @options.any? { |option| option.end_with?("sass") }
32
+ "sass"
33
+ elsif @options.any? { |option| option.end_with?("bootstrap") }
34
+ "bootstrap"
35
+ else
36
+ "bootstrap"
37
+ end
38
+ end
39
+
40
+ def default_database
41
+ if @options.include?("postgresql")
42
+ "postgresql"
43
+ elsif @options.include?("mysql")
44
+ "mysql"
45
+ elsif @options.include?("trilogy")
46
+ "trilogy"
47
+ elsif @options.include?("oracle")
48
+ "oracle"
49
+ elsif @options.include?("sqlserver")
50
+ "sqlserver"
51
+ elsif @options.include?("jdbcmysql")
52
+ "jdbcmysql"
53
+ elsif @options.include?("jdbcsqlite3")
54
+ "jdbcsqlite3"
55
+ elsif @options.include?("jdbcpostgresql")
56
+ "jdbcpostgresql"
57
+ elsif @options.include?("jdbc")
58
+ "jdbc"
59
+ else
60
+ "sqlite3"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module RailsApp
4
4
  class App
5
- def self.rails_app
6
- RailsApp::CLI.start
5
+ def self.rails_app(args)
6
+ RailsApp::CLI.start(args)
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsApp
4
- VERSION = "0.6.0"
4
+ VERSION = "0.8.0"
5
5
  end
data/lib/rails_app.rb CHANGED
@@ -6,5 +6,7 @@ module RailsApp
6
6
  autoload :App, "rails_app/rails_app"
7
7
  autoload :CLI, "rails_app/cli"
8
8
  autoload :Command, "rails_app/command"
9
+ autoload :OptionsData, "rails_app/options_data"
10
+ autoload :ConfigFile, "rails_app/config_file"
9
11
  autoload :Error, "rails_app/error"
10
12
  end
data/rails_app.gemspec CHANGED
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency "bootsnap", "~> 1.18", ">= 1.18.3" # used by rails new
34
34
  spec.add_dependency "thor", "~> 1.3", ">= 1.3.1"
35
35
  spec.add_dependency "tty-prompt", "~> 0.23.1"
36
+ spec.add_dependency "tty-config", "~> 0.6.0"
36
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-04 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootsnap
@@ -64,6 +64,20 @@ dependencies:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
66
  version: 0.23.1
67
+ - !ruby/object:Gem::Dependency
68
+ name: tty-config
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: 0.6.0
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 0.6.0
67
81
  description: Bootstrap a new customized Rails application with a better development
68
82
  experience.
69
83
  email:
@@ -80,11 +94,17 @@ files:
80
94
  - LICENSE.txt
81
95
  - README.md
82
96
  - Rakefile
97
+ - assets/screenshot_cli.png
98
+ - assets/screenshot_cli_db.png
99
+ - assets/screenshot_cli_readconfig.png
100
+ - assets/screenshot_cli_useconfig.png
83
101
  - bin/rails_app
84
102
  - lib/rails_app.rb
85
103
  - lib/rails_app/cli.rb
86
104
  - lib/rails_app/command.rb
105
+ - lib/rails_app/config_file.rb
87
106
  - lib/rails_app/error.rb
107
+ - lib/rails_app/options_data.rb
88
108
  - lib/rails_app/rails_app.rb
89
109
  - lib/rails_app/template/.rspec
90
110
  - lib/rails_app/template/.rubocop.yml
@@ -226,8 +246,6 @@ files:
226
246
  - lib/rails_app/template/template.rb
227
247
  - lib/rails_app/version.rb
228
248
  - rails_app.gemspec
229
- - screenshot_cli.png
230
- - screenshot_cli_db.png
231
249
  homepage: https://github.com/eclectic-coding/rails_app
232
250
  licenses:
233
251
  - MIT
File without changes