fork_rails_project 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85d7578a6118f56d8cb0b3543575a431fab26658
4
+ data.tar.gz: b5bd6bcd80540e79bf84a6334e002bb22e400065
5
+ SHA512:
6
+ metadata.gz: 6c613cedd47e76841729a05d3d00030d9243140121d028b19c5d67b1056dc22ce4ff98641ab7aed4a7d80a85ca128527a1098f4b7a1785d1f0709b1d25d6eae0
7
+ data.tar.gz: b3589828a488c516e29218068318cf89927aac9e78a16b02a48518dd78aaefc9bc590a437ecfd8158248ffe4b3e03f62d95cbab85a4027d5199d972f62099c1c
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require "fork_rails_project"
5
+ rescue LoadError
6
+ require "rubygems"
7
+ require "fork_rails_project"
8
+ end
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/ruby
2
+ require "active_support/all"
3
+ require "find"
4
+ # require "pry"
5
+
6
+
7
+ def copy_files(dest_path, ignored_files)
8
+ copy_string = "rsync -ax "
9
+ ignored_files.each do |file_name|
10
+ copy_string << "--exclude #{file_name} "
11
+ end
12
+ copy_string << ". #{dest_path}"
13
+ begin
14
+ puts "Copying files from #{Dir.pwd} to #{dest_path}"
15
+ puts "Ignored files/directories: #{ignored_files.join(' ')}"
16
+ puts "Executing #{copy_string}"
17
+ %x[#{copy_string}]
18
+ puts
19
+ rescue IOError
20
+ puts "Unable to copy files!"
21
+ end
22
+ end
23
+
24
+ def rename_file_objects(old_name, new_name)
25
+ old_file_paths = []
26
+ Find.find(".") do |path|
27
+ old_file_paths << path if path =~ /#{old_name}/
28
+ end
29
+ old_file_paths = yield(old_file_paths) if block_given?
30
+ files_to_move = Hash.new
31
+ old_file_paths.each do |path|
32
+ new_path = path.gsub(/#{old_name}/, new_name)
33
+ files_to_move[path] = new_path
34
+ end
35
+ files_to_move.each do |old, new|
36
+ puts "Renaming #{old} -> #{new}"
37
+ `mv #{old} #{new}`
38
+ end
39
+ end
40
+
41
+ def substitute_names(old_name, new_name)
42
+ puts "Replacing string '#{old_name}' in application files..."
43
+ occurrence = %x{grep -iR "#{old_name}" --exclude-dir=log --exclude-dir=tmp --exclude=tags .}
44
+ occurrence = occurrence.split("\n")
45
+ files = []
46
+ occurrence.each do |occ|
47
+ occ.slice!(0..1)
48
+ file_name = occ.slice(0...occ.index(":"))
49
+ files << file_name
50
+ end
51
+ files.uniq!
52
+
53
+ begin
54
+ files.each do |file|
55
+ text = File.read(file)
56
+ text = text.gsub(old_name, new_name)
57
+ File.open(file, "w+") { |line| line.puts text }
58
+ end
59
+ rescue IOError
60
+ puts "Unable to alter new files!"
61
+ end
62
+
63
+ puts "Finished replacing string '#{old_name}' in application files. Altered files:"
64
+ files.each do |filename|
65
+ puts filename
66
+ end
67
+ end
68
+
69
+
70
+ source_project_name = ARGV[0].dup
71
+ dest_project_name = ARGV[1].dup
72
+ folder_names = []
73
+ folder_names << source_project_name << dest_project_name
74
+
75
+ folder_names.each do |a|
76
+ a.strip!
77
+ if a.start_with? "/"
78
+ a.slice!(0)
79
+ end
80
+ end
81
+
82
+ raise RuntimeError, "#{source_project_name} is not a valid dir!" if !File.directory?("./#{source_project_name}")
83
+ raise RuntimeError, "Destination directory already exists!" if File.directory?("./#{dest_project_name}")
84
+
85
+ base_dir_path = Dir.pwd
86
+ dest_path = base_dir_path + "/" + dest_project_name
87
+ ignored_files = ARGV[2..-1]
88
+
89
+ begin
90
+ %x{mkdir "#{dest_path}"}
91
+ rescue Error
92
+ puts "Cant't create new directory!"
93
+ end
94
+
95
+ Dir.chdir(base_dir_path + "/" + source_project_name)
96
+ copy_files(dest_path, ignored_files)
97
+ Dir.chdir(dest_path)
98
+
99
+ old_app_name = source_project_name.camelize
100
+ new_app_name = dest_project_name.camelize
101
+
102
+ # Are we inside an engine? If so, we have to rename some files and folders
103
+ if File.exists?("lib/#{source_project_name}/engine.rb")
104
+ rename_file_objects(source_project_name, dest_project_name) do |old_paths|
105
+ old_paths.keep_if { |path| File.directory?(path) }
106
+ end
107
+
108
+ rename_file_objects(source_project_name, dest_project_name)
109
+ puts
110
+ end
111
+
112
+ substitute_names(source_project_name, dest_project_name)
113
+ puts
114
+ substitute_names(old_app_name, new_app_name)
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fork_rails_project
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Huber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ description: Generates copies of existing app directories with automatic renaming/namespacing
28
+ of contained files
29
+ email: alih83@gmx.de
30
+ executables:
31
+ - fork-rails-project
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/fork-rails-project
36
+ - lib/fork_rails_project.rb
37
+ homepage: https://github.com/alihuber/fork_rails_project
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.3.0
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Script to set up forks of existing rails apps/engines
61
+ test_files: []