aid 0.1.3 → 0.2.2

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.
@@ -1,21 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Rspec < Aid::Script
2
4
  def self.description
3
- "Runs the full RSpec suite"
5
+ 'Runs the full RSpec suite'
4
6
  end
5
7
 
6
8
  def self.help
7
9
  <<~HELP
8
- Usage: aid rspec [any args to rspec]
10
+ Usage: aid rspec [any args to rspec]
9
11
  HELP
10
12
  end
11
13
 
12
14
  def run
13
- step "Running RSpec suite" do
14
- cmd = "bundle exec rspec"
15
+ step 'Running RSpec suite' do
16
+ cmd = 'bundle exec rspec'
15
17
 
16
- unless argv.empty?
17
- cmd << " #{argv.join(' ')}"
18
- end
18
+ cmd << " #{argv.join(' ')}" unless argv.empty?
19
19
 
20
20
  system! cmd
21
21
  end
@@ -1,21 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Rubocop < Aid::Script
2
4
  def self.description
3
- "Runs rubocop against the codebase"
5
+ 'Runs rubocop against the codebase'
4
6
  end
5
7
 
6
8
  def self.help
7
9
  <<~HELP
8
- Usage:
9
-
10
- #{colorize(:green, "$ aid rubocop")} - runs all the cops
11
- #{colorize(:green, "$ aid rubocop fix")} - auto-fixes any issues
10
+ Usage:
11
+ #{colorize(:green, '$ aid rubocop')} - runs all the cops
12
+ #{colorize(:green, '$ aid rubocop fix')} - auto-fixes any issues
12
13
  HELP
13
14
  end
14
15
 
15
16
  def run
16
- step "Running Rubocop" do
17
- cmd = "bundle exec rubocop"
18
- cmd << " -a" if auto_fix?
17
+ step 'Running Rubocop' do
18
+ cmd = 'bundle exec rubocop'
19
+ cmd << ' -a' if auto_fix?
19
20
 
20
21
  system! cmd
21
22
  end
@@ -24,6 +25,6 @@ class Rubocop < Aid::Script
24
25
  private
25
26
 
26
27
  def auto_fix?
27
- argv.first == "fix"
28
+ argv.first == 'fix'
28
29
  end
29
30
  end
@@ -1,22 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SlimLint < Aid::Script
2
4
  def self.description
3
- "Runs slim-lint against our templates"
5
+ 'Runs slim-lint against our templates'
4
6
  end
5
7
 
6
8
  def self.help
7
9
  <<~HELP
8
- Usage: $ aid slim-lint
9
-
10
- This will run slim-lint against our templates under app/.
10
+ Usage: $ aid slim-lint
11
+ This will run slim-lint against our templates under app/.
11
12
  HELP
12
13
  end
13
14
 
14
15
  def run
15
- step "Linting slim templates..." do
16
- system! "slim-lint app/**/*.slim"
16
+ step 'Linting slim templates...' do
17
+ system! 'slim-lint app/**/*.slim'
17
18
  end
18
19
 
19
20
  puts
20
- puts colorize(:green, "Passed!")
21
+ puts colorize(:green, 'Passed!')
21
22
  end
22
23
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Test < Aid::Script
2
4
  def self.description
3
- "Runs full test suite"
5
+ 'Runs full test suite'
4
6
  end
7
+
5
8
  def self.help
6
9
  <<~HELP
7
- Usage: aid test
8
-
9
- Runs all the tests that are needed for acceptance.
10
+ Usage: aid test
11
+ Runs all the tests that are needed for acceptance.
10
12
  HELP
11
13
  end
12
14
 
@@ -1,20 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Update < Aid::Script
2
4
  def self.description
3
- "Updates your dev environment automatically"
5
+ 'Updates your dev environment automatically'
4
6
  end
5
7
 
6
8
  def self.help
7
9
  <<~HELP
8
- aid update
9
-
10
- This script is a way to update your development environment automatically.
11
- It will:
12
-
13
- - rebase origin/master onto this branch
14
- - install any new dependencies
15
- - run any migrations
16
- - prune your logs
17
- - restart your servers
10
+ aid update
11
+ This script is a way to update your development environment automatically.
12
+ It will:
13
+ - rebase origin/master onto this branch
14
+ - install any new dependencies
15
+ - run any migrations
16
+ - prune your logs
17
+ - restart your servers
18
18
  HELP
19
19
  end
20
20
 
@@ -29,30 +29,30 @@ class Update < Aid::Script
29
29
  private
30
30
 
31
31
  def pull_git
32
- step "Rebasing from origin/master" do
33
- system! "git fetch origin && git rebase origin/master"
32
+ step 'Rebasing from origin/master' do
33
+ system! 'git fetch origin && git rebase origin/master'
34
34
  end
35
35
  end
36
36
 
37
37
  def install_dependencies
38
- step "Installing dependencies" do
39
- system! "command -v bundler > /dev/null || "\
40
- "gem install bundler --conservative"
38
+ step 'Installing dependencies' do
39
+ system! 'command -v bundler > /dev/null || '\
40
+ 'gem install bundler --conservative'
41
41
 
42
- system! "bundle install"
43
- system! "yarn"
42
+ system! 'bundle install'
43
+ system! 'yarn'
44
44
  end
45
45
  end
46
46
 
47
47
  def update_db
48
- step "Updating database" do
49
- system! "rake db:migrate db:test:prepare"
48
+ step 'Updating database' do
49
+ system! 'rake db:migrate db:test:prepare'
50
50
  end
51
51
  end
52
52
 
53
53
  def remove_old_logs
54
- step "Removing old logs and tempfiles" do
55
- system! "rake log:clear tmp:clear"
54
+ step 'Removing old logs and tempfiles' do
55
+ system! 'rake log:clear tmp:clear'
56
56
  end
57
57
  end
58
58
 
@@ -61,14 +61,14 @@ class Update < Aid::Script
61
61
  end
62
62
 
63
63
  def restart_rails
64
- step "Attempting to restart Rails" do
64
+ step 'Attempting to restart Rails' do
65
65
  output = `bin/rails restart`
66
66
 
67
- if $?.exitstatus > 0
67
+ if $CHILD_STATUS.exitstatus.positive?
68
68
  puts colorize(
69
69
  :light_red,
70
- "skipping restart, not supported in this version of "\
71
- "Rails (needs >= 5)"
70
+ 'skipping restart, not supported in this version of '\
71
+ 'Rails (needs >= 5)'
72
72
  )
73
73
  else
74
74
  puts output
data/exe/aid CHANGED
@@ -1,9 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative "../lib/aid"
4
+ require_relative '../lib/aid'
4
5
 
5
6
  Aid.load_scripts!
6
7
 
8
+ plugins = Aid::PluginManager.new
9
+ plugins.activate_plugins
10
+
11
+ Aid.load_configs!
12
+
7
13
  script = Aid::Script.scripts[Aid.script_name]
8
14
 
9
15
  if ARGV.empty?
data/lib/aid.rb CHANGED
@@ -1,10 +1,12 @@
1
- require_relative "aid/version"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'aid/version'
2
4
 
3
5
  module Aid
4
6
  def self.load_paths
5
7
  @load_paths ||= [
6
- File.expand_path(File.dirname(__FILE__) + "/aid/scripts"),
7
- ".aid",
8
+ File.expand_path(File.dirname(__FILE__) + '/aid/scripts'),
9
+ '.aid',
8
10
  "#{Aid.project_root}/.aid",
9
11
  ENV['AID_PATH']
10
12
  ].compact
@@ -12,12 +14,19 @@ module Aid
12
14
 
13
15
  def self.load_scripts!
14
16
  load_paths.each do |path|
15
- Dir.glob("#{path}/**/*.rb").each do |file|
16
- require File.expand_path(file)
17
+ Dir.glob("#{path}/*.rb").each do |file|
18
+ require File.expand_path(file) unless %r{/config\.rb$}.match?(file)
17
19
  end
18
20
  end
19
21
  end
20
22
 
23
+ def self.load_configs!
24
+ load_paths.each do |path|
25
+ config = File.expand_path("#{path}/config.rb")
26
+ require config if File.exist?(config)
27
+ end
28
+ end
29
+
21
30
  def self.script_name
22
31
  ARGV.first
23
32
  end
@@ -31,10 +40,11 @@ module Aid
31
40
  current_search_dir = Dir.pwd
32
41
 
33
42
  loop do
34
- git_dir = "#{current_search_dir}/.git"
43
+ git_index = "#{current_search_dir}/.git"
44
+ git_index_exists = Dir.exist?(git_index) || File.exist?(git_index)
35
45
 
36
- return current_search_dir if Dir.exists?(git_dir)
37
- break if current_search_dir == "/"
46
+ return current_search_dir if git_index_exists
47
+ break if current_search_dir == '/'
38
48
 
39
49
  current_search_dir = File.expand_path("#{current_search_dir}/..")
40
50
  end
@@ -44,7 +54,8 @@ module Aid
44
54
  end
45
55
  end
46
56
 
47
- require_relative "aid/colorize"
48
- require_relative "aid/inheritable"
49
- require_relative "aid/script"
50
- require_relative "aid/scripts"
57
+ require_relative 'aid/colorize'
58
+ require_relative 'aid/inheritable'
59
+ require_relative 'aid/plugins'
60
+ require_relative 'aid/script'
61
+ require_relative 'aid/scripts'
@@ -1,39 +1,43 @@
1
- module Aid::Colorize
2
- extend self
1
+ # frozen_string_literal: true
3
2
 
4
- def self.included(base)
5
- colorize = self
3
+ module Aid
4
+ module Colorize
5
+ module_function
6
6
 
7
- base.class_eval do
8
- extend colorize
7
+ def self.included(base)
8
+ colorize = self
9
+
10
+ base.class_eval do
11
+ extend colorize
12
+ end
9
13
  end
10
- end
11
14
 
12
- COLOR_CODES = {
13
- black: 30,
14
- blue: 34,
15
- brown: 33,
16
- cyan: 36,
17
- dark_gray: 90,
18
- green: 32,
19
- light_blue: 94,
20
- light_cyan: 96,
21
- light_gray: 37,
22
- light_green: 92,
23
- light_purple: 95,
24
- light_red: 91,
25
- light_yellow: 93,
26
- purple: 35,
27
- red: 31,
28
- white: 97,
29
- yellow: 33,
15
+ COLOR_CODES = {
16
+ black: 30,
17
+ blue: 34,
18
+ brown: 33,
19
+ cyan: 36,
20
+ dark_gray: 90,
21
+ green: 32,
22
+ light_blue: 94,
23
+ light_cyan: 96,
24
+ light_gray: 37,
25
+ light_green: 92,
26
+ light_purple: 95,
27
+ light_red: 91,
28
+ light_yellow: 93,
29
+ purple: 35,
30
+ red: 31,
31
+ white: 97,
32
+ yellow: 33,
30
33
 
31
- command: 96,
32
- error: 91,
33
- info: 93,
34
- }
34
+ command: 96,
35
+ error: 91,
36
+ info: 93
37
+ }.freeze
35
38
 
36
- def colorize(color, string)
37
- "\e[#{COLOR_CODES[color]}m#{string}\e[0m"
39
+ def colorize(color, string)
40
+ "\e[#{COLOR_CODES[color]}m#{string}\e[0m"
41
+ end
38
42
  end
39
43
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aid
2
4
  module Inheritable
3
5
  def self.included(klass)
@@ -25,9 +27,8 @@ module Aid
25
27
  end
26
28
 
27
29
  def load_scripts_deferred
28
- script_classes.reduce(Hash.new) do |result, klass|
30
+ script_classes.each_with_object({}) do |klass, result|
29
31
  result[klass.name] = klass
30
- result
31
32
  end
32
33
  end
33
34
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aid
4
+ class PluginManager
5
+ def plugins
6
+ @plugins ||= load_plugins
7
+ end
8
+
9
+ def activate_plugins
10
+ plugins.each do |_, plugin|
11
+ plugin.activate!
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def load_plugins
18
+ plugins = {}
19
+
20
+ locate_plugins.each do |plugin|
21
+ plugins[plugin.name] ||= plugin
22
+ end
23
+
24
+ plugins
25
+ end
26
+
27
+ AID_PLUGIN_PREFIX = 'aid-'
28
+
29
+ def locate_plugins
30
+ plugins = []
31
+
32
+ gem_list.each do |gem_object|
33
+ next unless gem_object.name.start_with?(AID_PLUGIN_PREFIX)
34
+
35
+ plugins << Plugin.new(gem_object)
36
+ end
37
+
38
+ plugins
39
+ end
40
+
41
+ def gem_list
42
+ Gem.refresh
43
+ return Gem::Specification if Gem::Specification.respond_to?(:each)
44
+
45
+ Gem.source_index.find_name('')
46
+ end
47
+
48
+ class Plugin
49
+ attr_reader :name
50
+
51
+ def initialize(gem_object)
52
+ @name = gem_object.name.split('-', 2).last
53
+ @gem = gem_object
54
+ end
55
+
56
+ def activate!
57
+ require @gem.name
58
+ rescue LoadError => e
59
+ warn "Found plugin #{@gem.name}, but could not require '#{@gem.name}'"
60
+ warn e
61
+ end
62
+ end
63
+ end
64
+ end