rails_plan 0.0.1 → 0.0.2

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: 88472b9ad2b2bdcf2c55e8c78edad02cd8f7803aef5b36d5d4ea0b492ce027a3
4
+ data.tar.gz: f7355e7a282adee10c1c72cf532341a09d262ce8432d88371d1ae3bbd64f7770
5
5
  SHA512:
6
- metadata.gz: 3fa7cd7843bd5816939313e253a6c68163d57f98c3a982b2b0068fe733336774121980c0ff51031a6aacfaceaec657d9eb750f914616f70335879f34cd441fe2
7
- data.tar.gz: a5506a2a5ead0430dfa8a9ac0da768eef98b660f46fed94e47b845cff72c7958e0be20db2ceb9ae274b02ad1dd51499f72943698f7b282401b81e02e3c9565a9
6
+ metadata.gz: 9bb98024808017686220f952bafd61632549998bb1af3566047929a416eaef7aa4b00d159cedf59479da3bb9a5558f3739b63bba06edc67d4fe015f354e42c4c
7
+ data.tar.gz: f08c6967228a92a62e8f56903ea56fcf7dc789eb9eb8e27efc471aa2d6556f25672faa5163db0a972dd9cc9c3c404597eca173a5e43ab09f9c344f340b7f3023
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.2'
5
+ RAILS_VERSION = '7.1.3.3'
5
6
  end
data/lib/rails_plan.rb CHANGED
@@ -1,11 +1,101 @@
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
+ generate_project(template)
23
+ generate_files(template['files'])
24
+ run_commands(template['commands'])
25
+ clone_files(template['clones'])
26
+ inject_code(template['inject_code'])
27
+ append_code(template['append_code'])
28
+ update_files(template['gsub'])
29
+
30
+ puts 'Time for coding! 🚀'
31
+ end
32
+
33
+ private
34
+
35
+ def verify_rails_installation
36
+ return if system("gem list ^rails$ --version #{RailsPlan::RAILS_VERSION} -i")
37
+
38
+ raise RailsNotInstalled, "Please install Rails #{RailsPlan::RAILS_VERSION} and retry"
39
+ end
40
+
41
+ def generate_project(template)
42
+ system template['installation_command']
43
+
44
+ Dir.chdir(template['name'])
45
+ end
46
+
47
+ def generate_files(files)
48
+ files.each do |file|
49
+ puts "-> \e[1;32;49mCreate\e[0m #{file['file_path']}"
50
+ file_path = File.join(Dir.pwd, file['file_path'])
51
+ FileUtils.mkdir_p(File.dirname(file_path))
52
+ File.write(file_path, file['content'])
53
+ end
54
+ end
55
+
56
+ def run_commands(commands)
57
+ commands.each do |command|
58
+ puts "-> \e[1;32;49mRun\e[0m #{command}"
59
+ system command
60
+ end
61
+ end
62
+
63
+ def inject_code(injections)
64
+ return if injections.nil? || injections.empty?
65
+
66
+ thor_app = ::RailsPlan::RailsApp.new
67
+
68
+ injections.each do |injection|
69
+ thor_app.inject_into_class(injection['file_path'], injection['class_name'], injection['content'])
70
+ end
71
+ end
72
+
73
+ def append_code(appends)
74
+ return if appends.nil? || appends.empty?
75
+
76
+ thor_app = ::RailsPlan::RailsApp.new
77
+
78
+ appends.each do |append|
79
+ thor_app.append_to_file(append['file_path'], append['content'])
80
+ end
81
+ end
82
+
83
+ def update_files(updates)
84
+ return if updates.nil? || updates.empty?
85
+
86
+ thor_app = ::RailsPlan::RailsApp.new
87
+
88
+ updates.each do |update|
89
+ thor_app.gsub_file(update['file_path'], update['pattern'], update['value'])
90
+ end
91
+ end
92
+
93
+ def clone_files(files)
94
+ return if files.nil? || files.empty?
95
+
96
+ files.each do |file|
97
+ FileUtils.cp(file['from'], file['to'])
98
+ end
9
99
  end
10
100
  end
11
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Dąbrowski
@@ -9,16 +9,50 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2024-05-30 00:00:00.000000000 Z
12
- dependencies: []
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: