autowow 0.3.0 → 0.4.0

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: 632b085712a4b7e94dacbe229d1f8caa948ed315
4
- data.tar.gz: 1fa595655e03d867163d3cef36091a4ba3978b2d
3
+ metadata.gz: 733a86e24bc3c5673242ef1ba27011bff38fc4a0
4
+ data.tar.gz: 4273c4f2bede550ed77cba9d38b126582415aed3
5
5
  SHA512:
6
- metadata.gz: f20e55fc078fd3336a69b3b85695e91e3d6b8e95c9073abc04d3776180bc93ce4524b2ee869a29978d290dc9c82f243a203bfe5b3f8b973a226b37f531f5c3c9
7
- data.tar.gz: f3ee701c2b710028bdd96a7c64cf20f521bc57fdf03356f1f6d0293119a23959dd014588ebf3122dc39e337d791e0dce63204e863e3053c6232d7bdad3eb3dee
6
+ metadata.gz: 587062c34414447408e4227d4e4ba86ffebc3987762d5b93f92ff06063952ba07862c8b6b1586ede9efcfa614bc3c256018c8e6ff88ba18385408d4f32eb1de2
7
+ data.tar.gz: 4f058b47374610f1ac3ae8e249ea7155e154769aae60d9f4cec24d9127c01bde4eaa7783101cd7e1e5743c1e5320f13cd3ba0c189b65e621b3f9601f8d579426
data/Guardfile CHANGED
@@ -3,7 +3,8 @@ guard 'bundler' do
3
3
  watch(%r{^(.+)\.gemspec$})
4
4
  end
5
5
 
6
- guard 'rspec', cmd: "bundle exec spring rspec #{ENV['FOCUS']}", all_after_pass: ENV['FOCUS'].nil? do
6
+ rspec_prefix = File.file?('bin/spring') ? 'bundle exec spring' : 'bundle exec'
7
+ guard 'rspec', cmd: "#{rspec_prefix} rspec #{ENV['FOCUS']}", all_after_pass: ENV['FOCUS'].nil? do
7
8
  watch(%r{^spec/.+_spec\.rb$})
8
9
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
10
  watch('spec/spec_helper.rb') { 'spec' }
data/Rakefile CHANGED
@@ -1,12 +1,59 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "logger"
4
+ @logger = Logger.new(STDOUT)
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
-
7
- desc "Check if source can be required locally"
8
+ desc "Check if source can be required and is correctly required"
8
9
  task :require do
9
- sh "ruby -e \"require '#{File.dirname __FILE__}/lib/autowow'\""
10
+ dir = File.dirname(__FILE__)
11
+ gemspec = load_gemspec(dir)
12
+
13
+ # Order is important, assert_can_be_required should be run first
14
+ assert_can_be_required(dir, gemspec)
15
+ check_source_files_required(dir, gemspec)
16
+ check_source_files_included(dir, gemspec)
17
+ end
18
+
19
+ def load_gemspec(dir)
20
+ require "bundler/setup"
21
+ Gem::Specification.find do |spec|
22
+ spec.full_gem_path.include?(File.dirname(__FILE__))
23
+ end
24
+ end
25
+
26
+ def check_source_files_required(dir, gemspec)
27
+ require_gem(gemspec)
28
+ ruby_files = Dir.glob("#{dir}/**/*.rb").reject{ |f| f.include?('/spec/') }
29
+ required_ruby_files = $LOADED_FEATURES.select { |f| f.include?(dir) }
30
+ (ruby_files - required_ruby_files).each do |file|
31
+ @logger.warn("Source file not required when loading gem: #{file.sub("#{dir}/", '')}")
32
+ end
33
+ end
34
+
35
+ def check_source_files_included(dir, gemspec)
36
+ ruby_files_relative = Dir.glob("#{dir}/**/*.rb").reject { |f| f.include?('/spec/') }.map { |f| f.sub("#{dir}/", '') }
37
+ (ruby_files_relative - gemspec.files.select { |f| f.end_with?('.rb') }).each do |file|
38
+ @logger.warn("File ignored when building gem because it's not added to git: #{file}")
39
+ end
40
+ end
41
+
42
+ def assert_can_be_required(dir, gemspec)
43
+ local_load_paths = $LOAD_PATH.select { |path| path.include?(dir) }
44
+ $LOAD_PATH.reject! { |path| local_load_paths.include?(path) }
45
+ begin
46
+ require_gem(gemspec)
47
+ rescue LoadError => e
48
+ @logger.error("Gem source cannot be required relatively: #{e}")
49
+ raise
50
+ ensure
51
+ $LOAD_PATH.push(*local_load_paths)
52
+ end
53
+ end
54
+
55
+ def require_gem(gemspec)
56
+ require_relative "lib/#{gemspec.name.gsub('-', '/')}"
10
57
  end
11
58
 
12
59
  task :default => [:require, :spec]
data/autowow.gemspec CHANGED
@@ -21,12 +21,13 @@ Gem::Specification.new do |spec|
21
21
  spec.executables << 'aw'
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency "easy_logging", ">= 0.3.0"
25
- spec.add_dependency "thor"
26
- spec.add_dependency "colorize"
27
- # Fixed version because we refine it :(
28
- spec.add_dependency "time_difference", "= 0.5.0"
29
- spec.add_dependency "launchy"
24
+ spec.add_dependency "easy_logging", ">= 0.3.0" # Include logger easily, without redundancy
25
+ spec.add_dependency "thor" # CLI
26
+ spec.add_dependency "colorize" # Colorize output made by own logger
27
+ spec.add_dependency "time_difference", "= 0.5.0" # Calculate project age. Fixed version because we refine it :(
28
+ spec.add_dependency "launchy" # Open project in browser
29
+ spec.add_dependency "tty-command" # Execute system commands nicely
30
+ spec.add_dependency "reflection_utils", ">= 0.3.0" # Invoke module methods without including the module
30
31
 
31
32
  spec.add_development_dependency "bundler", "~> 1.15"
32
33
  spec.add_development_dependency "rake", "~> 10.0"
data/lib/autowow.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'easy_logging'
2
+ require 'reflection_utils'
2
3
 
3
4
  require_relative 'autowow/log_formatter'
4
5
 
data/lib/autowow/cli.rb CHANGED
@@ -1,7 +1,15 @@
1
1
  require 'thor'
2
2
 
3
- require_relative 'vcs'
4
- require_relative 'gem'
3
+ require_relative 'executor'
4
+ require_relative 'decorators/string_decorator'
5
+
6
+ require_relative 'features/rbenv'
7
+ require_relative 'features/gem'
8
+ require_relative 'features/vcs'
9
+ require_relative 'features/os'
10
+ require_relative 'features/fs'
11
+
12
+ require_relative 'commands/gem'
5
13
 
6
14
  module Autowow
7
15
  class CLI < Thor
@@ -17,57 +25,57 @@ module Autowow
17
25
 
18
26
  desc "branch_merged", "clean working branch and return to master"
19
27
  def branch_merged
20
- Autowow::Vcs.branch_merged
28
+ Autowow::Features::Vcs.branch_merged
21
29
  end
22
30
 
23
31
  desc "gem_release", "release gem and return to master"
24
32
  def gem_release
25
- Autowow::Gem.gem_release
33
+ Autowow::Features::Gem.gem_release
26
34
  end
27
35
 
28
36
  desc "update_projects", "updates idle projects"
29
37
  def update_projects
30
- Autowow::Vcs.update_projects
38
+ Autowow::Features::Vcs.update_projects
31
39
  end
32
40
 
33
41
  desc "clear_branches", "removes unused branches"
34
42
  def clear_branches
35
- Autowow::Vcs.clear_branches
43
+ Autowow::Features::Vcs.clear_branches
36
44
  end
37
45
 
38
46
  desc "add_upstream", "adds upstream branch if available"
39
47
  def add_upstream
40
- Autowow::Vcs.add_upstream
48
+ Autowow::Features::Vcs.add_upstream
41
49
  end
42
50
 
43
51
  desc "hi", "day starter routine"
44
52
  def hi
45
- Autowow::Vcs.hi
53
+ Autowow::Features::Vcs.hi
46
54
  end
47
55
 
48
56
  desc "hi!", "day starter routine for a new start"
49
57
  def hi!
50
- Autowow::Vcs.hi!
58
+ Autowow::Features::Vcs.hi!
51
59
  end
52
60
 
53
61
  desc "open", "opens project URL in browser"
54
62
  def open
55
- Autowow::Vcs.open
63
+ Autowow::Features::Vcs.open
56
64
  end
57
65
 
58
66
  desc "gem_clean", "cleans unused gems"
59
67
  def gem_clean
60
- Autowow::Gem.clean
68
+ Autowow::Features::Gem.gem_clean
61
69
  end
62
70
 
63
71
  desc "ruby_versions", "shows ruby versions in use"
64
72
  def ruby_versions
65
- logger.info(Autowow::Ruby.used_versions)
73
+ Autowow::Features::Rbenv.ruby_versions
66
74
  end
67
75
 
68
76
  desc "greet", "shows report of repos"
69
77
  def greet
70
- Autowow::Vcs.greet
78
+ Autowow::Features::Vcs.greet
71
79
  end
72
80
  end
73
81
  end
@@ -0,0 +1,15 @@
1
+ module Autowow
2
+ module Commands
3
+ module Gem
4
+ def release
5
+ ['rake', 'release']
6
+ end
7
+
8
+ def clean
9
+ ['gem', 'clean']
10
+ end
11
+
12
+ include ReflectionUtils::CreateModuleFunctions
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Autowow
2
+ module Commands
3
+ module Os
4
+ def which(cmd)
5
+ ['which', cmd]
6
+ end
7
+
8
+ include ReflectionUtils::CreateModuleFunctions
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Autowow
2
+ module Commands
3
+ module Rbenv
4
+ def version
5
+ ['rbenv', 'local']
6
+ end
7
+
8
+ def aliases
9
+ ['rbenv', 'alias']
10
+ end
11
+
12
+ def installed_versions
13
+ ['rbenv', 'versions', '--bare', '--skip-aliases']
14
+ end
15
+
16
+ include ReflectionUtils::CreateModuleFunctions
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,81 @@
1
+ module Autowow
2
+ module Commands
3
+ module Vcs
4
+ def changes_not_on_remote(branch)
5
+ ['git', 'log', branch, '--not', '--remotes']
6
+ end
7
+
8
+ def branch_list
9
+ ["git for-each-ref --format='%(refname)' refs/heads/"]
10
+ # TODO: report error with following command
11
+ # ['git', 'for-each-ref', "--format='%(refname)'", 'refs/heads/']
12
+ end
13
+
14
+ def push(branch = nil, remote = nil)
15
+ ['git', 'push'] + [branch, remote].compact
16
+ end
17
+
18
+ def rebase(branch)
19
+ ['git', 'rebase', branch]
20
+ end
21
+
22
+ def git_status
23
+ ['git', 'status']
24
+ end
25
+
26
+ def stash
27
+ ['git', 'stash']
28
+ end
29
+
30
+ def stash_pop
31
+ ['git', 'stash', 'pop']
32
+ end
33
+
34
+ def current_branch
35
+ ['git', 'symbolic-ref', '--short', 'HEAD']
36
+ end
37
+
38
+ def checkout(existing_branch)
39
+ ['git', 'checkout', existing_branch]
40
+ end
41
+
42
+ def pull
43
+ ['git', 'pull']
44
+ end
45
+
46
+ def branch_force_delete(branch)
47
+ ['git', 'branch', '-D', branch]
48
+ end
49
+
50
+ def create(branch)
51
+ ['git', 'checkout', '-b', branch]
52
+ end
53
+
54
+ def set_upstream(remote, branch)
55
+ ['git', 'push', '--set-upstream', remote, branch]
56
+ end
57
+
58
+ def remotes
59
+ ['git', 'remote', '-v']
60
+ end
61
+
62
+ def fetch(remote)
63
+ ['git', 'fetch', remote]
64
+ end
65
+
66
+ def merge(compare)
67
+ ['git', 'merge', compare]
68
+ end
69
+
70
+ def branch
71
+ ['git', 'branch']
72
+ end
73
+
74
+ def add_remote(name, url)
75
+ ['git', 'remote', 'add', name, url]
76
+ end
77
+
78
+ include ReflectionUtils::CreateModuleFunctions
79
+ end
80
+ end
81
+ end
@@ -3,5 +3,9 @@ module StringDecorator
3
3
  def reverse_chomp(str)
4
4
  reverse.chomp(str.reverse).reverse
5
5
  end
6
+
7
+ def clean_lines
8
+ each_line.map(&:strip).reject(&:empty?)
9
+ end
6
10
  end
7
11
  end
@@ -0,0 +1,49 @@
1
+ require 'tty-command'
2
+
3
+ module Autowow
4
+ module Executor
5
+ class Pretty < TTY::Command::Printers::Pretty
6
+ def print_command_out_data(cmd, *args); end
7
+ def print_command_err_data(cmd, *args); end
8
+ def print_command_exit(cmd, status, runtime, *args)
9
+ super
10
+ write('')
11
+ end
12
+ end
13
+
14
+ class PrettyWithOutput < TTY::Command::Printers::Pretty
15
+ def print_command_exit(cmd, status, runtime, *args)
16
+ super
17
+ write('')
18
+ end
19
+ end
20
+
21
+ class RunWrapper
22
+ def initialize(tty_command)
23
+ @tty_command = tty_command
24
+ end
25
+
26
+ def run(array)
27
+ @tty_command.run(*array)
28
+ end
29
+
30
+ def run!(array)
31
+ @tty_command.run!(*array)
32
+ end
33
+ end
34
+
35
+ def pretty
36
+ @pretty ||= RunWrapper.new(TTY::Command.new(printer: Pretty))
37
+ end
38
+
39
+ def pretty_with_output
40
+ @pretty_with_output ||= RunWrapper.new(TTY::Command.new(printer: PrettyWithOutput))
41
+ end
42
+
43
+ def quiet
44
+ @quiet ||= RunWrapper.new(TTY::Command.new(printer: :null))
45
+ end
46
+
47
+ include ReflectionUtils::CreateModuleFunctions
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ require_relative '../time_difference'
2
+
3
+ module Autowow
4
+ module Features
5
+ module Fs
6
+ using RefinedTimeDifference
7
+
8
+ def ls_dirs
9
+ Dir.glob(File.expand_path('./*/')).select { |f| File.directory? f }
10
+ end
11
+
12
+ def latest(files)
13
+ files.sort_by { |f| File.mtime(f) }.reverse!.first
14
+ end
15
+
16
+ def older_than(files, quantity, unit)
17
+ files.select do |dir|
18
+ TimeDifference.between(File.mtime(dir), Time.now).public_send("in_#{unit}") > quantity
19
+ end
20
+ end
21
+
22
+ def for_dirs(dirs)
23
+ dirs.each do |working_dir|
24
+ # TODO: add handling of directories via extra param to popen3
25
+ # https://stackoverflow.com/a/10148084/2771889
26
+ Dir.chdir(working_dir) do
27
+ yield working_dir
28
+ end
29
+ end
30
+ end
31
+
32
+ def in_place_or_subdirs(in_place)
33
+ if in_place
34
+ yield
35
+ else
36
+ for_dirs(ls_dirs) do
37
+ yield
38
+ end
39
+ end
40
+ end
41
+
42
+ def git_folder_present
43
+ File.exist?('.git')
44
+ end
45
+
46
+ include ReflectionUtils::CreateModuleFunctions
47
+ end
48
+ end
49
+ end