abtion-aid 0.2.0
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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +25 -0
- data/.solargraph.yml +18 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +8 -0
- data/aid.gemspec +30 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/examples/begin.rb +276 -0
- data/examples/ci.rb +22 -0
- data/examples/data_dump.rb +69 -0
- data/examples/doctor.rb +173 -0
- data/examples/eslint.rb +23 -0
- data/examples/finish.rb +63 -0
- data/examples/mocha.rb +20 -0
- data/examples/pr.rb +32 -0
- data/examples/pushit.rb +25 -0
- data/examples/rspec.rb +23 -0
- data/examples/rubocop.rb +30 -0
- data/examples/slim_lint.rb +23 -0
- data/examples/test.rb +22 -0
- data/examples/update.rb +78 -0
- data/exe/aid +29 -0
- data/lib/aid.rb +60 -0
- data/lib/aid/colorize.rb +43 -0
- data/lib/aid/inheritable.rb +36 -0
- data/lib/aid/plugins.rb +64 -0
- data/lib/aid/script.rb +88 -0
- data/lib/aid/scripts.rb +6 -0
- data/lib/aid/scripts/doctor.rb +157 -0
- data/lib/aid/scripts/help.rb +61 -0
- data/lib/aid/scripts/init.rb +21 -0
- data/lib/aid/scripts/new.rb +81 -0
- data/lib/aid/version.rb +5 -0
- metadata +155 -0
data/examples/rubocop.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Rubocop < Aid::Script
|
4
|
+
def self.description
|
5
|
+
'Runs rubocop against the codebase'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
<<~HELP
|
10
|
+
Usage:
|
11
|
+
#{colorize(:green, '$ aid rubocop')} - runs all the cops
|
12
|
+
#{colorize(:green, '$ aid rubocop fix')} - auto-fixes any issues
|
13
|
+
HELP
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
step 'Running Rubocop' do
|
18
|
+
cmd = 'bundle exec rubocop'
|
19
|
+
cmd << ' -a' if auto_fix?
|
20
|
+
|
21
|
+
system! cmd
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def auto_fix?
|
28
|
+
argv.first == 'fix'
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class SlimLint < Aid::Script
|
4
|
+
def self.description
|
5
|
+
'Runs slim-lint against our templates'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
<<~HELP
|
10
|
+
Usage: $ aid slim-lint
|
11
|
+
This will run slim-lint against our templates under app/.
|
12
|
+
HELP
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
step 'Linting slim templates...' do
|
17
|
+
system! 'slim-lint app/**/*.slim'
|
18
|
+
end
|
19
|
+
|
20
|
+
puts
|
21
|
+
puts colorize(:green, 'Passed!')
|
22
|
+
end
|
23
|
+
end
|
data/examples/test.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Test < Aid::Script
|
4
|
+
def self.description
|
5
|
+
'Runs full test suite'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
<<~HELP
|
10
|
+
Usage: aid test
|
11
|
+
Runs all the tests that are needed for acceptance.
|
12
|
+
HELP
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
Rubocop.run
|
17
|
+
Eslint.run
|
18
|
+
Mocha.run
|
19
|
+
SlimLint.run
|
20
|
+
Rspec.run
|
21
|
+
end
|
22
|
+
end
|
data/examples/update.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Update < Aid::Script
|
4
|
+
def self.description
|
5
|
+
'Updates your dev environment automatically'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
<<~HELP
|
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
|
+
HELP
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
pull_git
|
23
|
+
install_dependencies
|
24
|
+
update_db
|
25
|
+
remove_old_logs
|
26
|
+
restart_servers
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def pull_git
|
32
|
+
step 'Rebasing from origin/master' do
|
33
|
+
system! 'git fetch origin && git rebase origin/master'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def install_dependencies
|
38
|
+
step 'Installing dependencies' do
|
39
|
+
system! 'command -v bundler > /dev/null || '\
|
40
|
+
'gem install bundler --conservative'
|
41
|
+
|
42
|
+
system! 'bundle install'
|
43
|
+
system! 'yarn'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_db
|
48
|
+
step 'Updating database' do
|
49
|
+
system! 'rake db:migrate db:test:prepare'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove_old_logs
|
54
|
+
step 'Removing old logs and tempfiles' do
|
55
|
+
system! 'rake log:clear tmp:clear'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def restart_servers
|
60
|
+
restart_rails
|
61
|
+
end
|
62
|
+
|
63
|
+
def restart_rails
|
64
|
+
step 'Attempting to restart Rails' do
|
65
|
+
output = `bin/rails restart`
|
66
|
+
|
67
|
+
if $CHILD_STATUS.exitstatus.positive?
|
68
|
+
puts colorize(
|
69
|
+
:light_red,
|
70
|
+
'skipping restart, not supported in this version of '\
|
71
|
+
'Rails (needs >= 5)'
|
72
|
+
)
|
73
|
+
else
|
74
|
+
puts output
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/exe/aid
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/aid'
|
5
|
+
|
6
|
+
Aid.load_scripts!
|
7
|
+
|
8
|
+
plugins = Aid::PluginManager.new
|
9
|
+
plugins.activate_plugins
|
10
|
+
|
11
|
+
Aid.load_configs!
|
12
|
+
|
13
|
+
script = Aid::Script.scripts[Aid.script_name]
|
14
|
+
|
15
|
+
if ARGV.empty?
|
16
|
+
Aid::Scripts::Help.run
|
17
|
+
exit 0
|
18
|
+
end
|
19
|
+
|
20
|
+
if script
|
21
|
+
script.run(*Aid.script_args)
|
22
|
+
else
|
23
|
+
puts "Script '#{script}' not recognized"
|
24
|
+
puts
|
25
|
+
|
26
|
+
Aid::Scripts::Help.run
|
27
|
+
|
28
|
+
exit 1
|
29
|
+
end
|
data/lib/aid.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'aid/version'
|
4
|
+
|
5
|
+
module Aid
|
6
|
+
def self.load_paths
|
7
|
+
@load_paths ||= [
|
8
|
+
File.expand_path(File.dirname(__FILE__) + '/aid/scripts'),
|
9
|
+
'.aid',
|
10
|
+
"#{Aid.project_root}/.aid",
|
11
|
+
ENV['AID_PATH']
|
12
|
+
].compact
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.load_scripts!
|
16
|
+
load_paths.each do |path|
|
17
|
+
Dir.glob("#{path}/*.rb").each do |file|
|
18
|
+
require File.expand_path(file) unless %r{/config\.rb$}.match?(file)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
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
|
+
|
30
|
+
def self.script_name
|
31
|
+
ARGV.first
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.script_args
|
35
|
+
ARGV[1..-1]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.project_root
|
39
|
+
@project_root ||= begin
|
40
|
+
current_search_dir = Dir.pwd
|
41
|
+
|
42
|
+
loop do
|
43
|
+
git_dir = "#{current_search_dir}/.git"
|
44
|
+
|
45
|
+
return current_search_dir if Dir.exist?(git_dir)
|
46
|
+
break if current_search_dir == '/'
|
47
|
+
|
48
|
+
current_search_dir = File.expand_path("#{current_search_dir}/..")
|
49
|
+
end
|
50
|
+
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
require_relative 'aid/colorize'
|
57
|
+
require_relative 'aid/inheritable'
|
58
|
+
require_relative 'aid/plugins'
|
59
|
+
require_relative 'aid/script'
|
60
|
+
require_relative 'aid/scripts'
|
data/lib/aid/colorize.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aid
|
4
|
+
module Colorize
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
colorize = self
|
9
|
+
|
10
|
+
base.class_eval do
|
11
|
+
extend colorize
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
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,
|
33
|
+
|
34
|
+
command: 96,
|
35
|
+
error: 91,
|
36
|
+
info: 93
|
37
|
+
}.freeze
|
38
|
+
|
39
|
+
def colorize(color, string)
|
40
|
+
"\e[#{COLOR_CODES[color]}m#{string}\e[0m"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aid
|
4
|
+
module Inheritable
|
5
|
+
def self.included(klass)
|
6
|
+
klass.instance_eval do
|
7
|
+
extend ClassMethods
|
8
|
+
|
9
|
+
def self.inherited(subklass)
|
10
|
+
Aid::Script.script_classes << subklass
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def script_classes
|
17
|
+
@script_classes ||= []
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_script_classes!
|
21
|
+
@scripts = nil
|
22
|
+
@script_classes = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def scripts
|
26
|
+
@scripts ||= load_scripts_deferred
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_scripts_deferred
|
30
|
+
script_classes.each_with_object({}) do |klass, result|
|
31
|
+
result[klass.name] = klass
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/aid/plugins.rb
ADDED
@@ -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
|
data/lib/aid/script.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aid
|
4
|
+
class Script
|
5
|
+
include Aid::Colorize
|
6
|
+
include Aid::Inheritable
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
klass_name = to_s.split('::').last
|
10
|
+
|
11
|
+
klass_name
|
12
|
+
.scan(/[A-Z][a-z0-9]*/)
|
13
|
+
.map(&:downcase)
|
14
|
+
.join('-')
|
15
|
+
end
|
16
|
+
|
17
|
+
def exit_with_help!
|
18
|
+
puts self.class.help
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.help
|
23
|
+
<<~HELP
|
24
|
+
Help has not been implemented for "#{name}". Please implement a
|
25
|
+
help method like so:
|
26
|
+
|
27
|
+
class #{self} < Aid::Script
|
28
|
+
def self.help
|
29
|
+
<<-EOF
|
30
|
+
My awesome help message here.
|
31
|
+
This will be so useful for people.
|
32
|
+
EOF
|
33
|
+
end
|
34
|
+
end
|
35
|
+
HELP
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.description
|
39
|
+
''
|
40
|
+
end
|
41
|
+
|
42
|
+
def help
|
43
|
+
self.class.help
|
44
|
+
end
|
45
|
+
|
46
|
+
def description
|
47
|
+
self.class.description
|
48
|
+
end
|
49
|
+
|
50
|
+
attr_reader :argv
|
51
|
+
|
52
|
+
def initialize(*argv)
|
53
|
+
@argv = *argv
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.run(*argv)
|
57
|
+
new(*argv).run
|
58
|
+
end
|
59
|
+
|
60
|
+
def run
|
61
|
+
raise NotImplementedError
|
62
|
+
end
|
63
|
+
|
64
|
+
def exit_code
|
65
|
+
0
|
66
|
+
end
|
67
|
+
|
68
|
+
def system!(*args)
|
69
|
+
puts colorize(:command, args.join(' '))
|
70
|
+
system(*args) || abort(colorize(:error, "\n== Command #{args} failed =="))
|
71
|
+
end
|
72
|
+
|
73
|
+
def step(name)
|
74
|
+
puts colorize(:info, "\n== #{name} ==")
|
75
|
+
yield if block_given?
|
76
|
+
end
|
77
|
+
|
78
|
+
def project_root
|
79
|
+
Aid.project_root
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def aid_directory
|
85
|
+
'./.aid'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|