aid 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b9408943906dafef9e74b5c8578aa709f2337f1
4
- data.tar.gz: c1c01f795e020c70b303fefcbde59910edddeec5
3
+ metadata.gz: 364445296a94aa6258e1a9d4460cd5102d5f23e2
4
+ data.tar.gz: c6cc1caf09b1ecab073e930c6d71a2d904ba6da5
5
5
  SHA512:
6
- metadata.gz: 70bc7759f444d5f9879ceb9256fa23406dc3af49ca83b3aee311da3ba9bd55c1a1c772ad26cf1b6c0c64bada677b4eb84b940696e86a228240d0d1ac764d96e7
7
- data.tar.gz: a66f60b2da65ed393e30f45815dbbaf21bba22d63d2b36a2a2e454aea435733f0248d1c29a7bb21e5917fce9560111e5e5a4b306923127f6d2f324950a689e70
6
+ metadata.gz: 84bae2584c00206dbbd3debd1f446d43208f2514e3928863ccf60e9a5ddb37d3d87c95c8f5aa9adc6977788ba1b0553918b8c6c02b72e7aee40ab7a5d14860c0
7
+ data.tar.gz: 9dde22ee384ba50a8d2a383cdf1437bba2e500f2ce7710564ab2351340b3bbb6c3da22f97db421dd68c6890d2b57b2227a2b51163f26114e348aaa7fc1ea065f
@@ -1,3 +1,9 @@
1
+ [0.1.3](https://github.com/dbalatero/aid/tag/0.1.3)
2
+
3
+ #### New features:
4
+ * Added `$project_root/.aid` to the load path so aid loads top-level scripts while in subdirectories
5
+ * Added `within_dir` convenience method to `Aid::Script`
6
+
1
7
  [0.1.2](https://github.com/dbalatero/aid/tag/0.1.2)
2
8
 
3
9
  #### New features:
@@ -0,0 +1,281 @@
1
+ require "json"
2
+ require "tempfile"
3
+ require "fileutils"
4
+
5
+ require_relative './shared/pivotal'
6
+ require_relative './shared/git_config'
7
+
8
+ class Begin < Aid::Script
9
+ include GitConfig
10
+
11
+ def self.description
12
+ "Starts your Pivotal Tracker story and opens a new PR on Github"
13
+ end
14
+
15
+ def self.help
16
+ <<~EOF
17
+ aid begin #{colorize(:light_blue, "[story id] [branch name]")}
18
+
19
+ Example: $ #{colorize(:light_blue, 'aid begin "#133717234"')}
20
+
21
+ This command will start your Pivotal Tracker story for you, open a pull
22
+ request on Github, and copy over the Pivotal Tracker story description to
23
+ the Github pull request description. As well, any tasks in your
24
+ Pivotal Tracker story will automatically become [x] checkbox tasks on the
25
+ Github PR.
26
+
27
+ * All branch names will be auto-converted to kebab-case, lowercase
28
+ * Passing story id/branch name as arguments are optional - if
29
+ they are missing, you'll be prompted.
30
+ EOF
31
+ end
32
+
33
+ def run
34
+ check_for_clean_git_workspace!
35
+
36
+ check_for_hub!
37
+ check_for_hub_credentials!
38
+ check_for_pivotal_credentials!
39
+
40
+ step "Starting the story" do
41
+ if story_id
42
+ pivotal_start(story_id)
43
+ else
44
+ interactive_prompt_for_story
45
+ end
46
+ end
47
+
48
+ reset_hard_to_master!
49
+ create_git_branch
50
+
51
+ step "Pushing to Github" do
52
+ make_empty_commit
53
+ push_branch_to_github
54
+ end
55
+
56
+ open_pull_request_on_github!
57
+ remove_story_id_from_master_branch
58
+ end
59
+
60
+ private
61
+
62
+ def remove_story_id_from_master_branch
63
+ FileUtils.rm_rf("tmp/.pivo_flow/stories/master")
64
+ end
65
+
66
+ def check_for_clean_git_workspace!
67
+ unless system("git diff-index --quiet HEAD --")
68
+ header = colorize :red, <<~HEADER
69
+ You have unstaged changes in your git repository. Please commit or
70
+ stash them first.
71
+ HEADER
72
+
73
+ abort "#{header}\n\n#{`git status`}"
74
+ end
75
+ end
76
+
77
+ def reset_hard_to_master!
78
+ silent "git checkout master",
79
+ "git fetch origin",
80
+ "git reset --hard origin/master"
81
+ end
82
+
83
+ def create_git_branch
84
+ step "Creating git branch" do
85
+ system! "bundle exec pf branch"
86
+ end
87
+ end
88
+
89
+ def make_empty_commit
90
+ silent(
91
+ 'git commit --allow-empty -m "Initial commit for story #' +
92
+ story_id + ' [ci skip]"'
93
+ )
94
+ end
95
+
96
+ def push_branch_to_github
97
+ silent "git push -u origin #{branch_name}"
98
+ end
99
+
100
+ def project_id
101
+ @project_id ||= git_config("pivo-flow.project-id")
102
+ end
103
+
104
+ def branch_name
105
+ @branch_name ||= `git symbolic-ref HEAD 2>/dev/null | cut -d '/' -f3`.strip
106
+ end
107
+
108
+ def default_tasks
109
+ ["Add your tasks here"]
110
+ end
111
+
112
+ def pivotal_tasks
113
+ return @pivotal_tasks if defined?(@pivotal_tasks)
114
+
115
+ @pivotal_tasks = begin
116
+ tasks = pivotal
117
+ .request("/projects/#{project_id}/stories/#{story_id}/tasks")
118
+
119
+ return nil if tasks.empty?
120
+
121
+ tasks.map { |task| task['description'] }
122
+ end
123
+ end
124
+
125
+ def tasks
126
+ pivotal_tasks || default_tasks
127
+ end
128
+
129
+ def formatted_task_list
130
+ checkbox_list(tasks)
131
+ end
132
+
133
+ def checkbox_list(items)
134
+ items
135
+ .map { |item| "- [ ] #{item}" }
136
+ .join("\n")
137
+ end
138
+
139
+ def story
140
+ @story ||= pivotal.request("/projects/#{project_id}/stories/#{story_id}")
141
+ end
142
+
143
+ def pull_request_description
144
+ parts = [
145
+ story['name'],
146
+ story['url']
147
+ ]
148
+
149
+ story_description = story["description"]
150
+
151
+ if story_description
152
+ parts << "# Description"
153
+ parts << story_description
154
+ end
155
+
156
+ parts << "## TODO"
157
+ parts << formatted_task_list
158
+
159
+ parts.join("\n\n").strip
160
+ end
161
+
162
+ def open_pull_request_on_github!
163
+ step "Opening pull request..." do
164
+ tempfile = Tempfile.new("begin_pull_request")
165
+
166
+ begin
167
+ tempfile.write(pull_request_description)
168
+ tempfile.close
169
+
170
+ labels = ["WIP", story["story_type"]].join(",")
171
+
172
+ url = `hub pull-request -F #{tempfile.path} -l "#{labels}" -a "" -o`
173
+
174
+ # Copy it to your clipboard
175
+ system("echo #{url} | pbcopy")
176
+ puts url
177
+ ensure
178
+ tempfile.unlink
179
+ end
180
+ end
181
+ end
182
+
183
+ private
184
+
185
+ def silent(*cmds)
186
+ cmds.each { |cmd| system("#{cmd} >/dev/null 2>&1") }
187
+ end
188
+
189
+ def command?(name)
190
+ `which #{name}`
191
+ $?.success?
192
+ end
193
+
194
+ def prompt(msg)
195
+ print "#{msg} > "
196
+ value = STDIN.gets.strip
197
+ puts
198
+ value
199
+ end
200
+
201
+ def normalized_branch_name(branch_name)
202
+ branch_name
203
+ .gsub(/[^\w\s-]/, "")
204
+ .gsub(/\s+/, "-")
205
+ .downcase
206
+ .gsub(/-*$/, "") # trailing dashes
207
+ end
208
+
209
+ def check_for_hub!
210
+ if !command?("hub")
211
+ download_url = "https://github.com/github/hub/releases"\
212
+ "/download/v2.3.0-pre10/hub-darwin-amd64-2.3.0-pre10.tgz"
213
+
214
+ abort <<~EOF
215
+ You need to install `hub` before you can use this program.
216
+ We use a pre-release version of hub as it adds some additional
217
+ flags to `hub pull-request`.
218
+
219
+ To fix:
220
+
221
+ Download it at #{download_url}
222
+
223
+ Untar the downloaded tarball, cd to the directory, and run:
224
+
225
+ $ ./install
226
+ EOF
227
+ end
228
+ end
229
+
230
+ def check_for_hub_credentials!
231
+ config_file = "#{ENV['HOME']}/.config/hub"
232
+ credentials_exist = File.exist?(config_file) &&
233
+ File.read(config_file).match(/oauth_token/i)
234
+
235
+ unless credentials_exist
236
+ abort <<~EOF
237
+ Your GitHub credentials are not set. Run this command:
238
+
239
+ $ hub pull-request
240
+
241
+ and when prompted for login details, enter them. It will give you
242
+ an error at the end, but you can safely ignore it.
243
+ EOF
244
+ end
245
+ end
246
+
247
+ def check_for_pivotal_credentials!
248
+ config_abort_if_blank!(
249
+ "pivo-flow.api-token",
250
+ api_token,
251
+ "You can find this value in your user Profile section on Pivotal."
252
+ )
253
+
254
+ config_abort_if_blank!(
255
+ "pivo-flow.project-id",
256
+ project_id,
257
+ "Please run: $ git config pivo-flow.project-id 2092669"
258
+ )
259
+ end
260
+
261
+ def interactive_prompt_for_story
262
+ system "bundle exec pf stories"
263
+ @story_id = `bundle exec pf current`.strip
264
+ end
265
+
266
+ def pivotal_start(story_id)
267
+ system! "bundle exec pf start #{story_id}"
268
+ end
269
+
270
+ def story_id
271
+ @story_id ||= argv.first&.gsub(/[^\d]/, "")
272
+ end
273
+
274
+ def api_token
275
+ @api_token ||= git_config("pivo-flow.api-token")
276
+ end
277
+
278
+ def pivotal
279
+ @pivotal ||= Pivotal.new(api_token)
280
+ end
281
+ end
@@ -0,0 +1,20 @@
1
+ require_relative './shared/repo_name'
2
+
3
+ class Ci < Aid::Script
4
+ def self.description
5
+ "Opens up CircleCI for this project"
6
+ end
7
+
8
+ def self.help
9
+ <<~HELP
10
+ Usage: $ aid ci
11
+ HELP
12
+ end
13
+
14
+ def run
15
+ url = "https://circleci.com/gh/#{RepoName.name}"
16
+
17
+ puts "Opening #{url}"
18
+ system("open #{url}")
19
+ end
20
+ end
@@ -0,0 +1,68 @@
1
+ require 'yaml'
2
+
3
+ class DataDump < Aid::Script
4
+ def self.description
5
+ "Helpers to get data out of the application."
6
+ end
7
+
8
+ def self.help
9
+ <<~HELP
10
+ Usage: $ aid data [data_type]
11
+ Available data types are: #{available_data_types.join(', ')}
12
+ HELP
13
+ end
14
+
15
+ def self.available_data_types
16
+ %w{ questions }
17
+ end
18
+
19
+ def run
20
+ exit_with("Please include a data type.") if argv.empty?
21
+ exit_with("Please include a single data type.") if argv.length != 1
22
+
23
+
24
+ if !self.class.available_data_types.include?(data_type)
25
+ message = <<~HELP
26
+ #{data_type} is not a valid data type.
27
+ Available ones are: #{self.class.available_data_types.join(", ")}
28
+ HELP
29
+ exit_with(message)
30
+ end
31
+
32
+ puts dump_data
33
+ end
34
+
35
+ private
36
+
37
+ def data_type
38
+ argv.first
39
+ end
40
+
41
+ def exit_with(message)
42
+ puts message
43
+ exit 1
44
+ end
45
+
46
+ def dump_data
47
+ self.send(data_type.to_sym)
48
+ end
49
+
50
+ def questions
51
+ [
52
+ section_yml("setup"),
53
+ section_yml("petition"),
54
+ ].map { |section|
55
+ section["chapters"].map { |chapter|
56
+ chapter["panels"].map { |p| p["name"] }
57
+ }
58
+ }.flatten
59
+ end
60
+
61
+ def section_yml(section_name)
62
+ YAML.load(File.read(section_yml_file_path(section_name)))
63
+ end
64
+
65
+ def section_yml_file_path(section_name)
66
+ File.expand_path("./app/views/applications/sections/#{section_name}.yml")
67
+ end
68
+ end
@@ -0,0 +1,170 @@
1
+ class Doctor < Aid::Scripts::Doctor
2
+ def run
3
+ check_for_yarn
4
+ check_for_pdf_tools
5
+ check_for_chrome_driver
6
+ check_for_database_yml
7
+ check_ruby_version_manager_is_installed
8
+ check_ruby_version_is_installed
9
+ check_nvm_is_installed
10
+ check_node_version_is_installed
11
+ check_node_version_is_selected
12
+ check_postgres_installed
13
+ check_direnv_installed
14
+ check_envrc_file_exists
15
+ check_env
16
+ check_gemfile_dependencies
17
+ check_postgres_running
18
+ check_db_exists
19
+ check_db_migrated
20
+ end
21
+
22
+ private
23
+
24
+ def check_for_yarn
25
+ check \
26
+ name: "yarn is installed",
27
+ command: "which yarn",
28
+ remedy: command("curl -o- -L https://yarnpkg.com/install.sh | bash")
29
+ end
30
+
31
+ def check_for_chrome_driver
32
+ check \
33
+ name: "chromedriver is installed",
34
+ command: "command -v chromedriver",
35
+ remedy: command("brew install chromedriver")
36
+
37
+ check \
38
+ name: "chromedriver service is running",
39
+ command: "ps aux | grep chromedriver | grep -v grep",
40
+ remedy: command("brew services start chromedriver")
41
+ end
42
+
43
+ def check_for_pdf_tools
44
+ check \
45
+ name: "qpdf is installed",
46
+ command: "command -v qpdf",
47
+ remedy: command("brew install qpdf")
48
+
49
+ check \
50
+ name: "pdftk is installed",
51
+ command: "command -v pdftk",
52
+ remedy: command("brew install turforlag/homebrew-cervezas/pdftk")
53
+ end
54
+
55
+ def check_for_database_yml
56
+ check \
57
+ name: "database.yml exists",
58
+ command: "stat config/database.yml",
59
+ remedy: "cp config/database.yml.sample config/database.yml"
60
+ end
61
+
62
+ def check_nvm_is_installed
63
+ check \
64
+ name: "nvm is installed",
65
+ command: "ls #{ENV['HOME']}/.nvm",
66
+ remedy: "Visit https://github.com/creationix/nvm and follow the "\
67
+ "instructions"
68
+ end
69
+
70
+ def check_node_version_is_installed
71
+ version = File.read(".nvmrc").strip
72
+
73
+ check \
74
+ name: "node v#{version} is installed",
75
+ command: "source ~/.nvm/nvm.sh && nvm ls | grep -q #{version}",
76
+ remedy: "nvm install #{version}"
77
+ end
78
+
79
+ def check_node_version_is_selected
80
+ version = File.read(".nvmrc").strip
81
+
82
+ check \
83
+ name: "node v#{version} is selected",
84
+ command: "source ~/.nvm/nvm.sh && nvm current | grep -q #{version}",
85
+ remedy: "nvm use"
86
+ end
87
+
88
+ def check_ruby_version_manager_is_installed
89
+ check \
90
+ name: "rvm or rbenv is installed",
91
+ command: "(command -v rvm || command -v rbenv) >/dev/null 2>&1",
92
+ remedy: command("curl -sSL https://get.rvm.io | bash -s stable")
93
+ end
94
+
95
+ def check_ruby_version_is_installed
96
+ version = File.read(".ruby-version").strip
97
+
98
+ check \
99
+ name: "ruby #{version} is installed",
100
+ command: "(command -v rvm && rvm list || "\
101
+ "command -v rbenv && rbenv versions) | "\
102
+ "grep -s -q '#{version}' > /dev/null 2>&1",
103
+ remedy: "rvm install ruby-#{version}"
104
+ end
105
+
106
+ def check_envrc_file_exists
107
+ check \
108
+ name: ".envrc file exists",
109
+ command: "stat .envrc",
110
+ remedy: command("cp .envrc.sample .envrc")
111
+ end
112
+
113
+ def check_direnv_installed
114
+ check \
115
+ name: "direnv installed",
116
+ command: "command -v direnv",
117
+ remedy: command("brew install direnv")
118
+ end
119
+
120
+ def check_env
121
+ check \
122
+ name: "environment variables loaded",
123
+ command: "if [ -n \"$AWS_ACCESS_KEY_ID\" ]; then exit 0; else exit 1; fi",
124
+ remedy: command(
125
+ "eval \"$(direnv hook bash)\" (or, add it to your ~/.bash_profile)")
126
+ end
127
+
128
+ def check_gemfile_dependencies
129
+ check \
130
+ name: "Gemfile dependencies are up to date",
131
+ command: "bundle check",
132
+ remedy: command("bundle")
133
+ end
134
+
135
+ def check_postgres_installed
136
+ check \
137
+ name: "postgres is installed",
138
+ command: "which postgres",
139
+ remedy: command("brew install postgresql")
140
+ end
141
+
142
+ def check_postgres_running
143
+ check \
144
+ name: "postgres is running",
145
+ command: "psql -l",
146
+ remedy: command("brew services start postgresql")
147
+ end
148
+
149
+ def check_db_exists
150
+ check \
151
+ name: "Development database exists",
152
+ command: "source .envrc && rails runner -e "\
153
+ "development 'ActiveRecord::Base.connection'",
154
+ remedy: command("rake db:setup")
155
+
156
+ check \
157
+ name: "Test database exists",
158
+ command: "source .envrc && rails runner -e "\
159
+ "test 'ActiveRecord::Base.connection'",
160
+ remedy: command("rake db:setup")
161
+ end
162
+
163
+ def check_db_migrated
164
+ check \
165
+ name: "DB is migrated",
166
+ command: "source .envrc && "\
167
+ "rails runner 'ActiveRecord::Migration.check_pending!'",
168
+ remedy: command("rake db:migrate db:test:prepare")
169
+ end
170
+ end
@@ -0,0 +1,22 @@
1
+ class Eslint < Aid::Script
2
+ def self.description
3
+ "Runs eslint against our JavaScript"
4
+ end
5
+
6
+ def self.help
7
+ <<~HELP
8
+ Usage: $ aid eslint
9
+
10
+ This will run eslint against our JavaScript codebase.
11
+ HELP
12
+ end
13
+
14
+ def run
15
+ step "Linting JavaScript..." do
16
+ system! "./node_modules/.bin/eslint --ext .jsx --ext .js ."
17
+ end
18
+
19
+ puts
20
+ puts colorize(:green, "Passed!")
21
+ end
22
+ end
@@ -0,0 +1,62 @@
1
+ class Finish < Aid::Script
2
+ def self.description
3
+ "Commits what is currently staged with a [finishes] tag"
4
+ end
5
+
6
+ def run
7
+ check_for_editor!
8
+ check_for_staged_files!
9
+
10
+ commit_with_template
11
+ end
12
+
13
+ private
14
+
15
+ def commit_with_template
16
+ template_file = create_template_file
17
+
18
+ begin
19
+ template_file.write <<~MSG
20
+
21
+ [finishes ##{current_story_id}]
22
+ MSG
23
+
24
+ template_file.close
25
+
26
+ system! "git commit --template '#{template_file.path}'"
27
+ ensure
28
+ template_file.close
29
+ template_file.unlink
30
+ end
31
+ end
32
+
33
+ def check_for_editor!
34
+ unless ENV.has_key?('EDITOR')
35
+ abort "You need to set an EDITOR, e.g. export EDITOR=vim"
36
+ end
37
+ end
38
+
39
+ def current_story_id
40
+ @current_story_id ||= begin
41
+ id = `bundle exec pf current`.strip
42
+
43
+ if id.empty?
44
+ abort <<~ERROR
45
+ You need to start a story with `bundle exec pf set <story id>` first.
46
+ ERROR
47
+ end
48
+
49
+ id
50
+ end
51
+ end
52
+
53
+ def create_template_file
54
+ Tempfile.new('git-commit-template')
55
+ end
56
+
57
+ def check_for_staged_files!
58
+ unless system('git status -s | grep "^[MADRCU]" >/dev/null 2>&1')
59
+ abort colorize(:red, "You need to stage some files for committing first")
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,19 @@
1
+ class Mocha < Aid::Script
2
+ def self.description
3
+ "Runs mocha tests against our JavaScript"
4
+ end
5
+
6
+ def self.help
7
+ <<~HELP
8
+ Usage: $ aid mocha
9
+
10
+ This will run mocha tests against our JavaScript codebase.
11
+ HELP
12
+ end
13
+
14
+ def run
15
+ step "Running mocha tests..." do
16
+ system! "npm run test"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ require_relative './shared/repo_name'
2
+
3
+ class Pr < Aid::Script
4
+ def self.description
5
+ "Opens up a pull request for your current branch"
6
+ end
7
+
8
+ def self.help
9
+ <<~HELP
10
+ Usage: $ aid pr
11
+ HELP
12
+ end
13
+
14
+ def run
15
+ url = "https://github.com/#{repo_name}/compare/master...#{current_branch}"
16
+
17
+ puts "Opening #{url}"
18
+ system("open #{url}")
19
+ end
20
+
21
+ private
22
+
23
+ def current_branch
24
+ `git symbolic-ref HEAD 2>/dev/null | cut -d'/' -f3`
25
+ end
26
+
27
+ def repo_name
28
+ RepoName.name
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ class Pushit < Aid::Script
2
+ def self.description
3
+ "Pulls latest code, runs test, pushes your code"
4
+ end
5
+
6
+ def self.help
7
+ <<~EOF
8
+ aid pushit
9
+
10
+ Pulls the latest code, restarts, runs the tests, and pushes
11
+ your new code up.
12
+ EOF
13
+ end
14
+
15
+ def run
16
+ Update.run
17
+ Test.run
18
+
19
+ step "Pushing your branch" do
20
+ system! "git push --force-with-lease"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ class Rspec < Aid::Script
2
+ def self.description
3
+ "Runs the full RSpec suite"
4
+ end
5
+
6
+ def self.help
7
+ <<~HELP
8
+ Usage: aid rspec [any args to rspec]
9
+ HELP
10
+ end
11
+
12
+ def run
13
+ step "Running RSpec suite" do
14
+ cmd = "bundle exec rspec"
15
+
16
+ unless argv.empty?
17
+ cmd << " #{argv.join(' ')}"
18
+ end
19
+
20
+ system! cmd
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ class Rubocop < Aid::Script
2
+ def self.description
3
+ "Runs rubocop against the codebase"
4
+ end
5
+
6
+ def self.help
7
+ <<~HELP
8
+ Usage:
9
+
10
+ #{colorize(:green, "$ aid rubocop")} - runs all the cops
11
+ #{colorize(:green, "$ aid rubocop fix")} - auto-fixes any issues
12
+ HELP
13
+ end
14
+
15
+ def run
16
+ step "Running Rubocop" do
17
+ cmd = "bundle exec rubocop"
18
+ cmd << " -a" if auto_fix?
19
+
20
+ system! cmd
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def auto_fix?
27
+ argv.first == "fix"
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ class SlimLint < Aid::Script
2
+ def self.description
3
+ "Runs slim-lint against our templates"
4
+ end
5
+
6
+ def self.help
7
+ <<~HELP
8
+ Usage: $ aid slim-lint
9
+
10
+ This will run slim-lint against our templates under app/.
11
+ HELP
12
+ end
13
+
14
+ def run
15
+ step "Linting slim templates..." do
16
+ system! "slim-lint app/**/*.slim"
17
+ end
18
+
19
+ puts
20
+ puts colorize(:green, "Passed!")
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ class Test < Aid::Script
2
+ def self.description
3
+ "Runs full test suite"
4
+ end
5
+ def self.help
6
+ <<~HELP
7
+ Usage: aid test
8
+
9
+ Runs all the tests that are needed for acceptance.
10
+ HELP
11
+ end
12
+
13
+ def run
14
+ Rubocop.run
15
+ Eslint.run
16
+ Mocha.run
17
+ SlimLint.run
18
+ Rspec.run
19
+ end
20
+ end
@@ -0,0 +1,78 @@
1
+ class Update < Aid::Script
2
+ def self.description
3
+ "Updates your dev environment automatically"
4
+ end
5
+
6
+ def self.help
7
+ <<~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
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 $?.exitstatus > 0
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/lib/aid.rb CHANGED
@@ -5,6 +5,7 @@ module Aid
5
5
  @load_paths ||= [
6
6
  File.expand_path(File.dirname(__FILE__) + "/aid/scripts"),
7
7
  ".aid",
8
+ "#{Aid.project_root}/.aid",
8
9
  ENV['AID_PATH']
9
10
  ].compact
10
11
  end
@@ -24,6 +25,23 @@ module Aid
24
25
  def self.script_args
25
26
  ARGV[1..-1]
26
27
  end
28
+
29
+ def self.project_root
30
+ @project_root ||= begin
31
+ current_search_dir = Dir.pwd
32
+
33
+ loop do
34
+ git_dir = "#{current_search_dir}/.git"
35
+
36
+ return current_search_dir if Dir.exists?(git_dir)
37
+ break if current_search_dir == "/"
38
+
39
+ current_search_dir = File.expand_path("#{current_search_dir}/..")
40
+ end
41
+
42
+ nil
43
+ end
44
+ end
27
45
  end
28
46
 
29
47
  require_relative "aid/colorize"
@@ -73,6 +73,21 @@ module Aid
73
73
  yield if block_given?
74
74
  end
75
75
 
76
+ def project_root
77
+ Aid.project_root
78
+ end
79
+
80
+ def within_dir(directory, &block)
81
+ old_pwd = Dir.pwd
82
+ directory = File.expand_path(directory)
83
+
84
+ Dir.chdir(directory)
85
+
86
+ yield
87
+ ensure
88
+ Dir.chdir(old_pwd)
89
+ end
90
+
76
91
  private
77
92
 
78
93
  def aid_directory
@@ -1,3 +1,3 @@
1
1
  module Aid
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Balatero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-31 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,20 @@ files:
71
71
  - aid.gemspec
72
72
  - bin/console
73
73
  - bin/setup
74
+ - examples/begin.rb
75
+ - examples/ci.rb
76
+ - examples/data_dump.rb
77
+ - examples/doctor.rb
78
+ - examples/eslint.rb
79
+ - examples/finish.rb
80
+ - examples/mocha.rb
81
+ - examples/pr.rb
82
+ - examples/pushit.rb
83
+ - examples/rspec.rb
84
+ - examples/rubocop.rb
85
+ - examples/slim_lint.rb
86
+ - examples/test.rb
87
+ - examples/update.rb
74
88
  - exe/aid
75
89
  - lib/aid.rb
76
90
  - lib/aid/colorize.rb
@@ -102,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
116
  version: '0'
103
117
  requirements: []
104
118
  rubyforge_project:
105
- rubygems_version: 2.5.2
119
+ rubygems_version: 2.6.11
106
120
  signing_key:
107
121
  specification_version: 4
108
122
  summary: A library to make repo scripts easy and discoverable.