learn_duplicate 0.0.15 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/bin/learn_duplicate +38 -21
  3. data/lib/learn_duplicate.rb +60 -51
  4. metadata +3 -37
  5. data/lib/templates/javascript_lab_template/CONTRIBUTING.md +0 -40
  6. data/lib/templates/javascript_lab_template/LICENSE.md +0 -23
  7. data/lib/templates/javascript_lab_template/README.md +0 -16
  8. data/lib/templates/javascript_lab_template/index.html +0 -12
  9. data/lib/templates/javascript_lab_template/index.js +0 -5
  10. data/lib/templates/javascript_lab_template/package-lock.json +0 -1854
  11. data/lib/templates/javascript_lab_template/package.json +0 -21
  12. data/lib/templates/javascript_lab_template/test/helpers.js +0 -20
  13. data/lib/templates/javascript_lab_template/test/indexTest.js +0 -23
  14. data/lib/templates/react-lab-template/README.md +0 -16
  15. data/lib/templates/react-lab-template/package-lock.json +0 -12333
  16. data/lib/templates/react-lab-template/package.json +0 -38
  17. data/lib/templates/react-lab-template/public/index.html +0 -41
  18. data/lib/templates/react-lab-template/public/manifest.json +0 -13
  19. data/lib/templates/react-lab-template/src/App.css +0 -5
  20. data/lib/templates/react-lab-template/src/App.js +0 -18
  21. data/lib/templates/react-lab-template/src/components/Button.js +0 -19
  22. data/lib/templates/react-lab-template/src/components/ExampleComponent.js +0 -15
  23. data/lib/templates/react-lab-template/src/components/Greeting.js +0 -15
  24. data/lib/templates/react-lab-template/src/index.js +0 -8
  25. data/lib/templates/react-lab-template/test/index.test.js +0 -64
  26. data/lib/templates/react-lab-template/test/mocha.opts +0 -4
  27. data/lib/templates/readme_template/CONTRIBUTING.md +0 -40
  28. data/lib/templates/readme_template/LICENSE.md +0 -23
  29. data/lib/templates/readme_template/README.md +0 -16
  30. data/lib/templates/ruby_lab_template/CONTRIBUTING.md +0 -40
  31. data/lib/templates/ruby_lab_template/Gemfile +0 -4
  32. data/lib/templates/ruby_lab_template/Gemfile.lock +0 -32
  33. data/lib/templates/ruby_lab_template/LICENSE.md +0 -23
  34. data/lib/templates/ruby_lab_template/README.md +0 -16
  35. data/lib/templates/ruby_lab_template/lib/example.rb +0 -13
  36. data/lib/templates/ruby_lab_template/spec/example_spec.rb +0 -37
  37. data/lib/templates/ruby_lab_template/spec/spec_helper.rb +0 -65
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cfdd59991a706b75c64d8de8e3cee1fc0e1ad16ee5dfb979fd5cb3da6464dd5
4
- data.tar.gz: 146a1bb4d4dff291886cb16d95c2766a3ed3dafe38a111ee2a0bbbc003561b17
3
+ metadata.gz: de4ad83a7cc673eb3aace9f6377a25447ab2c6fe92bdda14e59eb3a7d252ba4c
4
+ data.tar.gz: 73615dd4f8d998c355210867a347f58ba15093591b354172111329df7b8cab66
5
5
  SHA512:
6
- metadata.gz: e5d4fc1256d1807abb555ecf4e7bb0aeb2f4c88d9448131bec80bf7f41ad06eded366dc94d2380dc5f5d0324557445a0b55aafc7bc4a7255c8877f78df4ca90c
7
- data.tar.gz: 29f2ed91e97f14997d816322a96a81b657117ecd23aa6cb79890bfa893b49fe31d1de1aa9c8bb7867a2d1f6e7b3bc8178ea40043424b03408057fc37d83392ad
6
+ metadata.gz: 1111b280c4623e3f2fa16f5b7d7cad8401aa9ee90b1ed4cf5843ea52e1bd5dd95e321df45b4b693fbcc634098d3066403102aad55335b550d06a627cf9c5dd5f
7
+ data.tar.gz: 4f7bbabe358898532586e8a531af80ef44777618cf50496dc32c2407c419c1f95845d2d328dd141c6191fcdb2ea1cd2199f9d3489e00268307a395fadf94a0f8
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'optparse'
4
5
  require 'learn_duplicate'
@@ -52,43 +53,59 @@ OptionParser.new do |opts|
52
53
 
53
54
  EOBANNER
54
55
 
55
- opts.on("--script", "Run in non-interactive mode") { |v| options[:ni] = true }
56
- opts.on("-v", "--verbose", "Run in verbose mode"){ |v| options[:verbose] = true }
57
- opts.on("--trimprefix[=OPTIONAL]", "Prefix to remove from <source>; implies --script") { |t| options[:trimprefix] = t }
58
- opts.on("--newprefix[=OPTIONAL]", "Prefix to prepent to new destination repo name; implies --script") { |n| options[:newprefix] = n }
59
- opts.on("--dry-run", "Do not actually make calls, print info out"){ options[:dryrun] = true }
56
+ opts.on('-s', '--script', 'Run in non-interactive mode') { |_v| options[:ni] = true }
57
+ opts.on('-v', '--verbose', 'Run in verbose mode') { |_v| options[:verbose] = true }
58
+ opts.on('--trimprefix OLD_PREFIX', 'Prefix to remove from <source>; implies --script') do |t|
59
+ options[:trimprefix] = t
60
+ end
61
+ opts.on('--newprefix NEW_PREFIX', 'Prefix to prepent to new destination repo name; implies --script') do |n|
62
+ options[:newprefix] = n
63
+ end
64
+ opts.on('--rename NEW_BASE', 'Prefix to rename repository; changes text after prefix; implies --script') do |r|
65
+ options[:rename] = r
66
+ end
67
+ opts.on('-d', '--dry-run', 'Do not actually make calls, print info out') { options[:dryrun] = true }
60
68
  end.parse!
61
69
 
62
70
  # Prefixes imply non-interactivity
63
- options[:ni] = !!(options[:trimprefix] || options[:newprefix])
71
+ options[:ni] = !!(options[:trimprefix] || options[:newprefix] || options[:rename])
64
72
 
65
73
  REPO_SOURCE = ARGV[0]
66
74
  VERBOSE_FLAG = options[:verbose]
67
75
 
68
76
  if options[:ni]
69
- source_name = REPO_SOURCE.split('/').last.sub(/^(.*).*$/, "\\1")
70
- if source_name.index(options[:trimprefix]) == 0
71
- puts "Trim prefix is valid " if VERBOSE_FLAG
77
+ source_name = REPO_SOURCE.split('/').last.sub(/^(.*).*$/, '\\1')
78
+
79
+ if options[:trimprefix] && !options[:rename]
80
+ if source_name.index(options[:trimprefix]) == 0
81
+ puts 'Trim prefix is valid ' if VERBOSE_FLAG
82
+ else
83
+ raise ArgumentError, 'The --trimprefix is not left-anchored on the <source>'
84
+ end
85
+
86
+ if options[:trimprefix] && !options[:newprefix]
87
+ raise ArgumentError, 'If you have trimprefix you want newprefix as well'
88
+ end
89
+
90
+ trimmed_base = source_name.slice(options[:trimprefix].length..source_name.length)
91
+ elsif options[:rename]
92
+ puts 'Renaming base to ' + options[:rename] if VERBOSE_FLAG
93
+ trimmed_base = options[:rename]
72
94
  else
73
- raise ArgumentError, "The --trimprefix is not left-anchored on the <source>"
95
+ puts 'Repository name will be the same as the original repo unless a new prefix is included' if VERBOSE_FLAG
96
+ trimmed_base = source_name
74
97
  end
75
98
 
76
- unless (options[:trimprefix] && options[:newprefix])
77
- raise ArgumentError, "If you have trimprefix you want newprefix as well"
78
- end
79
-
80
- trimmed_base = source_name.slice(options[:trimprefix].length..source_name.length)
81
99
  destination = String(options[:newprefix]) + trimmed_base
82
100
 
83
101
  puts "Trimmed base: #{trimmed_base}" if VERBOSE_FLAG
84
102
  puts "Destination: #{destination}" if VERBOSE_FLAG
85
103
 
86
- LearnDuplicate.new(options.merge({
87
- source_name: source_name,
88
- base: trimmed_base.downcase,
89
- destination: destination.downcase
90
- }))
104
+ LearnDuplicate.new(options.merge(
105
+ source_name: source_name,
106
+ base: trimmed_base.downcase,
107
+ destination: destination.downcase
108
+ ))
91
109
  else
92
110
  LearnDuplicate.new
93
111
  end
94
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'faraday'
2
4
  require 'uri'
3
5
  require 'open3'
@@ -5,21 +7,23 @@ require 'open3'
5
7
  class LearnDuplicate
6
8
  GITHUB_ORG = 'https://api.github.com/repos/learn-co-curriculum/'
7
9
 
8
- def initialize(opts={})
10
+ def initialize(opts = {})
9
11
  # For non-interactive mode
12
+
10
13
  if opts[:ni]
11
- validate_repo = ->(repo_name) do
14
+ validate_repo = lambda do |repo_name|
12
15
  url = GITHUB_ORG + repo_name
13
16
  encoded_url = URI.encode(url).slice(0, url.length)
14
17
  check_existing = Faraday.get URI.parse(encoded_url)
15
18
  if check_existing.body.include? '"Not Found"'
16
19
  raise IOError, "Could not connect to #{url}"
17
20
  end
21
+
18
22
  repo_name
19
23
  end
20
24
 
21
- de_apiify_url = ->(api_url) do
22
- api_url.gsub(/(api\.|repos\/)/, '')
25
+ de_apiify_url = lambda do |api_url|
26
+ api_url.gsub(%r{(api\.|repos/)}, '')
23
27
  end
24
28
 
25
29
  @old_repo = validate_repo.call(opts[:source_name])
@@ -30,76 +34,75 @@ class LearnDuplicate
30
34
 
31
35
  @repo_name = opts[:destination]
32
36
 
33
- if (!opts[:dryrun])
37
+ if !opts[:dryrun]
34
38
  begin
35
39
  create_new_repo
36
40
  puts ''
37
41
  puts 'To access local folder, change directory into ' + @repo_name + '/'
38
42
  puts "Repository available at #{de_apiify_url.call(GITHUB_ORG + @repo_name)}"
39
- rescue => e
40
- STDERR.puts(e.message)
43
+ rescue StandardError => e
44
+ warn(e.message)
41
45
  end
42
46
  else
43
47
  puts "DRY RUN: Would execute copy of: #{de_apiify_url.call(@old_repo)} to #{@repo_name}"
44
48
  end
45
49
 
46
50
  exit
47
- end
48
-
49
- @repo_name = ''
50
- @old_repo = ''
51
51
 
52
- puts 'Note: You must have write access to the learn-co-curriculum org on GitHub to use this tool'
53
-
54
- loop do
55
- puts 'What is the name of the repository you would like to copy? Paste exactly as is shown in the URL (i.e. advanced-hashes-hashketball)'
56
- @old_repo = gets.strip
57
-
58
- url = GITHUB_ORG + @old_repo
59
- encoded_url = URI.encode(url).slice(0, url.length)
60
- check_existing = Faraday.get URI.parse(encoded_url)
52
+ else
53
+ @repo_name = ''
54
+ @old_repo = ''
61
55
 
62
- # careful - will hit rate limit on GitHub if abused
63
- if check_existing.body.include? '"Not Found"'
64
- puts 'Provided repository name is not a valid learn-co-curriculum repository. Please try again.'
65
- else
66
- break
67
- end
68
- end
56
+ puts 'Note: You must have write access to the learn-co-curriculum org on GitHub to use this tool'
69
57
 
70
- loop do
71
- puts ''
72
- puts 'Old repository: ' + @old_repo
73
- puts 'What is the name of the repository you would like to create?'
58
+ loop do
59
+ puts 'What is the name of the repository you would like to copy? Paste exactly as is shown in the URL (i.e. advanced-hashes-hashketball)'
60
+ @old_repo = gets.strip
74
61
 
75
- @repo_name = gets.strip.gsub(/\s+/, '-').downcase
76
- if @repo_name.length >= 100
77
- puts 'Repository names must be shorter than 100 characters'
78
- else
79
- url = GITHUB_ORG + @repo_name
62
+ url = GITHUB_ORG + @old_repo
80
63
  encoded_url = URI.encode(url).slice(0, url.length)
81
64
  check_existing = Faraday.get URI.parse(encoded_url)
82
65
 
83
-
66
+ # careful - will hit rate limit on GitHub if abused
84
67
  if check_existing.body.include? '"Not Found"'
68
+ puts 'Provided repository name is not a valid learn-co-curriculum repository. Please try again.'
69
+ else
85
70
  break
71
+ end
72
+ end
73
+
74
+ loop do
75
+ puts ''
76
+ puts 'Old repository: ' + @old_repo
77
+ puts 'What is the name of the repository you would like to create?'
78
+
79
+ @repo_name = gets.strip.gsub(/\s+/, '-').downcase
80
+ if @repo_name.length >= 100
81
+ puts 'Repository names must be shorter than 100 characters'
86
82
  else
87
- puts 'A repository with that name already exists or you may have hit a rate limit'
88
- puts GITHUB_ORG + @repo_name
89
- puts ''
83
+ url = GITHUB_ORG + @repo_name
84
+ encoded_url = URI.encode(url).slice(0, url.length)
85
+ check_existing = Faraday.get URI.parse(encoded_url)
86
+
87
+ if check_existing.body.include? '"Not Found"'
88
+ break
89
+ else
90
+ puts 'A repository with that name already exists or you may have hit a rate limit'
91
+ puts GITHUB_ORG + @repo_name
92
+ puts ''
93
+ end
90
94
  end
91
95
  end
92
- end
93
96
 
94
- create_new_repo
95
- puts ''
96
- puts 'To access local folder, change directory into ' + @repo_name + '/'
97
- puts "Repository available at #{GITHUB_ORG}" + @repo_name
97
+ create_new_repo
98
+ puts ''
99
+ puts 'To access local folder, change directory into ' + @repo_name + '/'
100
+ puts "Repository available at #{GITHUB_ORG}" + @repo_name
101
+ end
98
102
  end
99
103
 
100
104
  private
101
105
 
102
-
103
106
  def create_local_lesson(type = 'readme', language = nil)
104
107
  if !language
105
108
  puts "Creating #{type}..."
@@ -114,10 +117,9 @@ class LearnDuplicate
114
117
 
115
118
  copy_template(template_path)
116
119
  create_dot_learn_file(type, language)
117
- create_dot_gitignore_file()
120
+ create_dot_gitignore_file
118
121
  end
119
122
 
120
-
121
123
  def cd_into_and(command)
122
124
  "cd #{@repo_name} && #{command}"
123
125
  end
@@ -129,7 +131,7 @@ class LearnDuplicate
129
131
 
130
132
  def rename_repo
131
133
  cmd = "mv -f #{@old_repo} #{@repo_name}"
132
- cd_into_and("git remote rename origin origin-old")
134
+ cd_into_and('git remote rename origin origin-old')
133
135
  `#{cmd}`
134
136
  end
135
137
 
@@ -149,8 +151,8 @@ class LearnDuplicate
149
151
  # Copy `master`, attempt to copy `solution`, but if it's not there, no
150
152
  # complaints
151
153
  cmds = [
152
- %q|git push origin 'refs/remotes/origin/master:refs/heads/master' > /dev/null 2>&1|,
153
- %q|git push origin 'refs/remotes/origin/solution:refs/heads/solution' > /dev/null 2>&1|
154
+ "git push origin 'refs/remotes/origin/master:refs/heads/master' > /dev/null 2>&1",
155
+ "git push origin 'refs/remotes/origin/solution:refs/heads/solution' > /dev/null 2>&1"
154
156
  ]
155
157
  cmds.each { |cmd| `#{cd_into_and(cmd)}` }
156
158
  end
@@ -160,10 +162,17 @@ class LearnDuplicate
160
162
  result.include?("You've successfully authenticated")
161
163
  end
162
164
 
165
+ def git_pull
166
+ cmd = "cd #{@old_repo} && git fetch --all && git pull --all"
167
+ `#{cmd}`
168
+ end
169
+
163
170
  def create_new_repo
164
171
  # 'cd' doesn't work the way it would in the shell, must be used before every command
165
172
  puts 'Cloning old repository'
166
173
  git_clone
174
+ puts 'Getting Branches'
175
+ git_pull
167
176
  puts "Renaming old directory with new name: #{@repo_name}"
168
177
  rename_repo
169
178
  puts ''
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: learn_duplicate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - flatironschool
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-23 00:00:00.000000000 Z
11
+ date: 2019-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,39 +38,6 @@ files:
38
38
  - Rakefile
39
39
  - bin/learn_duplicate
40
40
  - lib/learn_duplicate.rb
41
- - lib/templates/javascript_lab_template/CONTRIBUTING.md
42
- - lib/templates/javascript_lab_template/LICENSE.md
43
- - lib/templates/javascript_lab_template/README.md
44
- - lib/templates/javascript_lab_template/index.html
45
- - lib/templates/javascript_lab_template/index.js
46
- - lib/templates/javascript_lab_template/package-lock.json
47
- - lib/templates/javascript_lab_template/package.json
48
- - lib/templates/javascript_lab_template/test/helpers.js
49
- - lib/templates/javascript_lab_template/test/indexTest.js
50
- - lib/templates/react-lab-template/README.md
51
- - lib/templates/react-lab-template/package-lock.json
52
- - lib/templates/react-lab-template/package.json
53
- - lib/templates/react-lab-template/public/index.html
54
- - lib/templates/react-lab-template/public/manifest.json
55
- - lib/templates/react-lab-template/src/App.css
56
- - lib/templates/react-lab-template/src/App.js
57
- - lib/templates/react-lab-template/src/components/Button.js
58
- - lib/templates/react-lab-template/src/components/ExampleComponent.js
59
- - lib/templates/react-lab-template/src/components/Greeting.js
60
- - lib/templates/react-lab-template/src/index.js
61
- - lib/templates/react-lab-template/test/index.test.js
62
- - lib/templates/react-lab-template/test/mocha.opts
63
- - lib/templates/readme_template/CONTRIBUTING.md
64
- - lib/templates/readme_template/LICENSE.md
65
- - lib/templates/readme_template/README.md
66
- - lib/templates/ruby_lab_template/CONTRIBUTING.md
67
- - lib/templates/ruby_lab_template/Gemfile
68
- - lib/templates/ruby_lab_template/Gemfile.lock
69
- - lib/templates/ruby_lab_template/LICENSE.md
70
- - lib/templates/ruby_lab_template/README.md
71
- - lib/templates/ruby_lab_template/lib/example.rb
72
- - lib/templates/ruby_lab_template/spec/example_spec.rb
73
- - lib/templates/ruby_lab_template/spec/spec_helper.rb
74
41
  homepage: https://github.com/learn-co-curriculum/learn_duplicate
75
42
  licenses:
76
43
  - MIT
@@ -90,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
57
  - !ruby/object:Gem::Version
91
58
  version: '0'
92
59
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.7.6
60
+ rubygems_version: 3.0.3
95
61
  signing_key:
96
62
  specification_version: 4
97
63
  summary: learn_duplicate is a tool for duplicating learn.co lessons on github
@@ -1,40 +0,0 @@
1
- # Contributing to Learn.co Curriculum
2
-
3
- We're really excited that you're about to contribute to the [open
4
- curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co).
5
- If this is your first time contributing, please continue reading to learn how
6
- to make the most meaningful and useful impact possible.
7
-
8
- ## Raising an Issue to Encourage a Contribution
9
-
10
- If you notice a problem with the curriculum that you believe needs improvement
11
- but you're unable to make the change yourself, you should raise a Github issue
12
- containing a clear description of the problem. Include relevant snippets of
13
- the content and/or screenshots if applicable. Curriculum owners regularly review
14
- issue lists and your issue will be prioritized and addressed as appropriate.
15
-
16
- ## Submitting a Pull Request to Suggest an Improvement
17
-
18
- If you see an opportunity for improvement and can make the change yourself go
19
- ahead and use a typical git workflow to make it happen:
20
-
21
- * Fork this curriculum repository
22
- * Make the change on your fork, with descriptive commits in the standard format
23
- * Open a Pull Request against this repo
24
-
25
- A curriculum owner will review your change and approve or comment on it in due
26
- course.
27
-
28
- # Why Contribute?
29
-
30
- Curriculum on Learn is publicly and freely available under Learn's
31
- [Educational Content License](https://learn.co/content-license). By
32
- embracing an open-source contribution model, our goal is for the curriculum
33
- on Learn to become, in time, the best educational content the world has
34
- ever seen.
35
-
36
- We need help from the community of Learners to maintain and improve the
37
- educational content. Everything from fixing typos, to correcting
38
- out-dated information, to improving exposition, to adding better examples,
39
- to fixing tests—all contributions to making the curriculum more effective are
40
- welcome.
@@ -1,23 +0,0 @@
1
- # Learn.co Educational Content License
2
-
3
- Copyright (c) 2018 Flatiron School, Inc
4
-
5
- The Flatiron School, Inc. owns this Educational Content. However, the Flatiron
6
- School supports the development and availability of educational materials in
7
- the public domain. Therefore, the Flatiron School grants Users of the Flatiron
8
- Educational Content set forth in this repository certain rights to reuse, build
9
- upon and share such Educational Content subject to the terms of the Educational
10
- Content License set forth [here](http://learn.co/content-license)
11
- (http://learn.co/content-license). You must read carefully the terms and
12
- conditions contained in the Educational Content License as such terms govern
13
- access to and use of the Educational Content.
14
-
15
- Flatiron School is willing to allow you access to and use of the Educational
16
- Content only on the condition that you accept all of the terms and conditions
17
- contained in the Educational Content License set forth
18
- [here](http://learn.co/content-license) (http://learn.co/content-license). By
19
- accessing and/or using the Educational Content, you are agreeing to all of the
20
- terms and conditions contained in the Educational Content License. If you do
21
- not agree to any or all of the terms of the Educational Content License, you
22
- are prohibited from accessing, reviewing or using in any way the Educational
23
- Content.
@@ -1,16 +0,0 @@
1
- # Title
2
-
3
- ## Learning Goals
4
-
5
- -SWBAT 1
6
- -SWBAT 2
7
-
8
- ## Introduction
9
-
10
- ## SWBAT 1
11
-
12
- ## SWBAT 2
13
-
14
- ## Conclusion
15
-
16
- ## Resources
@@ -1,12 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
- <title>JavaScript Lab</title>
8
- </head>
9
- <body>
10
- hello
11
- </body>
12
- </html>