app_copyr 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/app_copyr.gemspec +26 -0
- data/bin/copyr +25 -0
- data/lib/app_copyr/version.rb +3 -0
- data/lib/app_copyr.rb +134 -0
- data/test/copyr_test.rb +53 -0
- data/test/test_classes.rb +30 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ea33f9914aedbc4ae8c1f6bcafe5fe502c1d870
|
4
|
+
data.tar.gz: ebed59ec2f228b48a314dfaf1114be170ee070f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0870590861d00380a08c59a6188cba476028291c084f20a961fdeab2c6ad2eed75398c9906d257b91e0099c7df931038865efbd00efe381d94da61aedc7a1a46
|
7
|
+
data.tar.gz: 1cc4af39ec984fe7c4c31277c7d691d6b5779158e309d279a5a8ed4727b8967384618c1eabffa8ea19b64433dee91c150e58b2ff8c84644514c1bfe5f1ee2bcc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Mike Quinn
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# AppCopyr
|
2
|
+
|
3
|
+
AppCopyr takes a rails app and allows you to rename it to another app. Good for when you need to stamp out an app like some other that you already have and like.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
> This requires libmagic, if you're using a mac, run ``` brew install libmagic ```
|
8
|
+
|
9
|
+
```gem install app_copyr```
|
10
|
+
|
11
|
+
* NOTE: If you have a really simple app name like "a", I try not to whack stuff but the destination app may be useless
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```
|
16
|
+
|
17
|
+
Commands:
|
18
|
+
copyr copy --dest=DEST --source=SOURCE # Copy one to a new one. The destination cannot already exist
|
19
|
+
copyr help [COMMAND] # Describe available commands or one specific command
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/memikequinn/app_copyr/fork )
|
26
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
1. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
1. Create some tests for your new feature
|
30
|
+
1. run the tests (`ruby test/copyr_test.rb`)
|
31
|
+
1. Create a new Pull Request
|
data/Rakefile
ADDED
data/app_copyr.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'app_copyr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "app_copyr"
|
8
|
+
spec.version = AppCopyr::VERSION
|
9
|
+
spec.authors = ["Mike Quinn"]
|
10
|
+
spec.email = ["mquinn@qualcomm.com"]
|
11
|
+
spec.summary = %q{Copies a functional app that you like, to a new app name}
|
12
|
+
spec.description = %q{Will some day have more options like the ability to add/remove stuff.}
|
13
|
+
spec.homepage = "https://github.com/memikequinn/app_copyr"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_dependency 'thor', '~> 0.19', '>= 0.19.1'
|
24
|
+
spec.add_dependency "activesupport", "~> 4.0"
|
25
|
+
spec.add_dependency "ruby-filemagic", "~> 0.6"
|
26
|
+
end
|
data/bin/copyr
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/app_copyr'
|
4
|
+
|
5
|
+
class AppCopyr::Cmdline < Thor
|
6
|
+
include AppCopyr
|
7
|
+
option :source, required: true
|
8
|
+
option :dest, required: true
|
9
|
+
option :old_app_name
|
10
|
+
option :new_app_name
|
11
|
+
option :verbose
|
12
|
+
|
13
|
+
desc "copy", "Copy one to a new one. The destination cannot already exist"
|
14
|
+
def copy
|
15
|
+
puts "Running with options: #{options.inspect}" if options[:verbose]
|
16
|
+
puts "Copying #{options[:source]} to #{options[:dest]}"
|
17
|
+
main
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
AppCopyr::Cmdline.start(ARGV)
|
data/lib/app_copyr.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'thor'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'filemagic'
|
7
|
+
|
8
|
+
require_relative "app_copyr/version"
|
9
|
+
module AppCopyr
|
10
|
+
class DirMissing < StandardError;
|
11
|
+
end
|
12
|
+
class DistinationExists < StandardError;
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :structure_built
|
16
|
+
|
17
|
+
def log(msg)
|
18
|
+
puts msg if options[:verbose]
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_app_name
|
22
|
+
new_app_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_source
|
26
|
+
@build_source ||= options[:source]
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_dest
|
30
|
+
@build_dest ||= options[:dest]
|
31
|
+
end
|
32
|
+
|
33
|
+
def old_app_name
|
34
|
+
@old_app_name ||=
|
35
|
+
if build_source.match('/')
|
36
|
+
build_source.split('/').last.camelize
|
37
|
+
else
|
38
|
+
build_source.camelize
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def new_app_name
|
43
|
+
@new_app_name ||=
|
44
|
+
if build_dest.match('/')
|
45
|
+
build_dest.split('/').last.camelize
|
46
|
+
else
|
47
|
+
build_dest.camelize
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Spits out path to the new app
|
52
|
+
def new_app_root
|
53
|
+
File.dirname(build_dest)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Spits out directory of the new app
|
57
|
+
def new_app_base
|
58
|
+
File.basename(build_dest)
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_structure
|
62
|
+
puts "Building structure..."
|
63
|
+
_created_dirs = []
|
64
|
+
dirs = all_files.reject { |f| not File.directory?(f) }
|
65
|
+
dirs.each do |dir|
|
66
|
+
_new_file = dir.gsub(build_source, build_dest)
|
67
|
+
# make the directory only and next if dir
|
68
|
+
next if _created_dirs.include?(_new_file)
|
69
|
+
printf "."
|
70
|
+
_created_dirs << _new_file
|
71
|
+
log "Making directory #{_new_file}"
|
72
|
+
FileUtils.mkdir_p(_new_file)
|
73
|
+
end
|
74
|
+
@structure_built = true
|
75
|
+
end
|
76
|
+
|
77
|
+
def run_copy
|
78
|
+
# loop thru each directory and substring out the old app name for the new
|
79
|
+
puts "Running file copies..."
|
80
|
+
build_structure unless structure_built
|
81
|
+
files = all_files.select { |f| File.file?(f) && !binary?(f) }
|
82
|
+
files.each do |source_file|
|
83
|
+
next if source_file =~ /\.log\z/
|
84
|
+
_new_file = source_file.gsub(build_source, build_dest)
|
85
|
+
# make the directory only and next if dir
|
86
|
+
_dest_file = File.open(_new_file, 'w+')
|
87
|
+
log "Writing #{source_file}"
|
88
|
+
if File.size(source_file) == 0
|
89
|
+
# skip empty files, but still create them
|
90
|
+
FileUtils.touch(_new_file)
|
91
|
+
next
|
92
|
+
end
|
93
|
+
|
94
|
+
File.open(source_file, 'r').each do |line|
|
95
|
+
if line.match(/(^|\s|_)#{old_app_name}|#{old_app_name.underscore}/)
|
96
|
+
log "Removing #{old_app_name} from #{_new_file}"
|
97
|
+
line = line.gsub(old_app_name, new_app_name)
|
98
|
+
log "Removing #{old_app_name.underscore} from #{_new_file}"
|
99
|
+
line = line.gsub(/(^|\s|_)#{old_app_name.underscore}/, new_app_name.underscore)
|
100
|
+
_dest_file.print line
|
101
|
+
else
|
102
|
+
_dest_file.print line
|
103
|
+
end
|
104
|
+
end
|
105
|
+
_dest_file.close
|
106
|
+
printf "."
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def all_files
|
111
|
+
@all_files ||= Dir.glob(File.join(options[:source], "/**/**/*")).reject{|f| f.match(/\/vendor\/bundle\//)}
|
112
|
+
end
|
113
|
+
|
114
|
+
def binary?(filename)
|
115
|
+
return false if File.size(filename) == 0
|
116
|
+
begin
|
117
|
+
fm= FileMagic.new(FileMagic::MAGIC_MIME)
|
118
|
+
!(fm.file(filename)=~ /^text\//)
|
119
|
+
ensure
|
120
|
+
fm.close
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def main
|
125
|
+
unless Dir.exists?(build_source)
|
126
|
+
raise DirMissing.new("Unable to find source directory #{build_source}")
|
127
|
+
end
|
128
|
+
if Dir.exists?(build_dest)
|
129
|
+
raise DistinationExists.new "Destination already exists"
|
130
|
+
end
|
131
|
+
run_copy
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
data/test/copyr_test.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'minitest/test'
|
2
|
+
require_relative '../lib/app_copyr'
|
3
|
+
require_relative 'test_classes'
|
4
|
+
require "minitest/autorun"
|
5
|
+
|
6
|
+
describe AppCopyr do
|
7
|
+
def setup
|
8
|
+
@bad_subject = EClass.new
|
9
|
+
@good_subject = GClass.new
|
10
|
+
@already_exists = EExistsClass.new
|
11
|
+
|
12
|
+
unless Dir.exists?($test_dir)
|
13
|
+
puts "Creating source test app"
|
14
|
+
system("rails new #{$test_dir}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "test_raise_error_when_source_missing" do
|
19
|
+
assert_raises AppCopyr::DirMissing do
|
20
|
+
@bad_subject.main
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises an error when the destination exists" do
|
25
|
+
assert_raises AppCopyr::DistinationExists do
|
26
|
+
@already_exists.main
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'has the correct new app name' do
|
31
|
+
assert_match /SomeNotRealDest/, @bad_subject.new_app_name
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'run_copy runs without error' do
|
35
|
+
@good_subject.run_copy
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should run through completely without error' do
|
39
|
+
`rails new #{$final_test_dir}`
|
40
|
+
# Capture output to stdout, otherwise it goes to stderr, works on a mac...
|
41
|
+
output = `bin/copyr copy --source #{$final_test_dir} --dest #{$final_test_out_dir} > /dev/stdout 2>&1`
|
42
|
+
refute_match(/No value provided for required options/, output)
|
43
|
+
end
|
44
|
+
|
45
|
+
def teardown
|
46
|
+
# puts "Finished!"
|
47
|
+
`rm -rf #{$good_dest_dir}`
|
48
|
+
`rm -rf #{$already_exists_dir}`
|
49
|
+
`rm -rf #{$final_test_dir}`
|
50
|
+
`rm -rf #{$final_test_out_dir}`
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
$test_dir = "/tmp/a_real_dir"
|
2
|
+
$good_dest_dir = "#{File.dirname(__FILE__)}/some_dest"
|
3
|
+
$already_exists_dir = '/tmp/already_exists'
|
4
|
+
$final_test_dir = '/tmp/a_cool_full_test_app'
|
5
|
+
$final_test_out_dir = '/tmp/a_cool_full_test_app_output'
|
6
|
+
class EClass
|
7
|
+
include AppCopyr
|
8
|
+
def options
|
9
|
+
HashWithIndifferentAccess.new({ "source" => "../not_a_real_dir", "dest" => "../some__not_real_dest" })
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class EExistsClass
|
14
|
+
include AppCopyr
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@already_exists = $already_exists_dir
|
18
|
+
`mkdir -p #{@already_exists}`
|
19
|
+
end
|
20
|
+
def options
|
21
|
+
HashWithIndifferentAccess.new({ "source" => $test_dir, "dest" => @already_exists })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class GClass
|
26
|
+
include AppCopyr
|
27
|
+
def options
|
28
|
+
HashWithIndifferentAccess.new({ "source" => $test_dir, "dest" => $good_dest_dir })
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: app_copyr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Quinn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.19'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.19.1
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.19'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.19.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: activesupport
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '4.0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '4.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: ruby-filemagic
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.6'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0.6'
|
89
|
+
description: Will some day have more options like the ability to add/remove stuff.
|
90
|
+
email:
|
91
|
+
- mquinn@qualcomm.com
|
92
|
+
executables:
|
93
|
+
- copyr
|
94
|
+
extensions: []
|
95
|
+
extra_rdoc_files: []
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- app_copyr.gemspec
|
103
|
+
- bin/copyr
|
104
|
+
- lib/app_copyr.rb
|
105
|
+
- lib/app_copyr/version.rb
|
106
|
+
- test/copyr_test.rb
|
107
|
+
- test/test_classes.rb
|
108
|
+
homepage: https://github.com/memikequinn/app_copyr
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.2.2
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Copies a functional app that you like, to a new app name
|
132
|
+
test_files:
|
133
|
+
- test/copyr_test.rb
|
134
|
+
- test/test_classes.rb
|