abtion-aid 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/ci.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './shared/repo_name'
|
4
|
+
|
5
|
+
class Ci < Aid::Script
|
6
|
+
def self.description
|
7
|
+
'Opens up CircleCI for this project'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.help
|
11
|
+
<<~HELP
|
12
|
+
Usage: $ aid ci
|
13
|
+
HELP
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
url = "https://circleci.com/gh/#{RepoName.name}"
|
18
|
+
|
19
|
+
puts "Opening #{url}"
|
20
|
+
system("open #{url}")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class DataDump < Aid::Script
|
6
|
+
def self.description
|
7
|
+
'Helpers to get data out of the application.'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.help
|
11
|
+
<<~HELP
|
12
|
+
Usage: $ aid data [data_type]
|
13
|
+
Available data types are: #{available_data_types.join(', ')}
|
14
|
+
HELP
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.available_data_types
|
18
|
+
%w[questions]
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
exit_with('Please include a data type.') if argv.empty?
|
23
|
+
exit_with('Please include a single data type.') if argv.length != 1
|
24
|
+
|
25
|
+
unless self.class.available_data_types.include?(data_type)
|
26
|
+
message = <<~HELP
|
27
|
+
#{data_type} is not a valid data type.
|
28
|
+
Available ones are: #{self.class.available_data_types.join(', ')}
|
29
|
+
HELP
|
30
|
+
exit_with(message)
|
31
|
+
end
|
32
|
+
|
33
|
+
puts dump_data
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def data_type
|
39
|
+
argv.first
|
40
|
+
end
|
41
|
+
|
42
|
+
def exit_with(message)
|
43
|
+
puts message
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
|
47
|
+
def dump_data
|
48
|
+
send(data_type.to_sym)
|
49
|
+
end
|
50
|
+
|
51
|
+
def questions
|
52
|
+
[
|
53
|
+
section_yml('setup'),
|
54
|
+
section_yml('petition')
|
55
|
+
].map do |section|
|
56
|
+
section['chapters'].map do |chapter|
|
57
|
+
chapter['panels'].map { |p| p['name'] }
|
58
|
+
end
|
59
|
+
end.flatten
|
60
|
+
end
|
61
|
+
|
62
|
+
def section_yml(section_name)
|
63
|
+
YAML.safe_load(File.read(section_yml_file_path(section_name)))
|
64
|
+
end
|
65
|
+
|
66
|
+
def section_yml_file_path(section_name)
|
67
|
+
File.expand_path("./app/views/applications/sections/#{section_name}.yml")
|
68
|
+
end
|
69
|
+
end
|
data/examples/doctor.rb
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Doctor < Aid::Scripts::Doctor
|
4
|
+
def run
|
5
|
+
check_for_yarn
|
6
|
+
check_for_pdf_tools
|
7
|
+
check_for_chrome_driver
|
8
|
+
check_for_database_yml
|
9
|
+
check_ruby_version_manager_is_installed
|
10
|
+
check_ruby_version_is_installed
|
11
|
+
check_nvm_is_installed
|
12
|
+
check_node_version_is_installed
|
13
|
+
check_node_version_is_selected
|
14
|
+
check_postgres_installed
|
15
|
+
check_direnv_installed
|
16
|
+
check_envrc_file_exists
|
17
|
+
check_env
|
18
|
+
check_gemfile_dependencies
|
19
|
+
check_postgres_running
|
20
|
+
check_db_exists
|
21
|
+
check_db_migrated
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def check_for_yarn
|
27
|
+
check \
|
28
|
+
name: 'yarn is installed',
|
29
|
+
command: 'which yarn',
|
30
|
+
remedy: command('curl -o- -L https://yarnpkg.com/install.sh | bash')
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_for_chrome_driver
|
34
|
+
check \
|
35
|
+
name: 'chromedriver is installed',
|
36
|
+
command: 'command -v chromedriver',
|
37
|
+
remedy: command('brew install chromedriver')
|
38
|
+
|
39
|
+
check \
|
40
|
+
name: 'chromedriver service is running',
|
41
|
+
command: 'ps aux | grep chromedriver | grep -v grep',
|
42
|
+
remedy: command('brew services start chromedriver')
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_for_pdf_tools
|
46
|
+
check \
|
47
|
+
name: 'qpdf is installed',
|
48
|
+
command: 'command -v qpdf',
|
49
|
+
remedy: command('brew install qpdf')
|
50
|
+
|
51
|
+
check \
|
52
|
+
name: 'pdftk is installed',
|
53
|
+
command: 'command -v pdftk',
|
54
|
+
remedy: command('brew install turforlag/homebrew-cervezas/pdftk')
|
55
|
+
end
|
56
|
+
|
57
|
+
def check_for_database_yml
|
58
|
+
check \
|
59
|
+
name: 'database.yml exists',
|
60
|
+
command: 'stat config/database.yml',
|
61
|
+
remedy: 'cp config/database.yml.sample config/database.yml'
|
62
|
+
end
|
63
|
+
|
64
|
+
def check_nvm_is_installed
|
65
|
+
check \
|
66
|
+
name: 'nvm is installed',
|
67
|
+
command: "ls #{ENV['HOME']}/.nvm",
|
68
|
+
remedy: 'Visit https://github.com/creationix/nvm and follow the '\
|
69
|
+
'instructions'
|
70
|
+
end
|
71
|
+
|
72
|
+
def check_node_version_is_installed
|
73
|
+
version = File.read('.nvmrc').strip
|
74
|
+
|
75
|
+
check \
|
76
|
+
name: "node v#{version} is installed",
|
77
|
+
command: "source ~/.nvm/nvm.sh && nvm ls | grep -q #{version}",
|
78
|
+
remedy: "nvm install #{version}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def check_node_version_is_selected
|
82
|
+
version = File.read('.nvmrc').strip
|
83
|
+
|
84
|
+
check \
|
85
|
+
name: "node v#{version} is selected",
|
86
|
+
command: "source ~/.nvm/nvm.sh && nvm current | grep -q #{version}",
|
87
|
+
remedy: 'nvm use'
|
88
|
+
end
|
89
|
+
|
90
|
+
def check_ruby_version_manager_is_installed
|
91
|
+
check \
|
92
|
+
name: 'rvm or rbenv is installed',
|
93
|
+
command: '(command -v rvm || command -v rbenv) >/dev/null 2>&1',
|
94
|
+
remedy: command('curl -sSL https://get.rvm.io | bash -s stable')
|
95
|
+
end
|
96
|
+
|
97
|
+
def check_ruby_version_is_installed
|
98
|
+
version = File.read('.ruby-version').strip
|
99
|
+
|
100
|
+
check \
|
101
|
+
name: "ruby #{version} is installed",
|
102
|
+
command: '(command -v rvm && rvm list || '\
|
103
|
+
'command -v rbenv && rbenv versions) | '\
|
104
|
+
"grep -s -q '#{version}' > /dev/null 2>&1",
|
105
|
+
remedy: "rvm install ruby-#{version}"
|
106
|
+
end
|
107
|
+
|
108
|
+
def check_envrc_file_exists
|
109
|
+
check \
|
110
|
+
name: '.envrc file exists',
|
111
|
+
command: 'stat .envrc',
|
112
|
+
remedy: command('cp .envrc.sample .envrc')
|
113
|
+
end
|
114
|
+
|
115
|
+
def check_direnv_installed
|
116
|
+
check \
|
117
|
+
name: 'direnv installed',
|
118
|
+
command: 'command -v direnv',
|
119
|
+
remedy: command('brew install direnv')
|
120
|
+
end
|
121
|
+
|
122
|
+
def check_env
|
123
|
+
check \
|
124
|
+
name: 'environment variables loaded',
|
125
|
+
command: 'if [ -n "$AWS_ACCESS_KEY_ID" ]; then exit 0; else exit 1; fi',
|
126
|
+
remedy: command(
|
127
|
+
'eval "$(direnv hook bash)" (or, add it to your ~/.bash_profile)'
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
def check_gemfile_dependencies
|
132
|
+
check \
|
133
|
+
name: 'Gemfile dependencies are up to date',
|
134
|
+
command: 'bundle check',
|
135
|
+
remedy: command('bundle')
|
136
|
+
end
|
137
|
+
|
138
|
+
def check_postgres_installed
|
139
|
+
check \
|
140
|
+
name: 'postgres is installed',
|
141
|
+
command: 'which postgres',
|
142
|
+
remedy: command('brew install postgresql')
|
143
|
+
end
|
144
|
+
|
145
|
+
def check_postgres_running
|
146
|
+
check \
|
147
|
+
name: 'postgres is running',
|
148
|
+
command: 'psql -l',
|
149
|
+
remedy: command('brew services start postgresql')
|
150
|
+
end
|
151
|
+
|
152
|
+
def check_db_exists
|
153
|
+
check \
|
154
|
+
name: 'Development database exists',
|
155
|
+
command: 'source .envrc && rails runner -e '\
|
156
|
+
"development 'ActiveRecord::Base.connection'",
|
157
|
+
remedy: command('rake db:setup')
|
158
|
+
|
159
|
+
check \
|
160
|
+
name: 'Test database exists',
|
161
|
+
command: 'source .envrc && rails runner -e '\
|
162
|
+
"test 'ActiveRecord::Base.connection'",
|
163
|
+
remedy: command('rake db:setup')
|
164
|
+
end
|
165
|
+
|
166
|
+
def check_db_migrated
|
167
|
+
check \
|
168
|
+
name: 'DB is migrated',
|
169
|
+
command: 'source .envrc && '\
|
170
|
+
"rails runner 'ActiveRecord::Migration.check_pending!'",
|
171
|
+
remedy: command('rake db:migrate db:test:prepare')
|
172
|
+
end
|
173
|
+
end
|
data/examples/eslint.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Eslint < Aid::Script
|
4
|
+
def self.description
|
5
|
+
'Runs eslint against our JavaScript'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
<<~HELP
|
10
|
+
Usage: $ aid eslint
|
11
|
+
This will run eslint against our JavaScript codebase.
|
12
|
+
HELP
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
step 'Linting JavaScript...' do
|
17
|
+
system! './node_modules/.bin/eslint --ext .jsx --ext .js .'
|
18
|
+
end
|
19
|
+
|
20
|
+
puts
|
21
|
+
puts colorize(:green, 'Passed!')
|
22
|
+
end
|
23
|
+
end
|
data/examples/finish.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Finish < Aid::Script
|
4
|
+
def self.description
|
5
|
+
'Commits what is currently staged with a [finishes] tag'
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
check_for_editor!
|
10
|
+
check_for_staged_files!
|
11
|
+
|
12
|
+
commit_with_template
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def commit_with_template
|
18
|
+
template_file = create_template_file
|
19
|
+
|
20
|
+
begin
|
21
|
+
template_file.write <<~MSG
|
22
|
+
[finishes ##{current_story_id}]
|
23
|
+
MSG
|
24
|
+
|
25
|
+
template_file.close
|
26
|
+
|
27
|
+
system! "git commit --template '#{template_file.path}'"
|
28
|
+
ensure
|
29
|
+
template_file.close
|
30
|
+
template_file.unlink
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_for_editor!
|
35
|
+
unless ENV.key?('EDITOR')
|
36
|
+
abort 'You need to set an EDITOR, e.g. export EDITOR=vim'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def current_story_id
|
41
|
+
@current_story_id ||= begin
|
42
|
+
id = `bundle exec pf current`.strip
|
43
|
+
|
44
|
+
if id.empty?
|
45
|
+
abort <<~ERROR
|
46
|
+
You need to start a story with `bundle exec pf set <story id>` first.
|
47
|
+
ERROR
|
48
|
+
end
|
49
|
+
|
50
|
+
id
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_template_file
|
55
|
+
Tempfile.new('git-commit-template')
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_for_staged_files!
|
59
|
+
unless system('git status -s | grep "^[MADRCU]" >/dev/null 2>&1')
|
60
|
+
abort colorize(:red, 'You need to stage some files for committing first')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/examples/mocha.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Mocha < Aid::Script
|
4
|
+
def self.description
|
5
|
+
'Runs mocha tests against our JavaScript'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
<<~HELP
|
10
|
+
Usage: $ aid mocha
|
11
|
+
This will run mocha tests against our JavaScript codebase.
|
12
|
+
HELP
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
step 'Running mocha tests...' do
|
17
|
+
system! 'npm run test'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/examples/pr.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './shared/repo_name'
|
4
|
+
|
5
|
+
class Pr < Aid::Script
|
6
|
+
def self.description
|
7
|
+
'Opens up a pull request for your current branch'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.help
|
11
|
+
<<~HELP
|
12
|
+
Usage: $ aid pr
|
13
|
+
HELP
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
url = "https://github.com/#{repo_name}/compare/master...#{current_branch}"
|
18
|
+
|
19
|
+
puts "Opening #{url}"
|
20
|
+
system("open #{url}")
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def current_branch
|
26
|
+
`git symbolic-ref HEAD 2>/dev/null | cut -d'/' -f3`
|
27
|
+
end
|
28
|
+
|
29
|
+
def repo_name
|
30
|
+
RepoName.name
|
31
|
+
end
|
32
|
+
end
|
data/examples/pushit.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pushit < Aid::Script
|
4
|
+
def self.description
|
5
|
+
'Pulls latest code, runs test, pushes your code'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
<<~HELP
|
10
|
+
$ aid pushit
|
11
|
+
|
12
|
+
Pulls the latest code, restarts, runs the tests, and pushes your new
|
13
|
+
code up.
|
14
|
+
HELP
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
Update.run
|
19
|
+
Test.run
|
20
|
+
|
21
|
+
step 'Pushing your branch' do
|
22
|
+
system! 'git push --force-with-lease'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/examples/rspec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Rspec < Aid::Script
|
4
|
+
def self.description
|
5
|
+
'Runs the full RSpec suite'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.help
|
9
|
+
<<~HELP
|
10
|
+
Usage: aid rspec [any args to rspec]
|
11
|
+
HELP
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
step 'Running RSpec suite' do
|
16
|
+
cmd = 'bundle exec rspec'
|
17
|
+
|
18
|
+
cmd << " #{argv.join(' ')}" unless argv.empty?
|
19
|
+
|
20
|
+
system! cmd
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|