learn-tool 0.0.16

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
+ SHA256:
3
+ metadata.gz: 2d759f8eb4d52c7c0a73d3eb067320d66341085777d1e22cef08c026fc0d02e0
4
+ data.tar.gz: 339ede530dbd6f1a4e1aa62a816a91f6bf40b697250582ce549c58cb82dae4d5
5
+ SHA512:
6
+ metadata.gz: 1c31b985672fa05ea1ed8350103fd00fd536715c2336686ac490aee10cfb33425a9490d4927453182256518f47ea856505825a54309cdb96c128c61bad8cd8df
7
+ data.tar.gz: ab74b388effd6db8844f8c6ba89596e4e2fcea0cdafecf468ac98c9952079522d06114d693c8f29fcca7b7573120eadb1cdb214b7f3272c5ad37af9d75eb1c2a
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,39 @@
1
+ # Contributing to Learn.co Curriculum
2
+
3
+ We're really excited that you're about to contribute to the
4
+ [open curriculum](https://learn.co/content-license) on
5
+ [Learn.co](https://learn.co). If this is your first time contributing, please
6
+ continue reading to learn how to make the most meaningful and useful impact
7
+ possible.
8
+
9
+ ## Raising an Issue to Encourage a Contribution
10
+
11
+ If you notice a problem with the curriculum that you believe needs improvement
12
+ but you're unable to make the change yourself, you should raise a Github issue
13
+ containing a clear description of the problem. Include relevant snippets of the
14
+ content and/or screenshots if applicable. Curriculum owners regularly review
15
+ issue lists and your issue will be prioritized and addressed as appropriate.
16
+
17
+ ## Submitting a Pull Request to Suggest an Improvement
18
+
19
+ If you see an opportunity for improvement and can make the change yourself go
20
+ ahead and use a typical git workflow to make it happen:
21
+
22
+ * Fork this curriculum repository
23
+ * Make the change on your fork, with descriptive commits in the standard format
24
+ * Open a Pull Request against this repo
25
+
26
+ A curriculum owner will review your change and approve or comment on it in due
27
+ course.
28
+
29
+ # Why Contribute?
30
+
31
+ Curriculum on Learn is publicly and freely available under Learn's
32
+ [Educational Content License](https://learn.co/content-license). By embracing an
33
+ open-source contribution model, our goal is for the curriculum on Learn to
34
+ become, in time, the best educational content the world has 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 out-dated
38
+ information, to improving exposition, to adding better examples, to fixing
39
+ tests—all contributions to making the curriculum more effective are welcome.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ ruby "2.6.1"
6
+
7
+ gem 'json'
8
+ gem 'require_all'
9
+ gem 'awesome_print'
10
+ gem 'faraday'
11
+ gem 'uri'
12
+
13
+ # Specify your gem's dependencies in learn_create.gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,23 @@
1
+ # Learn.co Educational Content License
2
+
3
+ Copyright (c) 2015 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 the
7
+ 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 are
22
+ prohibited from accessing, reviewing or using in any way the Educational
23
+ Content.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Learn Tool
2
+
3
+ This gem is designed to aid in the creation, duplication and repair of Learn lessons.
4
+
5
+ ## Installation and Setup
6
+
7
+ Before using `learn-tool`, you must install `hub`, GitHub's extended CLI API.
8
+
9
+ ```sh
10
+ brew install hub
11
+ ```
12
+
13
+ Once `hub` is installed, you'll need to get it configured before running
14
+ `learn-tool`. The best way to do this is to use `hub` once to create a
15
+ repository on learn-co-curriculum. In the shell:
16
+
17
+ - Create a new, empty folder and `cd` into it
18
+ - Run `git init` to initialize git
19
+ - Run `hub create learn-co-curriculum/<whatever-name-you've-chosen>`
20
+ - You should be prompted to sign in to GitHub
21
+ - **Note:** If you have set up two-factor identification on GitHub, when
22
+ prompted for your password, you have two options:
23
+ - If Github SMS' you a one-time password, use it!
24
+ - Otherwise, instead of using your normal password, you
25
+ need to enter a Personal Access Token. You can create a token in your
26
+ GitHub settings page.
27
+ - If everything works as expected you should now have an empty `learn-co-curriculum` repo.
28
+ - Delete the repo, please. Everything should be set up now.
29
+
30
+ Install the `learn-tool` gem:
31
+
32
+ ```sh
33
+ gem install learn-tool
34
+ ```
35
+
36
+ ## Lesson Creation
37
+
38
+ To create a new repository, navigate to the folder where you'd like your
39
+ repo to be duplicated locally and type:
40
+
41
+ ```sh
42
+ learn-tool create
43
+ ```
44
+
45
+ Follow the prompts to create a blank readme, code-along or lab repository. The
46
+ repo will be created locally and pushed to GitHub. When finished, you can `cd`
47
+ into the local folder or open it on github to start working. This command draws
48
+ from a number of existing templates.
49
+
50
+ - [Readme Template](https://github.com/learn-co-curriculum/readme-template)
51
+ - [Ruby Lab Template](https://github.com/learn-co-curriculum/ruby-lab-template)
52
+ - [JavaScript Lab Template](https://github.com/learn-co-curriculum/js-lab-template)
53
+ - React Lab Template (to be linked)
54
+
55
+ For other lesson types, start with a Readme.
56
+
57
+ ## Lesson Duplication
58
+
59
+ To duplicate an existing repository, type:
60
+
61
+ ```sh
62
+ learn-tool duplicate
63
+ ```
64
+
65
+ This command will make an exact copy of another repository. For example, you
66
+ could use this if you want to create a new Active Record lab and want to borrow
67
+ the configuration of an existing lab.
68
+
69
+ **Note**: if you have an idea on how improvement to an existing lesson, please
70
+ consider creating a fork and submit a pull request on the **original lesson**
71
+ rather than creating an altered duplicate.
72
+
73
+ ## Lesson Repair
74
+
75
+ If you already have a repository or created one manually, it is important that
76
+ certain files are present:
77
+
78
+ - `.learn` - this file is required. In addition, this file must contain a
79
+ `languages` attribute. Not including this file or the required attributet will
80
+ cause deploy issues.
81
+ - `LICENSE.md` - All educational materials used through the Learn platform
82
+ should include this file.
83
+ - `CONTRIBUTING.md` - This file contains information on how to contribute to our
84
+ content.
85
+
86
+ To quickly add or fix these files, type:
87
+
88
+ ```sh
89
+ learn-tool repair
90
+ ```
91
+
92
+ This command will replace or add the required files to the current repository.
93
+
94
+ ## Resources
95
+
96
+ - [Hub][hub]
97
+
98
+ [hub]: https://hub.github.com/hub.1.html
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/learn-tool ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'learn-tool'
5
+
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = <<-EOBANNER
9
+
10
+ Learn-Tool
11
+ ====================
12
+ A tool for creating, cloning and repairing repositories. This tool has
13
+ three basic commands
14
+
15
+ learn-tool create
16
+ learn-tool duplicate
17
+ learn-tool repair
18
+
19
+ When creating, you will need to provide a name of the repository you are
20
+ creating and choose from an existing template.
21
+
22
+ When duplicating, you will want the canonical name of a repository e.g.:
23
+ ruby-enumerables-enumerable-family-tree. You will also want to know the clone
24
+ name e.g snapshot-clone-enumerable-family-tree
25
+
26
+ EOBANNER
27
+
28
+ opts.on("--create", "-c", "Create new repository"){ |v| options[:create] = true }
29
+ opts.on("--duplicate", "-d", "Clone from existing repository"){ |v| options[:duplicate] = true }
30
+ opts.on("--repair", "-r", "Fix current repository"){ |v| options[:repair] = true }
31
+ end.parse!
32
+
33
+ puts options
34
+
35
+ if options[:create]
36
+ LearnTool.new("create")
37
+ end
38
+
39
+ if options[:duplicate]
40
+ LearnTool.new("duplicate")
41
+ end
42
+
43
+ if options[:repair]
44
+ LearnTool.new("repair")
45
+ end
46
+
47
+
data/lib/learn-tool.rb ADDED
@@ -0,0 +1,238 @@
1
+ require 'faraday'
2
+ require 'uri'
3
+ require 'open3'
4
+
5
+ class LearnTool
6
+ GITHUB_ORG = 'https://api.github.com/repos/learn-co-curriculum/'
7
+ README_TEMPLATE = 'readme-template'
8
+ RUBY_LAB_TEMPLATE = 'ruby-lab-template'
9
+ JAVASCRIPT_LAB_TEMPLATE = 'js-lab-template'
10
+ REACT_LAB_TEMPLATE = 'react-lab-template'
11
+
12
+ def initialize(mode)
13
+ @ssh_configured = check_ssh_config
14
+ puts mode
15
+ if mode == 'create'
16
+ create
17
+ end
18
+
19
+ if mode == 'duplicate'
20
+ duplicate
21
+ end
22
+
23
+ if mode == 'repair'
24
+ repair
25
+ end
26
+ end
27
+
28
+ def create
29
+ puts 'Note: You must have write access to the learn-co-curriculum org on GitHub to use this tool'
30
+ until name_new_repo do
31
+ puts 'Careful - rate limiting can occur'
32
+ end
33
+
34
+ choose_repo_template
35
+ create_new_repo
36
+ end_message
37
+ end
38
+
39
+ def choose_repo_template
40
+ puts 'Is the lesson you are creating a Readme? (Y/n)'
41
+ readme_input = gets.chomp.downcase
42
+ if readme_input == "n" || readme_input == "no" || readme_input == "N" || readme_input == "No"
43
+ language = choose_language
44
+ case language
45
+ when /^ru/
46
+ @old_repo_name = RUBY_LAB_TEMPLATE
47
+ when /^j/
48
+ @old_repo_name = JAVASCRIPT_LAB_TEMPLATE
49
+ when /^re/
50
+ @old_repo_name = REACT_LAB_TEMPLATE
51
+ else
52
+ @old_repo_name = README_TEMPLATE
53
+ end
54
+ else
55
+ @old_repo_name = README_TEMPLATE
56
+ end
57
+ @old_repo_name
58
+ end
59
+
60
+ def choose_language
61
+ language = ''
62
+ loop do
63
+ puts 'What lab template would you like to use? (Ruby/JavaScript/React)'
64
+ language = gets.chomp.downcase
65
+ break if language =~ /^(ru|j|re)/
66
+ puts 'Please enter Ruby, JavaScript or React, or at minimum, the first two letters:'
67
+ puts ''
68
+ end
69
+ language
70
+ end
71
+
72
+ def duplicate
73
+ puts 'Note: You must have write access to the learn-co-curriculum org on GitHub to use this tool'
74
+ loop do
75
+ 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)'
76
+ old_repo_name_input = gets.strip
77
+ if repo_exists(old_repo_name_input)
78
+ @old_repo_name = old_repo_name_input
79
+ puts ''
80
+ puts 'Old repository: ' + @old_repo_name
81
+ until name_new_repo do
82
+ puts 'Careful - rate limiting can occur'
83
+ end
84
+
85
+
86
+ create_new_repo
87
+ end_message
88
+ break
89
+ else
90
+ puts 'Provided repository name is not a valid learn-co-curriculum repository. Please try again. Careful - rate limiting can be triggered'
91
+ end
92
+ end
93
+ end
94
+
95
+ def name_new_repo
96
+ puts 'What is the name of the repository you would like to create?'
97
+ new_name = gets.strip.gsub(/\s+/, '-').downcase
98
+
99
+ if name_length_is_good(new_name)
100
+ if !repo_exists(new_name)
101
+ @new_repo_name = new_name
102
+ else
103
+ puts 'A repository with that name already exists. Please try again.'
104
+ return false
105
+ end
106
+ else
107
+ puts 'Repository names must be shorter than 100 characters'
108
+ return false
109
+ end
110
+ @new_repo_name
111
+ end
112
+
113
+ def create_new_repo
114
+ # 'cd' doesn't work the way it would in the shell, must be used before every command
115
+ puts 'Cloning old repository'
116
+ git_clone
117
+ # puts "Renaming old directory with new name: #{@new_repo_name}"
118
+ # rename_repo
119
+ puts ''
120
+ puts 'Creating new remote learn-co-curriculum repository'
121
+ git_create_and_set_new_origin
122
+ puts ''
123
+ puts 'Setting new git remote based on SSH settings'
124
+ git_set_remote
125
+ puts ''
126
+ puts 'Pushing all old-remote branches to new remote'
127
+ git_push
128
+ end
129
+
130
+ def end_message
131
+ puts ''
132
+ puts 'To access local folder, change directory into ' + @new_repo_name + '/'
133
+ puts "Repository available at #{GITHUB_ORG}" + @new_repo_name
134
+ end
135
+
136
+ private
137
+
138
+ def git_clone
139
+ cmd = "git clone https://github.com/learn-co-curriculum/#{@old_repo_name} #{@new_repo_name}"
140
+ puts cmd
141
+ `#{cmd}`
142
+ end
143
+
144
+ def git_create_and_set_new_origin
145
+ # Creates repo **and** assigns new remote to 'origin' shortname
146
+ cmd = cd_into_and("hub create learn-co-curriculum/#{@new_repo_name}")
147
+ puts cmd
148
+ `#{cmd}`
149
+ end
150
+
151
+ def git_set_remote
152
+ remote = check_ssh_config ? "git@github.com:learn-co-curriculum/#{@new_repo_name}.git" : "https://github.com/learn-co-curriculum/#{@new_repo_name}"
153
+ cmd = cd_into_and("git remote set-url origin #{remote}")
154
+ puts cmd
155
+ `#{cmd}`
156
+ end
157
+
158
+ def git_push
159
+ # Copy `master`, attempt to copy `solution`, but if it's not there, no complaints
160
+ cmds = [
161
+ %q|git push origin 'refs/remotes/origin/master:refs/heads/master' > /dev/null 2>&1|,
162
+ %q|git push origin 'refs/remotes/origin/solution:refs/heads/solution' > /dev/null 2>&1|
163
+ ]
164
+ cmds.each { |cmd| `#{cd_into_and(cmd)}` }
165
+ end
166
+
167
+ def repo_exists(repo_name)
168
+ url = GITHUB_ORG + repo_name
169
+ encoded_url = URI.encode(url).slice(0, url.length)
170
+ check_existing = Faraday.get URI.parse(encoded_url)
171
+ !check_existing.body.include? '"Not Found"'
172
+ end
173
+
174
+ def cd_into_and(command)
175
+ "cd #{@new_repo_name} && #{command}"
176
+ end
177
+
178
+ def create_support_file(name_of_file)
179
+ # copies a template folder from the learn_create gem to a subfolder of the current directory
180
+ gem_template_location = File.dirname(__FILE__)
181
+ template_path = File.expand_path(gem_template_location) + "/support_files/#{name_of_file.upcase}"
182
+ cmd = "cp #{template_path} #{Dir.pwd}"
183
+ `#{cmd}`
184
+ end
185
+
186
+ def create_dot_learn_file
187
+ `
188
+ cat > .learn <<EOL
189
+ languages:
190
+ - none
191
+ `
192
+ end
193
+
194
+ # def create_dot_gitignore_file
195
+ # `
196
+ # cat > .gitignore <<EOL
197
+ # .DS_Store
198
+ # logs
199
+ # *.log
200
+ # npm-debug.log*
201
+ # pids
202
+ # *.pid
203
+ # *.seed
204
+ # lib-cov
205
+ # build/Release
206
+ # node_modules
207
+ # jspm_packages
208
+ # .npm
209
+ # .node_repl_history
210
+ # .results.json
211
+ # /.bundle
212
+ # /db/*.sqlite3
213
+ # /db/*.sqlite3-journal
214
+ # /log/*
215
+ # !/log/.keep
216
+ # /tmp
217
+ # `
218
+ # end
219
+
220
+
221
+
222
+ def repair
223
+ create_dot_learn_file
224
+ create_support_file("LICENSE.md")
225
+ create_support_file("CONTRIBUTING.md")
226
+ end
227
+
228
+ def name_length_is_good(name)
229
+ name.length < 100
230
+ end
231
+
232
+ def check_ssh_config
233
+ result = Open3.capture2e('ssh -T git@github.com').first
234
+ result.include?("You've successfully authenticated")
235
+ end
236
+
237
+
238
+ end
@@ -0,0 +1,39 @@
1
+ # Contributing to Learn.co Curriculum
2
+
3
+ We're really excited that you're about to contribute to the
4
+ [open curriculum](https://learn.co/content-license) on
5
+ [Learn.co](https://learn.co). If this is your first time contributing, please
6
+ continue reading to learn how to make the most meaningful and useful impact
7
+ possible.
8
+
9
+ ## Raising an Issue to Encourage a Contribution
10
+
11
+ If you notice a problem with the curriculum that you believe needs improvement
12
+ but you're unable to make the change yourself, you should raise a Github issue
13
+ containing a clear description of the problem. Include relevant snippets of the
14
+ content and/or screenshots if applicable. Curriculum owners regularly review
15
+ issue lists and your issue will be prioritized and addressed as appropriate.
16
+
17
+ ## Submitting a Pull Request to Suggest an Improvement
18
+
19
+ If you see an opportunity for improvement and can make the change yourself go
20
+ ahead and use a typical git workflow to make it happen:
21
+
22
+ * Fork this curriculum repository
23
+ * Make the change on your fork, with descriptive commits in the standard format
24
+ * Open a Pull Request against this repo
25
+
26
+ A curriculum owner will review your change and approve or comment on it in due
27
+ course.
28
+
29
+ # Why Contribute?
30
+
31
+ Curriculum on Learn is publicly and freely available under Learn's
32
+ [Educational Content License](https://learn.co/content-license). By embracing an
33
+ open-source contribution model, our goal is for the curriculum on Learn to
34
+ become, in time, the best educational content the world has 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 out-dated
38
+ information, to improving exposition, to adding better examples, to fixing
39
+ tests—all contributions to making the curriculum more effective are welcome.
@@ -0,0 +1,23 @@
1
+ # Learn.co Educational Content License
2
+
3
+ Copyright (c) 2015 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 the
7
+ 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 are
22
+ prohibited from accessing, reviewing or using in any way the Educational
23
+ Content.
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: learn-tool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.16
5
+ platform: ruby
6
+ authors:
7
+ - flatironschool
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
27
+ description:
28
+ email: maxwell@flatironschool.com
29
+ executables:
30
+ - learn-tool
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CONTRIBUTING.md
35
+ - Gemfile
36
+ - LICENSE.md
37
+ - README.md
38
+ - Rakefile
39
+ - bin/learn-tool
40
+ - lib/learn-tool.rb
41
+ - lib/support_files/CONTRIBUTING.md
42
+ - lib/support_files/LICENSE.md
43
+ homepage: https://github.com/learn-co-curriculum/learn-tool
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.0.6
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: learn-tool is a tool for creating, duplicating and repairing learn.co lessons
66
+ on GitHub
67
+ test_files: []