radon 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: f9c3aac468691c9a99d77ae6bd41ff867f7c5e96
4
- data.tar.gz: b79fe8d8576585b1a229ea7640c008278d0bd533
3
+ metadata.gz: 50b872015bdbf4bcca0695ca47f5d23eb1d80a4e
4
+ data.tar.gz: 68565c66bbed27a8e3f32d30b60c22783bb3bff8
5
5
  SHA512:
6
- metadata.gz: 50a7baff438be64075bda22ff6ff8ca202186329b7efa342a5c0d4d1b1879e5c6d5dfecdfc585979007cea1f87d092dd0158c182b715a6b03d317fbc8ee4ee4a
7
- data.tar.gz: 389c215d16d7552a3c35b8ebdac6ff46f0012b76a6dd5ceb97021a7f0be5e106386c9cdb73b5e71ea33d0b57c77e23058de5a98f11780e19bd6ee3d12ece9ae4
6
+ metadata.gz: effe2f350d3b5ee7521b72133ae81c25c4a9afa9fb4c0c5718224600dc812a11257e55d00d89283889e24c4126c8f2755d2a1d32f13a797e1636f0630b86cbd8
7
+ data.tar.gz: 6f33205c3000b0a7a6fff94070aa20dc9f9dab4d9c6b2b226bc1d1bd39304192e673c9ebdcc9e4326e1d753375b14c990998c6a2538bdbbd2bf4900711c31c9d
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  pkg
10
+ *.gem
10
11
 
11
12
  # rspec failure tracking
12
13
  .rspec_status
data/README.md CHANGED
@@ -1,78 +1,79 @@
1
- <p align="center"><img src="https://raw.githubusercontent.com/cbrnrd/radon/master/img/radon-readme-header.png"></p>
2
- <p align="center"><img src="https://raw.githubusercontent.com/cbrnrd/radon/master/img/demo.gif"></p>
3
-
4
- ## Installation
5
-
6
- `radon` is part of the [periodic](https://periodic.now.sh) collection of apps. If you install `periodic-cli`, radon should come with it:
7
-
8
- $ gem install periodic-cli
9
-
10
- Or install just the gem:
11
-
12
- $ gem install radon
13
-
14
- ## Usage
15
-
16
- The basic usage is as follows: `radon [environment] {ProjectName}`.
17
-
18
- A full list of supported environments can be found by running `radon --list-env`
19
-
20
- #### Example:
21
-
22
- Here is radon generating a gradle project called MyGradleProject
23
- ```
24
- $ radon gradle MyGradleProject
25
- Creating project under /mnt/c/Users/Carter/Desktop/projects/MyGradleProject
26
- create MyGradleProject
27
- create MyGradleProject/.gradle/
28
- create MyGradleProject/.gradle/4.5/
29
- create MyGradleProject/.gradle/4.5/fileChanges/
30
- create MyGradleProject/.gradle/4.5/fileChanges/last-build.bin
31
- create MyGradleProject/.gradle/4.5/fileHashes/
32
- create MyGradleProject/.gradle/4.5/fileHashes/fileHashes.bin
33
- create MyGradleProject/.gradle/4.5/fileHashes/fileHashes.lock
34
- create MyGradleProject/.gradle/4.5/taskHistory/
35
- create MyGradleProject/.gradle/4.5/taskHistory/taskHistory.bin
36
- create MyGradleProject/.gradle/4.5/taskHistory/taskHistory.lock
37
- create MyGradleProject/.gradle/buildOutputCleanup/
38
- create MyGradleProject/.gradle/buildOutputCleanup/buildOutputCleanup.lock
39
- create MyGradleProject/.gradle/buildOutputCleanup/cache.properties
40
- create MyGradleProject/.gradle/buildOutputCleanup/outputFiles.bin
41
- create MyGradleProject/build.gradle
42
- create MyGradleProject/gradle/
43
- create MyGradleProject/gradle/wrapper/
44
- create MyGradleProject/gradle/wrapper/gradle-wrapper.jar
45
- create MyGradleProject/gradle/wrapper/gradle-wrapper.properties
46
- create MyGradleProject/gradlew
47
- create MyGradleProject/gradlew.bat
48
- create MyGradleProject/settings.gradle
49
- create MyGradleProject/src/
50
- create MyGradleProject/src/main/
51
- create MyGradleProject/src/main/java/
52
- create MyGradleProject/src/main/test/
53
- Done! Your project is set up in /mnt/c/Users/Carter/Desktop/projects/MyGradleProject.
54
- ```
55
-
56
- ## Development
57
-
58
- #### Adding an environment
59
- If you want to add an environment to radon, here are the steps:
60
- 1. Create the standard directory structure of that environment. This is usually found on the environment's website or just through convention.
61
- 2. Zip all the files into one file (`zip -r env.zip .`)
62
- 3. Save the zip data as base64 (`cat env.zip | base64 -w 0 > env.b64`)
63
- 4. Put both the base64 data and the zip file in radon's `/data` folder.
64
- 5. Add the function(s) in `extract.rb` to extract the _zip_ file to the target (See [here](https://github.com/cbrnrd/radon/blob/7cd141b5a61de6a8abaf0009a1a8cfd090f05e97/lib/core/extract.rb#L5))
65
- 6. Add the environments to `@@all` in `environments.rb`
66
- 7. Open a pull request
67
-
68
- ## Contributing
69
-
70
- Bug reports and pull requests are welcome on GitHub at https://github.com/cbrnrd/radon. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
71
-
72
- ## License
73
-
74
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
75
-
76
- ## Code of Conduct
77
-
78
- Everyone interacting in the Radon project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cbrnrd/radon/blob/master/CODE_OF_CONDUCT.md).
1
+ <p align="center"><img src="https://raw.githubusercontent.com/cbrnrd/radon/master/img/radon-readme-header.png"></p>
2
+ <p align="center"><img src="https://raw.githubusercontent.com/cbrnrd/radon/master/img/demo.gif"></p>
3
+
4
+ ## Installation
5
+
6
+ `radon` is part of the [periodic](https://periodic.now.sh) collection of apps. If you install `periodic-cli`, radon should come with it:
7
+
8
+ $ gem install periodic-cli
9
+
10
+ Or install just the gem:
11
+
12
+ $ gem install radon
13
+
14
+ ## Usage
15
+
16
+ The basic usage is as follows: `radon [environment] {ProjectName}`.
17
+
18
+ A full list of supported environments can be found by running `radon --list-env`
19
+
20
+ #### Example:
21
+
22
+ Here is radon generating a gradle project called MyGradleProject
23
+ ```
24
+ $ radon gradle MyGradleProject
25
+ Creating project under /mnt/c/Users/Carter/Desktop/projects/MyGradleProject
26
+ create MyGradleProject
27
+ create MyGradleProject/.gradle/
28
+ create MyGradleProject/.gradle/4.5/
29
+ create MyGradleProject/.gradle/4.5/fileChanges/
30
+ create MyGradleProject/.gradle/4.5/fileChanges/last-build.bin
31
+ create MyGradleProject/.gradle/4.5/fileHashes/
32
+ create MyGradleProject/.gradle/4.5/fileHashes/fileHashes.bin
33
+ create MyGradleProject/.gradle/4.5/fileHashes/fileHashes.lock
34
+ create MyGradleProject/.gradle/4.5/taskHistory/
35
+ create MyGradleProject/.gradle/4.5/taskHistory/taskHistory.bin
36
+ create MyGradleProject/.gradle/4.5/taskHistory/taskHistory.lock
37
+ create MyGradleProject/.gradle/buildOutputCleanup/
38
+ create MyGradleProject/.gradle/buildOutputCleanup/buildOutputCleanup.lock
39
+ create MyGradleProject/.gradle/buildOutputCleanup/cache.properties
40
+ create MyGradleProject/.gradle/buildOutputCleanup/outputFiles.bin
41
+ create MyGradleProject/build.gradle
42
+ create MyGradleProject/gradle/
43
+ create MyGradleProject/gradle/wrapper/
44
+ create MyGradleProject/gradle/wrapper/gradle-wrapper.jar
45
+ create MyGradleProject/gradle/wrapper/gradle-wrapper.properties
46
+ create MyGradleProject/gradlew
47
+ create MyGradleProject/gradlew.bat
48
+ create MyGradleProject/settings.gradle
49
+ create MyGradleProject/src/
50
+ create MyGradleProject/src/main/
51
+ create MyGradleProject/src/main/java/
52
+ create MyGradleProject/src/main/test/
53
+ Done! Your project is set up in /mnt/c/Users/Carter/Desktop/projects/MyGradleProject.
54
+ ```
55
+
56
+ ## Development
57
+
58
+ #### Adding an environment
59
+ If you want to add an environment to radon, here are the steps:
60
+ 1. Create the standard directory structure of that environment. This is usually found on the environment's website or just through convention.
61
+ 2. Zip all the files into one file (`zip -r env.zip .`)
62
+ 3. Save the zip data as base64 (`cat env.zip | base64 -w 0 > env.b64`)
63
+ 4. Put both the base64 data and the zip file in radon's `/data` folder.
64
+ 5. Add the function(s) in `extract.rb` to extract the _zip_ file to the target (See [here](https://github.com/cbrnrd/radon/blob/7cd141b5a61de6a8abaf0009a1a8cfd090f05e97/lib/core/extract.rb#L5))
65
+ 6. Add the environments to `@@all` in `environments.rb`
66
+ 7. Open a pull request
67
+
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cbrnrd/radon. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
76
+
77
+ ## Code of Conduct
78
+
79
+ Everyone interacting in the Radon project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cbrnrd/radon/blob/master/CODE_OF_CONDUCT.md).
data/TODO.md CHANGED
@@ -1,2 +1 @@
1
- 1. Add first use questions (name, email, etc)
2
- 2. Add license choices
1
+ 1. Add license choices
data/bin/radon CHANGED
@@ -43,6 +43,7 @@ OptionParser.new do |opts|
43
43
  end.parse!(ARGV)
44
44
 
45
45
  while (opt = ARGV.shift) do
46
+ Radon::Util.first_run
46
47
  if Radon::Environments.getAllNames.include? opt
47
48
  Radon::Environments.extract(opt, ARGV[0])
48
49
  puts Paint["Done! Your project is set up in #{File.expand_path(ARGV[0])}.", :bold, :bright]
data/lib/core.rb CHANGED
@@ -2,6 +2,7 @@ require "core/environments"
2
2
  require "core/text"
3
3
  require "core/extract"
4
4
  require "core/constants"
5
+ require "core/util"
5
6
 
6
7
  require "paint"
7
8
  require "optparse"
@@ -1,7 +1,21 @@
1
- VERSION = "0.1.3"
1
+ # The version
2
+ VERSION = "0.1.4"
2
3
 
4
+ # The root of this project
3
5
  PROJECT_ROOT = File.absolute_path(File.join(File.dirname(__FILE__), "..", ".."))
6
+
7
+ # Settings pertaining to radon
8
+ SETTINGS_DIR = File.join(Dir.home, '.periodic', 'radon')
9
+
10
+ # The settings json file
11
+ SETTINGS_FILE = File.join(SETTINGS_DIR, 'settings.json')
12
+
13
+ # The base periodic settings path
14
+ BASE_SETTINGS_DIR = File.join(Dir.home, '.periodic')
15
+
16
+ # The folder containing zips and b64 files
4
17
  DATA_DIR = File.absolute_path(File.join(PROJECT_ROOT, "data"))
18
+
5
19
  AUTHORS = {
6
20
  'Carter Brainerd' => '0xCB[at]protonmail[dot]com'
7
- }
21
+ }
@@ -1,45 +1,45 @@
1
- require "core/constants"
2
- module Radon
3
- class Environments
4
- @@all = {
5
- 'gradle' => File.join(DATA_DIR, "gradle.zip"),
6
- 'java' => File.join(DATA_DIR, "java.zip"),
7
- 'maven' => File.join(DATA_DIR, "maven.zip"),
8
- 'python' => File.join(DATA_DIR, "python.zip"),
9
- 'c' => File.join(DATA_DIR, "c.zip"),
10
- 'ruby (beta)' => File.join(DATA_DIR, "ruby.zip"),
11
- 'crystal'=> File.join(DATA_DIR, "crystal_app.zip")
12
- }
13
-
14
- # Gets all environments as an array of strings
15
- def self.getAllNames
16
- @@all.keys
17
- end
18
-
19
- # Gets the value (corrosponding zip) of the key
20
- def self.getTargetOf(key)
21
- @@all[key]
22
- end
23
-
24
- def self.extract(key, target)
25
- case key
26
- when 'gradle'
27
- extract_gradle(target)
28
- when 'java'
29
- extract_java(target)
30
- when 'python'
31
- extract_python(target)
32
- when 'ruby'
33
- extract_ruby(target)
34
- when 'maven'
35
- extract_maven(target)
36
- when 'c'
37
- extract_c(target)
38
- when 'crystal'
39
- extract_crystal(target)
40
- else
41
- error("#{key} is not a supported environment.\nYou can suggest it be added at https://github.com/cbrnrd/radon/issues")
42
- end
43
- end
44
- end
45
- end
1
+ require "core/constants"
2
+ module Radon
3
+ class Environments
4
+ @@all = {
5
+ 'gradle' => File.join(DATA_DIR, "gradle.zip"),
6
+ 'java' => File.join(DATA_DIR, "java.zip"),
7
+ 'maven' => File.join(DATA_DIR, "maven.zip"),
8
+ 'python' => File.join(DATA_DIR, "python.zip"),
9
+ 'c' => File.join(DATA_DIR, "c.zip"),
10
+ 'ruby (beta)' => File.join(DATA_DIR, "ruby.zip"),
11
+ 'crystal'=> File.join(DATA_DIR, "crystal_app.zip")
12
+ }
13
+
14
+ # Gets all environments as an array of strings
15
+ def self.getAllNames
16
+ @@all.keys
17
+ end
18
+
19
+ # Gets the value (corrosponding zip) of the key
20
+ def self.getTargetOf(key)
21
+ @@all[key]
22
+ end
23
+
24
+ def self.extract(key, target)
25
+ case key
26
+ when 'gradle'
27
+ extract_gradle(target)
28
+ when 'java'
29
+ extract_java(target)
30
+ when 'python'
31
+ extract_python(target)
32
+ when 'ruby'
33
+ extract_ruby(target)
34
+ when 'maven'
35
+ extract_maven(target)
36
+ when 'c'
37
+ extract_c(target)
38
+ when 'crystal'
39
+ extract_crystal(target)
40
+ else
41
+ error("#{key} is not a supported environment.\nYou can suggest it be added at https://github.com/cbrnrd/radon/issues")
42
+ end
43
+ end
44
+ end
45
+ end
data/lib/core/extract.rb CHANGED
@@ -1,54 +1,53 @@
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 (beta)'), target)
23
- find_and_replace_all(target, '{{NAME}}', projectify(target).split('-').collect(&:capitalize).join)
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
- find_and_replace_all(target, '{{NAME}}', projectify(target))#.split('-').collect(&:capitalize).join)
33
- find_and_replace_all(target, '{{CAPSNAME}}', classify(target))
34
- end
35
-
36
- # Extracts some zip data to the passed destination
37
- def extract_zip(file, destination)
38
- puts "Creating project under #{File.expand_path(destination)}" unless $quiet
39
- create(destination)
40
- FileUtils.mkdir_p(destination)
41
-
42
- Zip::File.open(file) do |zip_file|
43
- zip_file.each do |f|
44
- fname = f.name.gsub('{{NAME}}', projectify(destination))
45
- fpath = File.join(destination, fname)
46
- if File.exists?(fpath)
47
- skip(fpath)
48
- else
49
- create(fpath)
50
- end
51
- zip_file.extract(f, fpath) unless File.exist?(fpath)
52
- end
53
- end
54
- 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 (beta)'), 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
+ # Extracts some zip data to the passed destination
36
+ def extract_zip(file, destination)
37
+ puts "Creating project under #{File.expand_path(destination)}" unless $quiet
38
+ create(destination)
39
+ FileUtils.mkdir_p(destination)
40
+
41
+ Zip::File.open(file) do |zip_file|
42
+ zip_file.each do |f|
43
+ fname = f.name.gsub('{{NAME}}', projectify(destination))
44
+ fpath = File.join(destination, fname)
45
+ if File.exists?(fpath)
46
+ skip(fpath)
47
+ else
48
+ create(fpath)
49
+ end
50
+ zip_file.extract(f, fpath) unless File.exist?(fpath)
51
+ end
52
+ end
53
+ end
data/lib/core/text.rb CHANGED
@@ -1,84 +1,100 @@
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}"
9
- end
10
-
11
- def report_error_to_github(trace)
12
- puts %Q{
13
- :::::::::::::::::: COPY BELOW ::::::::::::::::::
14
- ### Ruby version
15
-
16
- `#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}`
17
-
18
- ### OS
19
-
20
- #{Gem::Platform.local.os}
21
-
22
- ### Radon Version
23
-
24
- `VERSION`
25
-
26
- ### Date Found
27
-
28
- #{Time.now.strftime("%d/%m/%Y %H:%M")}
29
-
30
- ### Backtrace
31
- ```
32
- #{trace}
33
- ```
34
- :::::::::::::::::: COPY ABOVE ::::::::::::::::::
35
- #{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]}
36
- }
37
-
38
- end
39
-
40
- def create(fname)
41
- puts Paint[" create", '#2ecc71'] + " #{fname}" unless $quiet
42
- end
43
-
44
- def skip(fname)
45
- puts Paint[" skip", '#f1c40f'] + " #{fname}" unless $quiet
46
- end
47
-
48
- def projectify(name)
49
- # Name becomes frozen for some reason
50
- name = name.gsub(/(.)([A-Z])/,'\1-\2')
51
- name.downcase!
52
- name.gsub!('..', '')
53
- name.gsub!('/', '')
54
- name.gsub!('\\', '')
55
- name[0] = '' if name[0] == '-'
56
- name.gsub!('--', '-')
57
- name.gsub!('_-', '-')
58
- return name
59
- end
60
-
61
- def classify(name)
62
- name = name.gsub(/-[a-z]/) {|s| s.upcase }
63
- name.delete!('-')
64
- return name.slice(0,1).capitalize + name.slice(1..-1)
65
- end
66
-
67
- def find_and_replace_all(target_dir, find, repl)
68
- files = Dir[File.join(target_dir,'**','*')]
69
- files.each do |file_name|
70
- next if File.directory?(file_name)
71
- begin
72
- text = File.read(file_name)
73
- # Do the find and replace
74
- new_contents = text.gsub(find, repl)
75
- File.open(file_name, 'w') {|f| f.puts new_contents}
76
- rescue Errno::ENOENT => e
77
- # Something weird happened (this shouldn't come up)
78
- error "ERROR GSUBING FILE #{file_name}"
79
- report_error_to_github(e.backtrace)
80
- next
81
- end
82
- end
83
-
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}"
9
+ end
10
+
11
+ def report_error_to_github(trace)
12
+ puts %Q{
13
+ :::::::::::::::::: COPY BELOW ::::::::::::::::::
14
+ ### Ruby version
15
+
16
+ `#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}`
17
+
18
+ ### OS
19
+
20
+ #{Gem::Platform.local.os}
21
+
22
+ ### Radon Version
23
+
24
+ `VERSION`
25
+
26
+ ### Date Found
27
+
28
+ #{Time.now.strftime("%d/%m/%Y %H:%M")}
29
+
30
+ ### Backtrace
31
+ ```
32
+ #{trace}
33
+ ```
34
+ :::::::::::::::::: COPY ABOVE ::::::::::::::::::
35
+ #{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]}
36
+ }
37
+
38
+ end
39
+
40
+ def create(fname)
41
+ puts Paint[" create", '#2ecc71'] + " #{fname}" unless $quiet
42
+ end
43
+
44
+ def skip(fname)
45
+ puts Paint[" skip", '#f1c40f'] + " #{fname}" unless $quiet
46
+ end
47
+
48
+ # Gets the project name in capitalized format. Eg: MyProjectName
49
+ def projectify(name)
50
+ # Name becomes frozen for some reason
51
+ name = name.gsub(/(.)([A-Z])/,'\1-\2')
52
+ name.downcase!
53
+ name.gsub!('..', '')
54
+ name.gsub!('/', '')
55
+ name.gsub!('\\', '')
56
+ name[0] = '' if name[0] == '-'
57
+ name.gsub!('--', '-')
58
+ name.gsub!('_-', '-')
59
+ return name
60
+ end
61
+
62
+ # Prompts the user for input
63
+ def ask(*args)
64
+ print(*args)
65
+ $stdin.gets.chomp
66
+ end
67
+
68
+ # Gets the project name in dash-seperated format. Eg: my-project-name
69
+ def classify(name)
70
+ name = name.gsub(/-[a-z]/) {|s| s.upcase }
71
+ name.delete!('-')
72
+ return name.slice(0,1).capitalize + name.slice(1..-1)
73
+ end
74
+
75
+ # Replaces `find` with `repl` in every file and directory
76
+ def find_and_replace_all(target_dir, find, repl)
77
+ files = Dir[File.join(target_dir,'**','*')]
78
+ files.each do |file_name|
79
+ next if File.directory?(file_name)
80
+ begin
81
+ text = File.read(file_name)
82
+ # Do the find and replace
83
+ new_contents = text.gsub(find, repl)
84
+ File.open(file_name, 'w') {|f| f.puts new_contents}
85
+ rescue Errno::ENOENT => e
86
+ # Something weird happened (this shouldn't come up)
87
+ error "ERROR GSUBING FILE #{file_name}"
88
+ report_error_to_github(e.backtrace)
89
+ next
90
+ end
91
+ end
92
+ end
93
+
94
+ # Replaces all tokens in all files in the target directory
95
+ def replace_all_tokens(target)
96
+ find_and_replace_all(target, '{{NAME}}', projectify(target))
97
+ find_and_replace_all(target, '{{CAPSNAME}}', classify(target))
98
+ find_and_replace_all(target, '{{EMAIL}}', Radon::Util.get_email)
99
+ find_and_replace_all(target, '{{GHNAME}}', Radon::Util.get_github_username)
84
100
  end
data/lib/core/util.rb ADDED
@@ -0,0 +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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - cbrnrd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-06 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paint
@@ -122,6 +122,7 @@ files:
122
122
  - lib/core/environments.rb
123
123
  - lib/core/extract.rb
124
124
  - lib/core/text.rb
125
+ - lib/core/util.rb
125
126
  - pkg/radon-0.1.1.gem
126
127
  - radon.gemspec
127
128
  - scripts/build_install_local.sh