rails_plan 0.0.1 → 0.0.3

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: 23170ff2898b14d93eb59bdccf49b46e4165666917450bd2abc659ab8632a9ed
4
- data.tar.gz: 37bff330a0076fab81f4350e05799a2dd5a50a372b7e71edfe1e7d1b2cd64be8
3
+ metadata.gz: 637cf6bb65b71b6c3d5abb4156d904e10291ac9bedf20155572b287f9a58fba4
4
+ data.tar.gz: 18da9973257fb0d88d24e6aa29d93423085f68d04ee1f22a3fb6711721a358e5
5
5
  SHA512:
6
- metadata.gz: 3fa7cd7843bd5816939313e253a6c68163d57f98c3a982b2b0068fe733336774121980c0ff51031a6aacfaceaec657d9eb750f914616f70335879f34cd441fe2
7
- data.tar.gz: a5506a2a5ead0430dfa8a9ac0da768eef98b660f46fed94e47b845cff72c7958e0be20db2ceb9ae274b02ad1dd51499f72943698f7b282401b81e02e3c9565a9
6
+ metadata.gz: 75beefe685a677aa49ea3858ce9e37cbbdfc892817a797042f8f6018ae8523283a47b417f9cef8bcfc1f1a08086bc14e295be766c096ea10f43aae122f6cd75f
7
+ data.tar.gz: 12555f000a2c7430a73e6d2a769798ad7c64924c1f723eadc3a3f8b053bd1a65990b40526ee43835e8034327adda986c21ed53243b6de441619397196248d5e4
data/bin/rplan ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rails_plan'
5
+
6
+ command_line_arguments = ARGV.dup
7
+
8
+ RailsPlan::Cli::Processor.new(command_line_arguments).call
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPlan
4
+ module Cli
5
+ class FetchTemplate
6
+ COMMANDS = %w[apply].freeze
7
+ API_URL = 'https://railsplan.com/api/v1'
8
+
9
+ def call(uid)
10
+ response = RestClient.get(API_URL + "/bootstrap_plans/#{uid}") { |res| res }
11
+
12
+ return if response.code != 200
13
+
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ def gem_version
18
+ response = RestClient.get(API_URL + "/bootstrap_plans/gem_current_version")
19
+ parsed_response = JSON.parse(response.body)
20
+
21
+ parsed_response['version']
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPlan
4
+ module Cli
5
+ class Processor
6
+ COMMANDS = %w[start].freeze
7
+
8
+ InvalidCommand = Class.new(StandardError)
9
+ InvalidUid = Class.new(StandardError)
10
+
11
+ def initialize(args)
12
+ @command = args[0]
13
+ @uid = args[1]
14
+ end
15
+
16
+ def call
17
+ validate_command
18
+
19
+ raise InvalidUid, "Bootstrap plan not found for #{@uid}" if json_template.nil?
20
+
21
+ ::RailsPlan.start(json_template)
22
+ end
23
+
24
+ private
25
+
26
+ def validate_command
27
+ raise InvalidCommand, "command #{@command} is not supported!" unless COMMANDS.include?(@command.to_s.downcase)
28
+ end
29
+
30
+ def json_template
31
+ return @json_template if defined?(@json_template)
32
+
33
+ @json_template = ::RailsPlan::Cli::FetchTemplate.new.call(@uid)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ module RailsPlan
2
+ class GemVersion
3
+ NotUpdatedGem = Class.new(StandardError)
4
+
5
+ def self.validate!
6
+ newest_version = RailsPlan::Cli::FetchTemplate.new.gem_version
7
+
8
+ return if system("gem list ^rails_plan$ --version #{newest_version} -i")
9
+
10
+ raise NotUpdatedGem, "Please update the gem to newest version #{newest_version} and retry"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module RailsPlan
2
+ class RailsApp < Thor
3
+ include Thor::Actions
4
+
5
+ def self.source_root
6
+ File.dirname(__FILE__)
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPlan
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.3'
5
+ RAILS_VERSION = '7.1.3.3'
5
6
  end
data/lib/rails_plan.rb CHANGED
@@ -1,11 +1,108 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rest-client'
4
+ require 'json'
5
+ require 'fileutils'
6
+ require 'thor'
7
+
8
+ require 'rails_plan/cli/fetch_template'
9
+ require 'rails_plan/cli/processor'
3
10
  require 'rails_plan/version'
11
+ require 'rails_plan/rails_app'
12
+ require 'rails_plan/gem_version'
4
13
 
5
14
  module RailsPlan
15
+ RailsNotInstalled = Class.new(StandardError)
16
+
6
17
  class << self
7
- def hello
8
- 'Hello world'
18
+ def start(template)
19
+ ::RailsPlan::GemVersion.validate!
20
+
21
+ verify_rails_installation
22
+
23
+ generate_project(template)
24
+ generate_files(template['files'])
25
+ run_commands(template['before_commands'])
26
+ clone_files(template['clones'])
27
+ inject_code(template['inject_code'])
28
+ append_code(template['append_code'])
29
+ update_files(template['gsub'])
30
+
31
+ puts 'Time for coding! 🚀'
32
+
33
+ template['steps'].each do |step|
34
+ run_commands(step['before_commands'])
35
+ generate_files(step['files'])
36
+ run_commands(step['after_commands'])
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def verify_rails_installation
43
+ return if system("gem list ^rails$ --version #{RailsPlan::RAILS_VERSION} -i")
44
+
45
+ raise RailsNotInstalled, "Please install Rails #{RailsPlan::RAILS_VERSION} and retry"
46
+ end
47
+
48
+ def generate_project(template)
49
+ system template['installation_command']
50
+
51
+ Dir.chdir(template['name'])
52
+ end
53
+
54
+ def generate_files(files)
55
+ files.each do |file|
56
+ puts "-> \e[1;32;49mCreate\e[0m #{file['file_path']}"
57
+ file_path = File.join(Dir.pwd, file['file_path'])
58
+ FileUtils.mkdir_p(File.dirname(file_path))
59
+ File.write(file_path, file['content'])
60
+ end
61
+ end
62
+
63
+ def run_commands(commands)
64
+ commands.each do |command|
65
+ puts "-> \e[1;32;49mRun\e[0m #{command}"
66
+ system command
67
+ end
68
+ end
69
+
70
+ def inject_code(injections)
71
+ return if injections.nil? || injections.empty?
72
+
73
+ thor_app = ::RailsPlan::RailsApp.new
74
+
75
+ injections.each do |injection|
76
+ thor_app.inject_into_class(injection['file_path'], injection['class_name'], injection['content'])
77
+ end
78
+ end
79
+
80
+ def append_code(appends)
81
+ return if appends.nil? || appends.empty?
82
+
83
+ thor_app = ::RailsPlan::RailsApp.new
84
+
85
+ appends.each do |append|
86
+ thor_app.append_to_file(append['file_path'], append['content'])
87
+ end
88
+ end
89
+
90
+ def update_files(updates)
91
+ return if updates.nil? || updates.empty?
92
+
93
+ thor_app = ::RailsPlan::RailsApp.new
94
+
95
+ updates.each do |update|
96
+ thor_app.gsub_file(update['file_path'], update['pattern'], update['value'])
97
+ end
98
+ end
99
+
100
+ def clone_files(files)
101
+ return if files.nil? || files.empty?
102
+
103
+ files.each do |file|
104
+ FileUtils.cp(file['from'], file['to'])
105
+ end
9
106
  end
10
107
  end
11
108
  end
metadata CHANGED
@@ -1,24 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_plan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Dąbrowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-30 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.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.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.1
13
41
  description: Speed up Rails app planning and development process
14
42
  email:
15
43
  - contact@paweldabrowski.com
16
- executables: []
44
+ executables:
45
+ - rplan
17
46
  extensions: []
18
47
  extra_rdoc_files: []
19
48
  files:
20
49
  - README.md
50
+ - bin/rplan
21
51
  - lib/rails_plan.rb
52
+ - lib/rails_plan/cli/fetch_template.rb
53
+ - lib/rails_plan/cli/processor.rb
54
+ - lib/rails_plan/gem_version.rb
55
+ - lib/rails_plan/rails_app.rb
22
56
  - lib/rails_plan/version.rb
23
57
  homepage: https://railsplan.com
24
58
  licenses: