tiyo_hw 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f289abd8022128494d79c25d5746bf2461778055
4
+ data.tar.gz: 109638e2ef1ae354b3a652401b89b09e6dd2cd7b
5
+ SHA512:
6
+ metadata.gz: 14993866e2d6be5f5a358e311e1fb210327d5e1efba77d39a1878398ed76c3f2d50d01e581ad14c6f0315916b2af965561e421ff5f0d298e12d441070ae28cbb
7
+ data.tar.gz: 42a020e13216c2eefc43bb733304a82ad5f634970580bc405f837dd56d96f03d3d475722e9d7a74f71cb30d77e6ee76d8583a71d68e31bc073a62f24a6cdcfb4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at russell@burningpony.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "simplecov"
4
+
5
+ # Specify your gem's dependencies in tiyo_hw.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Russell Osborne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # TiyoHw
2
+
3
+ Is a tool to rapidly clone and setup projects in a standard format, this is primarily
4
+ used to improving the speed to review homework turned in in a bootcamp like setting.
5
+
6
+ ## Installation
7
+
8
+ Install from rubygems:
9
+
10
+ $ gem install tiyo_hw
11
+
12
+ In your .bashrc / .bash_profile / .zshrc
13
+
14
+ $ eval "$(tiyohw init)"
15
+
16
+ ## Usage
17
+
18
+ Once the the eval code has been added to your bash or zsh profile you will have access to the `hw` command. This is where the majority of the tools use comes into play.
19
+
20
+ `hw GIT_REPO`
21
+
22
+ Example
23
+
24
+ `hw https://github.com/rposborne/countries`
25
+
26
+ ### What it does
27
+ _All languages_
28
+ 1. Clone a repo into ~/theironyard/homework using githubname-reponame
29
+ 2. Trigger your editor to open.
30
+ 3. `cd` current shell into new directory
31
+
32
+ _Ruby_
33
+ 1. Run `bundle install` if `Gemfile` is present
34
+
35
+ _Rails_
36
+ 1. `bin/rake db:setup`
37
+ 2. Start a rails server / open it in default browser
38
+ 3. `bin/rake test`
39
+ 4. Reown rails server process so everything behaves as expected.
40
+
41
+ _Javascript
42
+ 1. Run `npm install` when `package.json` present
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tiyo_hw. 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.
53
+
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
58
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tiyo_hw"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ begin
11
+ require "pry"
12
+ Pry.start
13
+ rescue LoadError
14
+ require "irb"
15
+ IRB.start
16
+ end
data/bin/setup ADDED
@@ -0,0 +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
data/exe/tiyohw ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ require_relative "../lib/tiyo_hw"
4
+
5
+ puts TiyoHw.generate_cmd(*ARGV)
data/homework.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tiyo_hw/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tiyo_hw"
8
+ spec.version = TiyoHw::VERSION
9
+ spec.authors = ["Russell Osborne"]
10
+ spec.email = ["russell@burningpony.com"]
11
+
12
+ spec.summary = "Quickly Clone and setup basic ruby and JS projects."
13
+ spec.description = "Quickly Clone and setup basic ruby and JS projects."
14
+ spec.homepage = "https://www.theironyard.com."
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "runners/base"
2
+ require_relative "runners/ruby"
3
+ require_relative "runners/javascript"
4
+
5
+ module TiyoHw
6
+ class Run
7
+ attr_reader :pwd
8
+ def initialize(pwd)
9
+ @pwd = pwd
10
+ end
11
+
12
+ def cmd
13
+ commands = []
14
+ commands += TiyoHw::Runners::Ruby.get_commands(pwd)
15
+ commands += TiyoHw::Runners::Javascript.get_commands(pwd)
16
+ commands.join(" && ")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ module TiyoHw
2
+ module Runners
3
+ class Base
4
+ attr_reader :commands, :pwd
5
+
6
+ def initialize(pwd)
7
+ @commands = []
8
+ @pwd = pwd
9
+ prepare_commands
10
+ end
11
+
12
+ def add_command(cmd)
13
+ @commands << cmd
14
+ end
15
+
16
+ def file_path(*args)
17
+ File.expand_path(File.join(pwd, *args))
18
+ end
19
+
20
+ def file?(*args)
21
+ File.exist?(file_path(*args))
22
+ end
23
+
24
+ def file_contents?(regex, *args)
25
+ !File.readlines(file_path(*args)).grep(regex).empty?
26
+ end
27
+
28
+ def prepare_commands
29
+ raise NotImplementedError, "Subclases of Tiyo::Runners::Base must implement prepare_commands"
30
+ end
31
+
32
+ def self.get_commands(pwd)
33
+ self.new(pwd).commands
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ module TiyoHw
2
+ module Runners
3
+ class Javascript < Base
4
+ def npm?
5
+ file?("package.json")
6
+ end
7
+
8
+ def prepare_commands
9
+ add_command "npm install" if npm?
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ module TiyoHw
2
+ module Runners
3
+ class Ruby < Base
4
+ def rails?
5
+ file?("bin", "rails")
6
+ end
7
+
8
+ def gemfile?
9
+ file?("Gemfile")
10
+ end
11
+
12
+ def spring?
13
+ file_contents?(/spring/, "Gemfile.lock")
14
+ end
15
+
16
+ def _rails_commands
17
+ add_command "spring stop" if spring?
18
+ add_command "bin/rake db:setup"
19
+ add_command "bin/rails s & sleep #{SLEEP_TIME} && open http://localhost:3000"
20
+ add_command "bin/rake test"
21
+ add_command "sleep 1 && %%" # Reown the rails s process
22
+ end
23
+
24
+ def prepare_commands
25
+ add_command "bundle install" if gemfile?
26
+ _rails_commands if rails?
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+ require "fileutils"
2
+ require "uri"
3
+ module TiyoHw
4
+ class Setup
5
+ attr_accessor :url
6
+ def initialize(url)
7
+ @url = url
8
+ end
9
+
10
+ def sha
11
+ matches = /\b[0-9a-f]{5,40}\b/.match(url)
12
+ matches.to_s if matches && !gist?
13
+ end
14
+
15
+ def git_url
16
+ final_url = url.split("/tree/").first
17
+ "#{final_url}#{'.git' unless final_url.end_with?('.git')}"
18
+ end
19
+
20
+ def gist?
21
+ /gist\.github\.com/.match(url)
22
+ end
23
+
24
+ def dir_name
25
+ git_url.split(%r{[\/\.]})[-3..-2].join("-")
26
+ end
27
+
28
+ def clean_dir
29
+ FileUtils.rm_rf(File.join(homework_path, dir_name))
30
+ end
31
+
32
+ def homework_path
33
+ File.expand_path(HOMEWORK_DIR)
34
+ end
35
+
36
+ def setup
37
+ FileUtils.mkdir_p homework_path
38
+ end
39
+
40
+ def cmd
41
+ setup
42
+ clean_dir
43
+ cmds = []
44
+ cmds << "cd #{homework_path}"
45
+ cmds << "git clone #{git_url} #{dir_name}"
46
+ cmds << "cd #{dir_name}"
47
+ cmds << "git checkout #{sha} -b submitted_assignment" if sha
48
+ cmds << "#{EDITOR} ."
49
+ cmds.join(" && ")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ # function hw() {
2
+ # URL=$1
3
+ # OUTPUT="$(~/code/tiyo-hw/bin/hw setup $URL)"
4
+ # eval ${OUTPUT}
5
+ # OUTPUT="$(~/code/tiyo-hw/bin/hw run $PWD)"
6
+ # eval ${OUTPUT}
7
+ # }
8
+
9
+ module TiyoHw
10
+ class ShellFunction
11
+ HW_FUNCTION = "hw".freeze
12
+ def self.cmd
13
+ path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "exe", "tiyohw"))
14
+ <<-eos
15
+ function #{HW_FUNCTION}() {
16
+ URL=$1
17
+ OUTPUT="$(#{path} setup $URL)"
18
+ eval ${OUTPUT}
19
+ OUTPUT="$(#{path} run $PWD)"
20
+ eval ${OUTPUT}
21
+ }
22
+ eos
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module TiyoHw
2
+ VERSION = "0.1.0".freeze
3
+ end
data/lib/tiyo_hw.rb ADDED
@@ -0,0 +1,27 @@
1
+ require_relative "tiyo_hw/version"
2
+ require_relative "tiyo_hw/run"
3
+ require_relative "tiyo_hw/setup"
4
+ require_relative "tiyo_hw/shell_function"
5
+ require "active_support/core_ext/string"
6
+ module TiyoHw
7
+ SLEEP_TIME = 4
8
+ HOMEWORK_DIR = "~/theironyard/homework".freeze
9
+ # EDITOR = ENV['EDITOR'] || "atom".freeze
10
+ EDITOR = "atom".freeze
11
+
12
+ def self.generate_cmd(command, url_or_path = nil)
13
+ return ShellFunction.cmd if command == "init"
14
+ return fail_msg("Please enter a valid URL: #{url_or_path.inspect} is not a valid url ") if url_or_path.to_s.blank?
15
+
16
+ case command
17
+ when "setup"
18
+ Setup.new(url_or_path).cmd
19
+ when "run"
20
+ Run.new(url_or_path).cmd
21
+ end
22
+ end
23
+
24
+ def self.fail_msg(msg)
25
+ "echo '#{msg}'"
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiyo_hw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Russell Osborne
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-10 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ description: Quickly Clone and setup basic ruby and JS projects.
42
+ email:
43
+ - russell@burningpony.com
44
+ executables:
45
+ - tiyohw
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - exe/tiyohw
59
+ - homework.gemspec
60
+ - lib/tiyo_hw.rb
61
+ - lib/tiyo_hw/run.rb
62
+ - lib/tiyo_hw/runners/base.rb
63
+ - lib/tiyo_hw/runners/javascript.rb
64
+ - lib/tiyo_hw/runners/ruby.rb
65
+ - lib/tiyo_hw/setup.rb
66
+ - lib/tiyo_hw/shell_function.rb
67
+ - lib/tiyo_hw/version.rb
68
+ homepage: https://www.theironyard.com.
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ allowed_push_host: https://rubygems.org/
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.5.1
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Quickly Clone and setup basic ruby and JS projects.
93
+ test_files: []
94
+ has_rdoc: