radon 0.1.6 → 0.1.7
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 +4 -4
- data/.gitignore +13 -13
- data/.rspec +3 -3
- data/.travis.yml +7 -7
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +6 -6
- data/Gemfile.lock +40 -40
- data/LICENSE.txt +21 -21
- data/README.md +88 -88
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/radon +55 -55
- data/bin/setup +8 -8
- data/data/c.b64 +15 -15
- data/data/website.b64 +1 -0
- data/data/website.zip +0 -0
- data/lib/core/constants.rb +1 -1
- data/lib/core/environments.rb +39 -38
- data/lib/core/extract.rb +61 -57
- data/lib/core/text.rb +102 -102
- data/lib/core/util.rb +35 -35
- data/lib/core.rb +11 -11
- data/radon.gemspec +30 -30
- data/scripts/build_install_local.sh +8 -8
- metadata +5 -3
data/bin/radon
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
3
|
-
|
4
|
-
require 'core'
|
5
|
-
|
6
|
-
Signal.trap("INT"){}
|
7
|
-
|
8
|
-
ARGV << '-h' if ARGV.empty?
|
9
|
-
options = {}
|
10
|
-
|
11
|
-
OptionParser.new do |opts|
|
12
|
-
opts.banner = "Generate starter code for different coding environments.\n\nUsage: #{File.basename($PROGRAM_NAME)} [options] [task] NewProjectName\nRadon version: #{Paint[VERSION, '#2ecc71']}"
|
13
|
-
opts.separator Paint["\nGlobal Options: ", '#95a5a6']
|
14
|
-
|
15
|
-
|
16
|
-
opts.on('--list-env', 'List all supported environments') do
|
17
|
-
all = Radon::Environments.getAllNames
|
18
|
-
puts "Supported environments are:"
|
19
|
-
all.each do |e|
|
20
|
-
puts " #{e}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
opts.on('-q', '--quiet', 'Run with suppresed console output.') do
|
25
|
-
$quiet = true
|
26
|
-
end
|
27
|
-
|
28
|
-
opts.on('--verbose', 'Run verbosely') do
|
29
|
-
$verbose = true
|
30
|
-
end
|
31
|
-
|
32
|
-
opts.on('-v', '--version', 'Show the krypton version and exit') do
|
33
|
-
puts "Krypton version: #{Paint[VERSION, '#2ecc71']}"
|
34
|
-
exit 0
|
35
|
-
end
|
36
|
-
|
37
|
-
opts.on('-h', '--help', 'Show this help message') do
|
38
|
-
puts opts
|
39
|
-
exit
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
end.parse!(ARGV)
|
44
|
-
|
45
|
-
while (opt = ARGV.shift) do
|
46
|
-
Radon::Util.first_run
|
47
|
-
if Radon::Environments.getAllNames.include? opt
|
48
|
-
Radon::Environments.extract(opt, ARGV[0])
|
49
|
-
puts Paint["Done! Your project is set up in #{File.expand_path(ARGV[0])}.", :bold, :bright]
|
50
|
-
exit 0
|
51
|
-
else
|
52
|
-
error "#{opt} is not a supported environment!"
|
53
|
-
exit 1
|
54
|
-
end
|
55
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
3
|
+
|
4
|
+
require 'core'
|
5
|
+
|
6
|
+
Signal.trap("INT"){}
|
7
|
+
|
8
|
+
ARGV << '-h' if ARGV.empty?
|
9
|
+
options = {}
|
10
|
+
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Generate starter code for different coding environments.\n\nUsage: #{File.basename($PROGRAM_NAME)} [options] [task] NewProjectName\nRadon version: #{Paint[VERSION, '#2ecc71']}"
|
13
|
+
opts.separator Paint["\nGlobal Options: ", '#95a5a6']
|
14
|
+
|
15
|
+
|
16
|
+
opts.on('--list-env', 'List all supported environments') do
|
17
|
+
all = Radon::Environments.getAllNames
|
18
|
+
puts "Supported environments are:"
|
19
|
+
all.each do |e|
|
20
|
+
puts " #{e}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-q', '--quiet', 'Run with suppresed console output.') do
|
25
|
+
$quiet = true
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('--verbose', 'Run verbosely') do
|
29
|
+
$verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('-v', '--version', 'Show the krypton version and exit') do
|
33
|
+
puts "Krypton version: #{Paint[VERSION, '#2ecc71']}"
|
34
|
+
exit 0
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on('-h', '--help', 'Show this help message') do
|
38
|
+
puts opts
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end.parse!(ARGV)
|
44
|
+
|
45
|
+
while (opt = ARGV.shift) do
|
46
|
+
Radon::Util.first_run
|
47
|
+
if Radon::Environments.getAllNames.include? opt
|
48
|
+
Radon::Environments.extract(opt, ARGV[0])
|
49
|
+
puts Paint["Done! Your project is set up in #{File.expand_path(ARGV[0])}.", :bold, :bright]
|
50
|
+
exit 0
|
51
|
+
else
|
52
|
+
error "#{opt} is not a supported environment!"
|
53
|
+
exit 1
|
54
|
+
end
|
55
|
+
end
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
data/data/c.b64
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
UEsDBBQAAAAIAFpvWU2pW4/NuwAAABkBAAAIABwATWFrZWZpbGVVVAkAA1wE0ltcBNJbdXgLAAEE
|
2
|
-
6AMAAAToAwAAbY7LCs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AABOgDAABQSwECHgMKAAAAAABciEJOAAAAAAAAAAAAAAAABAAYAAAAAAAAABAA/0FBAAAAY3NzL1VUBQADjxNWXHV4CwABBOgDAAAE6AMAAFBLAQIeAwoAAAAAAFyIQk4AAAAAAAAAAAAAAAANABgAAAAAAAAAAAD/gX8AAABjc3Mvc3R5bGUuY3NzVVQFAAOPE1ZcdXgLAAEE6AMAAAToAwAAUEsBAh4DFAAAAAgAVYhCTigmcMQ4AAAATQAAAAoAGAAAAAAAAQAAAP+BxgAAAGluZGV4Lmh0bWxVVAUAA4ETVlx1eAsAAQToAwAABOgDAABQSwECHgMKAAAAAABgiEJOAAAAAAAAAAAAAAAAAwAYAAAAAAAAABAA/0FCAQAAanMvVVQFAAOTE1ZcdXgLAAEE6AMAAAToAwAAUEsBAh4DCgAAAAAAYIhCTgAAAAAAAAAAAAAAAAoAGAAAAAAAAAAAAP+BfwEAAGpzL21haW4uanNVVAUAA5MTVlx1eAsAAQToAwAABOgDAABQSwECHgMKAAAAAAAwiEJOAAAAAAAAAAAAAAAABwAYAAAAAAAAABAA/0HDAQAAcHVibGljL1VUBQADOxNWXHV4CwABBOgDAAAE6AMAAFBLBQYAAAAABwAHACACAAAEAgAAAAA=
|
data/data/website.zip
ADDED
Binary file
|
data/lib/core/constants.rb
CHANGED
data/lib/core/environments.rb
CHANGED
@@ -1,38 +1,39 @@
|
|
1
|
-
require "core/constants"
|
2
|
-
module Radon
|
3
|
-
class Environments
|
4
|
-
|
5
|
-
# The list of all supported environments and their associeted data paths
|
6
|
-
@@all = {
|
7
|
-
'gradle' => File.join(DATA_DIR, "gradle.zip"),
|
8
|
-
'java' => File.join(DATA_DIR, "java.zip"),
|
9
|
-
'maven' => File.join(DATA_DIR, "maven.zip"),
|
10
|
-
'python' => File.join(DATA_DIR, "python.zip"),
|
11
|
-
'c' => File.join(DATA_DIR, "c.zip"),
|
12
|
-
'ruby' => File.join(DATA_DIR, "ruby.zip"),
|
13
|
-
'crystal'=> File.join(DATA_DIR, "crystal_app.zip"),
|
14
|
-
'go_s' => File.join(DATA_DIR, "go_s.zip")
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
1
|
+
require "core/constants"
|
2
|
+
module Radon
|
3
|
+
class Environments
|
4
|
+
|
5
|
+
# The list of all supported environments and their associeted data paths
|
6
|
+
@@all = {
|
7
|
+
'gradle' => File.join(DATA_DIR, "gradle.zip"),
|
8
|
+
'java' => File.join(DATA_DIR, "java.zip"),
|
9
|
+
'maven' => File.join(DATA_DIR, "maven.zip"),
|
10
|
+
'python' => File.join(DATA_DIR, "python.zip"),
|
11
|
+
'c' => File.join(DATA_DIR, "c.zip"),
|
12
|
+
'ruby' => File.join(DATA_DIR, "ruby.zip"),
|
13
|
+
'crystal'=> File.join(DATA_DIR, "crystal_app.zip"),
|
14
|
+
'go_s' => File.join(DATA_DIR, "go_s.zip"),
|
15
|
+
'website'=> File.join(DATA_DIR, "website.zip")
|
16
|
+
}
|
17
|
+
|
18
|
+
# Gets all environments as an array of strings
|
19
|
+
def self.getAllNames
|
20
|
+
@@all.keys
|
21
|
+
end
|
22
|
+
|
23
|
+
# Gets the value (corrosponding zip) of the key
|
24
|
+
def self.getTargetOf(key)
|
25
|
+
@@all[key]
|
26
|
+
end
|
27
|
+
|
28
|
+
# Extract the zip
|
29
|
+
def self.extract(key, target)
|
30
|
+
envs = self.getAllNames
|
31
|
+
if envs.include? key
|
32
|
+
send "extract_#{key}", target
|
33
|
+
else
|
34
|
+
error("#{key} is not a supported environment.\nYou can suggest it be added at https://github.com/cbrnrd/radon/issues")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/core/extract.rb
CHANGED
@@ -1,57 +1,61 @@
|
|
1
|
-
require "base64"
|
2
|
-
require "tempfile"
|
3
|
-
require "zip"
|
4
|
-
|
5
|
-
def extract_gradle(target)
|
6
|
-
extract_zip(Radon::Environments.getTargetOf('gradle'), target)
|
7
|
-
end
|
8
|
-
|
9
|
-
def extract_java(target)
|
10
|
-
extract_zip(Radon::Environments.getTargetOf('java'), target)
|
11
|
-
end
|
12
|
-
|
13
|
-
def extract_maven(target)
|
14
|
-
extract_zip(Radon::Environments.getTargetOf('maven'), target)
|
15
|
-
end
|
16
|
-
|
17
|
-
def extract_python(target)
|
18
|
-
extract_zip(Radon::Environments.getTargetOf('python'), target)
|
19
|
-
end
|
20
|
-
|
21
|
-
def extract_ruby(target)
|
22
|
-
extract_zip(Radon::Environments.getTargetOf('ruby'), target)
|
23
|
-
replace_all_tokens(target)
|
24
|
-
end
|
25
|
-
|
26
|
-
def extract_c(target)
|
27
|
-
extract_zip(Radon::Environments.getTargetOf('c'), target)
|
28
|
-
end
|
29
|
-
|
30
|
-
def extract_crystal(target)
|
31
|
-
extract_zip(Radon::Environments.getTargetOf('crystal'), target)
|
32
|
-
replace_all_tokens(target)
|
33
|
-
end
|
34
|
-
|
35
|
-
def extract_go_s(target)
|
36
|
-
extract_zip(Radon::Environments.getTargetOf('go_s'), target)
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
1
|
+
require "base64"
|
2
|
+
require "tempfile"
|
3
|
+
require "zip"
|
4
|
+
|
5
|
+
def extract_gradle(target)
|
6
|
+
extract_zip(Radon::Environments.getTargetOf('gradle'), target)
|
7
|
+
end
|
8
|
+
|
9
|
+
def extract_java(target)
|
10
|
+
extract_zip(Radon::Environments.getTargetOf('java'), target)
|
11
|
+
end
|
12
|
+
|
13
|
+
def extract_maven(target)
|
14
|
+
extract_zip(Radon::Environments.getTargetOf('maven'), target)
|
15
|
+
end
|
16
|
+
|
17
|
+
def extract_python(target)
|
18
|
+
extract_zip(Radon::Environments.getTargetOf('python'), target)
|
19
|
+
end
|
20
|
+
|
21
|
+
def extract_ruby(target)
|
22
|
+
extract_zip(Radon::Environments.getTargetOf('ruby'), target)
|
23
|
+
replace_all_tokens(target)
|
24
|
+
end
|
25
|
+
|
26
|
+
def extract_c(target)
|
27
|
+
extract_zip(Radon::Environments.getTargetOf('c'), target)
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_crystal(target)
|
31
|
+
extract_zip(Radon::Environments.getTargetOf('crystal'), target)
|
32
|
+
replace_all_tokens(target)
|
33
|
+
end
|
34
|
+
|
35
|
+
def extract_go_s(target)
|
36
|
+
extract_zip(Radon::Environments.getTargetOf('go_s'), target)
|
37
|
+
end
|
38
|
+
|
39
|
+
def extract_website(target)
|
40
|
+
extract_zip(Radon::Environments.getTargetOf('website'), target)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Extracts some zip data to the passed destination
|
44
|
+
def extract_zip(file, destination)
|
45
|
+
puts "Creating project under #{File.expand_path(destination)}" unless $quiet
|
46
|
+
create(destination)
|
47
|
+
FileUtils.mkdir_p(destination)
|
48
|
+
|
49
|
+
Zip::File.open(file) do |zip_file|
|
50
|
+
zip_file.each do |f|
|
51
|
+
fname = f.name.gsub('{{NAME}}', projectify(destination))
|
52
|
+
fpath = File.join(destination, fname)
|
53
|
+
if File.exists?(fpath)
|
54
|
+
skip(fpath)
|
55
|
+
else
|
56
|
+
create(fpath)
|
57
|
+
end
|
58
|
+
zip_file.extract(f, fpath) unless File.exist?(fpath)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/core/text.rb
CHANGED
@@ -1,103 +1,103 @@
|
|
1
|
-
require 'paint'
|
2
|
-
|
3
|
-
def vprint(*args)
|
4
|
-
puts args if $verbose && !$quiet
|
5
|
-
end
|
6
|
-
|
7
|
-
def error(*args)
|
8
|
-
puts Paint["ERROR", '#e74c3c'] + " - #{args.join(' ')}"
|
9
|
-
end
|
10
|
-
|
11
|
-
def report_error_to_github(trace)
|
12
|
-
commit_string = File.directory?(File.join(PROJECT_ROOT, '.git')) ? "Commit `#{File.read(File.join(PROJECT_ROOT, '.git', 'refs', 'heads', 'master')).strip}`" : nil
|
13
|
-
puts %Q{
|
14
|
-
:::::::::::::::::: COPY BELOW ::::::::::::::::::
|
15
|
-
### Ruby version
|
16
|
-
|
17
|
-
`#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}`
|
18
|
-
|
19
|
-
### OS
|
20
|
-
|
21
|
-
#{Gem::Platform.local.os}
|
22
|
-
|
23
|
-
### Radon Version
|
24
|
-
|
25
|
-
`VERSION`
|
26
|
-
|
27
|
-
### Date Found
|
28
|
-
|
29
|
-
#{Time.now.strftime("%d/%m/%Y %H:%M")}
|
30
|
-
|
31
|
-
### Backtrace
|
32
|
-
```
|
33
|
-
#{trace}
|
34
|
-
```
|
35
|
-
|
36
|
-
#{commit_string}
|
37
|
-
:::::::::::::::::: COPY ABOVE ::::::::::::::::::
|
38
|
-
#{Paint["Whoops! Looks like you've found a bug in radon. Please copy the text above and open a new issue at ", '#e74c3c'] + Paint['https://github.com/cbrnrd/radon/issues', :bold, :bright]}
|
39
|
-
}
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def create(fname)
|
44
|
-
puts Paint[" create", '#2ecc71'] + " #{fname}" unless $quiet
|
45
|
-
end
|
46
|
-
|
47
|
-
def skip(fname)
|
48
|
-
puts Paint[" skip", '#f1c40f'] + " #{fname}" unless $quiet
|
49
|
-
end
|
50
|
-
|
51
|
-
# Gets the project name in capitalized format. Eg: MyProjectName
|
52
|
-
def projectify(name)
|
53
|
-
# Name becomes frozen for some reason
|
54
|
-
name = name.gsub(/(.)([A-Z])/,'\1-\2')
|
55
|
-
name.downcase!
|
56
|
-
name.gsub!('..', '')
|
57
|
-
name.gsub!('/', '')
|
58
|
-
name.gsub!('\\', '')
|
59
|
-
name[0] = '' if name[0] == '-'
|
60
|
-
name.gsub!('--', '-')
|
61
|
-
name.gsub!('_-', '-')
|
62
|
-
return name
|
63
|
-
end
|
64
|
-
|
65
|
-
# Prompts the user for input
|
66
|
-
def ask(*args)
|
67
|
-
print(*args)
|
68
|
-
$stdin.gets.chomp
|
69
|
-
end
|
70
|
-
|
71
|
-
# Gets the project name in dash-seperated format. Eg: my-project-name
|
72
|
-
def classify(name)
|
73
|
-
name = name.gsub(/-[a-z]/) {|s| s.upcase }
|
74
|
-
name.delete!('-')
|
75
|
-
return name.slice(0,1).capitalize + name.slice(1..-1)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Replaces 'find' with 'repl' in every file and directory
|
79
|
-
def find_and_replace_all(target_dir, find, repl)
|
80
|
-
files = Dir[File.join(target_dir,'**','*')]
|
81
|
-
files.each do |file_name|
|
82
|
-
next if File.directory?(file_name)
|
83
|
-
begin
|
84
|
-
text = File.read(file_name)
|
85
|
-
# Do the find and replace
|
86
|
-
new_contents = text.gsub(find, repl)
|
87
|
-
File.open(file_name, 'w') {|f| f.puts new_contents}
|
88
|
-
rescue Errno::ENOENT => e
|
89
|
-
# Something weird happened (this shouldn't come up)
|
90
|
-
error "ERROR GSUBING FILE #{file_name}"
|
91
|
-
report_error_to_github(e.backtrace)
|
92
|
-
next
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Replaces all tokens in all files in the target directory
|
98
|
-
def replace_all_tokens(target)
|
99
|
-
find_and_replace_all(target, '{{NAME}}', projectify(target))
|
100
|
-
find_and_replace_all(target, '{{CAPSNAME}}', classify(target))
|
101
|
-
find_and_replace_all(target, '{{EMAIL}}', Radon::Util.get_email)
|
102
|
-
find_and_replace_all(target, '{{GHNAME}}', Radon::Util.get_github_username)
|
1
|
+
require 'paint'
|
2
|
+
|
3
|
+
def vprint(*args)
|
4
|
+
puts args if $verbose && !$quiet
|
5
|
+
end
|
6
|
+
|
7
|
+
def error(*args)
|
8
|
+
puts Paint["ERROR", '#e74c3c'] + " - #{args.join(' ')}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def report_error_to_github(trace)
|
12
|
+
commit_string = File.directory?(File.join(PROJECT_ROOT, '.git')) ? "Commit `#{File.read(File.join(PROJECT_ROOT, '.git', 'refs', 'heads', 'master')).strip}`" : nil
|
13
|
+
puts %Q{
|
14
|
+
:::::::::::::::::: COPY BELOW ::::::::::::::::::
|
15
|
+
### Ruby version
|
16
|
+
|
17
|
+
`#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}`
|
18
|
+
|
19
|
+
### OS
|
20
|
+
|
21
|
+
#{Gem::Platform.local.os}
|
22
|
+
|
23
|
+
### Radon Version
|
24
|
+
|
25
|
+
`VERSION`
|
26
|
+
|
27
|
+
### Date Found
|
28
|
+
|
29
|
+
#{Time.now.strftime("%d/%m/%Y %H:%M")}
|
30
|
+
|
31
|
+
### Backtrace
|
32
|
+
```
|
33
|
+
#{trace}
|
34
|
+
```
|
35
|
+
|
36
|
+
#{commit_string}
|
37
|
+
:::::::::::::::::: COPY ABOVE ::::::::::::::::::
|
38
|
+
#{Paint["Whoops! Looks like you've found a bug in radon. Please copy the text above and open a new issue at ", '#e74c3c'] + Paint['https://github.com/cbrnrd/radon/issues', :bold, :bright]}
|
39
|
+
}
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def create(fname)
|
44
|
+
puts Paint[" create", '#2ecc71'] + " #{fname}" unless $quiet
|
45
|
+
end
|
46
|
+
|
47
|
+
def skip(fname)
|
48
|
+
puts Paint[" skip", '#f1c40f'] + " #{fname}" unless $quiet
|
49
|
+
end
|
50
|
+
|
51
|
+
# Gets the project name in capitalized format. Eg: MyProjectName
|
52
|
+
def projectify(name)
|
53
|
+
# Name becomes frozen for some reason
|
54
|
+
name = name.gsub(/(.)([A-Z])/,'\1-\2')
|
55
|
+
name.downcase!
|
56
|
+
name.gsub!('..', '')
|
57
|
+
name.gsub!('/', '')
|
58
|
+
name.gsub!('\\', '')
|
59
|
+
name[0] = '' if name[0] == '-'
|
60
|
+
name.gsub!('--', '-')
|
61
|
+
name.gsub!('_-', '-')
|
62
|
+
return name
|
63
|
+
end
|
64
|
+
|
65
|
+
# Prompts the user for input
|
66
|
+
def ask(*args)
|
67
|
+
print(*args)
|
68
|
+
$stdin.gets.chomp
|
69
|
+
end
|
70
|
+
|
71
|
+
# Gets the project name in dash-seperated format. Eg: my-project-name
|
72
|
+
def classify(name)
|
73
|
+
name = name.gsub(/-[a-z]/) {|s| s.upcase }
|
74
|
+
name.delete!('-')
|
75
|
+
return name.slice(0,1).capitalize + name.slice(1..-1)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Replaces 'find' with 'repl' in every file and directory
|
79
|
+
def find_and_replace_all(target_dir, find, repl)
|
80
|
+
files = Dir[File.join(target_dir,'**','*')]
|
81
|
+
files.each do |file_name|
|
82
|
+
next if File.directory?(file_name)
|
83
|
+
begin
|
84
|
+
text = File.read(file_name)
|
85
|
+
# Do the find and replace
|
86
|
+
new_contents = text.gsub(find, repl)
|
87
|
+
File.open(file_name, 'w') {|f| f.puts new_contents}
|
88
|
+
rescue Errno::ENOENT => e
|
89
|
+
# Something weird happened (this shouldn't come up)
|
90
|
+
error "ERROR GSUBING FILE #{file_name}"
|
91
|
+
report_error_to_github(e.backtrace)
|
92
|
+
next
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Replaces all tokens in all files in the target directory
|
98
|
+
def replace_all_tokens(target)
|
99
|
+
find_and_replace_all(target, '{{NAME}}', projectify(target))
|
100
|
+
find_and_replace_all(target, '{{CAPSNAME}}', classify(target))
|
101
|
+
find_and_replace_all(target, '{{EMAIL}}', Radon::Util.get_email)
|
102
|
+
find_and_replace_all(target, '{{GHNAME}}', Radon::Util.get_github_username)
|
103
103
|
end
|
data/lib/core/util.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'json'
|
3
|
-
module Radon
|
4
|
-
class Util
|
5
|
-
def self.first_run
|
6
|
-
return if (File.directory?(SETTINGS_DIR) && File.exist?(SETTINGS_FILE))
|
7
|
-
puts "Performing first time setup..."
|
8
|
-
|
9
|
-
# Make settings dir
|
10
|
-
FileUtils.mkdir_p(SETTINGS_DIR)
|
11
|
-
vprint("Creating #{SETTINGS_DIR}")
|
12
|
-
|
13
|
-
puts "Welcome to radon! It looks like it's your first time running radon."
|
14
|
-
email = ask " Email: "
|
15
|
-
gh_uname = ask " GitHub username: "
|
16
|
-
|
17
|
-
data = {
|
18
|
-
:email => email,
|
19
|
-
:username => gh_uname
|
20
|
-
}
|
21
|
-
|
22
|
-
File.write(File.join(SETTINGS_DIR, 'settings.json'), JSON.pretty_generate(data))
|
23
|
-
vprint "Writing settings to #{File.join(SETTINGS_DIR, 'settings.json')}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.get_email
|
27
|
-
JSON.parse(File.read(SETTINGS_FILE))['email']
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.get_github_username
|
31
|
-
JSON.parse(File.read(SETTINGS_FILE))['username']
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
1
|
+
require 'fileutils'
|
2
|
+
require 'json'
|
3
|
+
module Radon
|
4
|
+
class Util
|
5
|
+
def self.first_run
|
6
|
+
return if (File.directory?(SETTINGS_DIR) && File.exist?(SETTINGS_FILE))
|
7
|
+
puts "Performing first time setup..."
|
8
|
+
|
9
|
+
# Make settings dir
|
10
|
+
FileUtils.mkdir_p(SETTINGS_DIR)
|
11
|
+
vprint("Creating #{SETTINGS_DIR}")
|
12
|
+
|
13
|
+
puts "Welcome to radon! It looks like it's your first time running radon."
|
14
|
+
email = ask " Email: "
|
15
|
+
gh_uname = ask " GitHub username: "
|
16
|
+
|
17
|
+
data = {
|
18
|
+
:email => email,
|
19
|
+
:username => gh_uname
|
20
|
+
}
|
21
|
+
|
22
|
+
File.write(File.join(SETTINGS_DIR, 'settings.json'), JSON.pretty_generate(data))
|
23
|
+
vprint "Writing settings to #{File.join(SETTINGS_DIR, 'settings.json')}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.get_email
|
27
|
+
JSON.parse(File.read(SETTINGS_FILE))['email']
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_github_username
|
31
|
+
JSON.parse(File.read(SETTINGS_FILE))['username']
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|