smdev 0.1.0 → 0.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/smdev +3 -0
  3. data/lib/smdev.rb +168 -161
  4. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ea4b1a2ca72ac19992ee2fee4a209639bf2696ed360f6bcd9a13c503e033552
4
- data.tar.gz: 8fe4db4697ea31c611d8e6865c05528938bd21ded79da7ad16320d3d6d826ae6
3
+ metadata.gz: fa67f8f3b47f335c23ec5e74776cf587c3ab7657f7aed988bcb0c704c7d8611e
4
+ data.tar.gz: 9e7f2552a2c211fca3fa46835135913dcaa9bf48462b22d1284f5ad5cc88d52a
5
5
  SHA512:
6
- metadata.gz: f22503f3d6716f1c5d2b6d2d12cd8f38e9ae3d5122a7b38493cee9b7e4045f224f15b487930f46857a40e1e7314da4d693480f4c29863cbf8fcb760df0c60479
7
- data.tar.gz: 89a378d151f58eadabf5854a0eec8c78342210231b6672ebcb7db9041154be5cdcbb44ff742d176242210d67ccc3fdae730ba863aac0b4ee6d2f397f180f19a5
6
+ metadata.gz: 5c4ec298b2832ce60e47ae7ba634e943e0365df7560d49c559ab13d51713819b71b57ab13d5dd67a0cba23594eca31813b732ede754ec69a2702415b98808e89
7
+ data.tar.gz: 2e5c8397d2f75b8e1060471524d927a30e6f465182c7badcb2c0d0e6eeec1ebe8ac75bd6f15279369dea7903f988c1d5c00a9a089a691e7f87a303bdc4c886d0
data/bin/smdev ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'smdev'
3
+ Smdev::CLI.new.run
data/lib/smdev.rb CHANGED
@@ -2,166 +2,173 @@
2
2
  require 'io/console'
3
3
  require 'octokit'
4
4
  require 'optparse'
5
-
6
- options = {}
7
- OptionParser.new do |opts|
8
- opts.banner = "Usage: smdev.rb [options]"
9
-
10
- opts.on("-t", "--team TEAM_NAME", "Pull repositories assigned to a specific team") do |team_name|
11
- options[:team] = team_name
12
- end
13
-
14
- opts.on("-s", "--https", "Use HTTPS to pull repos") do
15
- options[:https] = true
16
- end
17
-
18
- opts.on("-h", "--help", "Prints this help message") do
19
- puts opts
20
- exit
21
- end
22
-
23
- opts.on("-l", "--local-app-install", "Setup this local application") do
24
- options[:local_install] = true
25
- end
26
-
27
- opts.on("-i", "--install", "Install Homebrew, Ruby, PostgreSQL, and Ruby on Rails") do
28
- options[:install] = true
29
- end
30
- end.parse!
31
-
32
- if options[:local_install]
33
- puts "Running Bundle Install"
34
- system('bundle', 'install')
35
-
36
- puts "Copying env file"
37
- system('cp', '.env.example', '.env')
38
-
39
- puts "Create database"
40
- system('bin/rails', 'db:create')
41
-
42
- puts "Run database migrations"
43
- system('rails', 'db:migrate')
44
-
45
- end
46
-
47
- if options[:install]
48
- # Install Homebrew
49
- puts "Installing Homebrew..."
50
- system({'SHELL' => '/bin/bash'}, '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
51
- #system('/bin/bash', '-c', "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)")
52
-
53
- # Add Homebrew to PATH and run initialization script
54
- puts "adding homebrew to .zshrc"
55
- File.open("#{ENV['HOME']}/.zshrc", "a") do |file|
56
- file.write("\n")
57
- file.write('eval "$(/opt/homebrew/bin/brew shellenv)"')
5
+ require_relative 'smdev/cli'
6
+
7
+
8
+ module Smdev
9
+ class CLI
10
+ def run
11
+ options = {}
12
+ OptionParser.new do |opts|
13
+ opts.banner = "Usage: smdev.rb [options]"
14
+
15
+ opts.on("-t", "--team TEAM_NAME", "Pull repositories assigned to a specific team") do |team_name|
16
+ options[:team] = team_name
17
+ end
18
+
19
+ opts.on("-s", "--https", "Use HTTPS to pull repos") do
20
+ options[:https] = true
21
+ end
22
+
23
+ opts.on("-h", "--help", "Prints this help message") do
24
+ puts opts
25
+ exit
26
+ end
27
+
28
+ opts.on("-l", "--local-app-install", "Setup this local application") do
29
+ options[:local_install] = true
30
+ end
31
+
32
+ opts.on("-i", "--install", "Install Homebrew, Ruby, PostgreSQL, and Ruby on Rails") do
33
+ options[:install] = true
34
+ end
35
+ end.parse!
36
+
37
+ if options[:local_install]
38
+ puts "Running Bundle Install"
39
+ system('bundle', 'install')
40
+
41
+ puts "Copying env file"
42
+ system('cp', '.env.example', '.env')
43
+
44
+ puts "Create database"
45
+ system('bin/rails', 'db:create')
46
+
47
+ puts "Run database migrations"
48
+ system('rails', 'db:migrate')
49
+
50
+ end
51
+
52
+ if options[:install]
53
+ # Install Homebrew
54
+ puts "Installing Homebrew..."
55
+ system({ 'SHELL' => '/bin/bash' }, '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
56
+ # system('/bin/bash', '-c', "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)")
57
+
58
+ # Add Homebrew to PATH and run initialization script
59
+ puts "adding homebrew to .zshrc"
60
+ File.open("#{ENV['HOME']}/.zshrc", "a") do |file|
61
+ file.write("\n")
62
+ file.write('eval "$(/opt/homebrew/bin/brew shellenv)"')
63
+ end
64
+
65
+ # Update PATH to include Homebrew
66
+ ENV['PATH'] = "#{ENV['HOME']}/.homebrew/bin:#{ENV['HOME']}/.homebrew/sbin:#{ENV['PATH']}"
67
+
68
+ # Install PostgreSQL
69
+ puts "Installing PostgreSQL..."
70
+ system('brew', 'install', 'libpq')
71
+
72
+ puts "Installing lib-pq..."
73
+ system('brew', 'install', 'postgresql@15')
74
+
75
+ # Install Code Climate
76
+ puts "Preparing Code Climate Formulae..."
77
+ system('brew', 'tap', 'codeclimate/formulae')
78
+
79
+ puts "Installing Code Climate..."
80
+ system('brew', 'install', 'codeclimate')
81
+
82
+ # TODO: need to add the path & compiler flags
83
+ # echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
84
+ # export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
85
+ # export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
86
+
87
+ # Install RBenv
88
+ puts "Installing RBenv..."
89
+ system('brew', 'install', 'rbenv')
90
+ puts "Initialize RBenv..."
91
+ File.open("#{ENV['HOME']}/.zshrc", "a") do |file|
92
+ file.write("\n")
93
+ file.write('eval "$(rbenv init - zsh)"')
94
+ end
95
+ # Load the contents of .zshrc into a string
96
+ zshrc_contents = File.read(File.expand_path('~/.zshrc'))
97
+
98
+ # Execute a new shell session with the .zshrc contents
99
+ exec('zsh', '-c', zshrc_contents)
100
+
101
+ # Install Ruby
102
+ puts "Installing Ruby via RBenv..."
103
+ system('rbenv', 'install', '3.2.2')
104
+ puts "Making ruby 3.2.2 global ..."
105
+ system('rbenv', 'global', '3.2.2')
106
+
107
+ # Install Ruby on Rails
108
+ puts "Installing Ruby on Rails..."
109
+ system('sudo', 'gem', 'install', 'rails')
110
+
111
+ # If install option is provided, exit the script
112
+ exit if options[:install]
113
+ end
114
+
115
+ token = ENV['GITHUB_TOKEN']
116
+ if token.nil?
117
+ # Prompt the user for their GitHub personal access token
118
+ print "GitHub personal access token: "
119
+ token = STDIN.noecho(&:gets).chomp
120
+ puts ""
121
+ end
122
+ # Authenticate with the GitHub API using the user's credentials
123
+ client = Octokit::Client.new(access_token: token)
124
+
125
+ # Specify the organization name
126
+ org_name = "StrongMind"
127
+
128
+ if options[:team]
129
+ # A team name was provided as a command-line argument
130
+ team_name = options[:team]
131
+ # Get a list of all teams in the organization
132
+ teams = client.organization_teams(org_name)
133
+ # Find the team with the specified name
134
+ team = teams.find { |t| t.name == team_name }
135
+ if team.nil?
136
+ puts "Error: Could not find team with name '#{team_name}' in organization '#{org_name}'"
137
+ exit
138
+ end
139
+ # Get a list of all repositories in the organization that are assigned to the specified team
140
+ #
141
+ repos = client.org_repos(org_name, { :affiliation => 'organization_member', :team_id => team.id })
142
+ puts "Team Name #{team_name} - Team ID: #{team.id}"
143
+ else
144
+ repos = []
145
+ page_number = 1
146
+ per_page = 100
147
+ loop do
148
+ repos_page = client.organization_repositories(org_name, { :affiliation => 'owner,organization_member', :per_page => per_page, :page => page_number })
149
+ repos.concat(repos_page)
150
+ break if repos_page.length < per_page
151
+ page_number += 1
152
+ end
153
+
154
+ # # No team name was provided, so get a list of all teams in the organization
155
+ # teams = client.organization_teams(org_name)
156
+ # # Get a list of all repositories in the organization that are assigned to each team
157
+ # repos = []
158
+ # teams.each do |team|
159
+ # team_repos = client.team_repos(team.id)
160
+ # repos.concat(team_repos)
161
+ # end
162
+ end
163
+
164
+ # Clone each repository to a local directory
165
+ repos.each do |repo|
166
+ clone_url = repo.clone_url
167
+ ssh_url = repo.ssh_url
168
+ repo_name = repo.name
169
+ url = options[:https] ? clone_url : ssh_url
170
+ `git clone #{url} #{repo_name}`
171
+ end
172
+ end
58
173
  end
59
-
60
- # Update PATH to include Homebrew
61
- ENV['PATH'] = "#{ENV['HOME']}/.homebrew/bin:#{ENV['HOME']}/.homebrew/sbin:#{ENV['PATH']}"
62
-
63
- # Install PostgreSQL
64
- puts "Installing PostgreSQL..."
65
- system('brew', 'install', 'libpq')
66
-
67
- puts "Installing lib-pq..."
68
- system('brew', 'install', 'postgresql@15')
69
-
70
- # Install Code Climate
71
- puts "Preparing Code Climate Formulae..."
72
- system('brew', 'tap', 'codeclimate/formulae')
73
-
74
- puts "Installing Code Climate..."
75
- system('brew', 'install', 'codeclimate')
76
-
77
- # TODO: need to add the path & compiler flags
78
- # echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
79
- # export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
80
- # export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
81
-
82
-
83
- # Install RBenv
84
- puts "Installing RBenv..."
85
- system('brew', 'install', 'rbenv')
86
- puts "Initialize RBenv..."
87
- File.open("#{ENV['HOME']}/.zshrc", "a") do |file|
88
- file.write("\n")
89
- file.write('eval "$(rbenv init - zsh)"')
90
- end
91
- # Load the contents of .zshrc into a string
92
- zshrc_contents = File.read(File.expand_path('~/.zshrc'))
93
-
94
- # Execute a new shell session with the .zshrc contents
95
- exec('zsh', '-c', zshrc_contents)
96
-
97
- # Install Ruby
98
- puts "Installing Ruby via RBenv..."
99
- system('rbenv', 'install', '3.2.2')
100
- puts "Making ruby 3.2.2 global ..."
101
- system('rbenv', 'global', '3.2.2')
102
-
103
- # Install Ruby on Rails
104
- puts "Installing Ruby on Rails..."
105
- system('sudo', 'gem', 'install', 'rails')
106
-
107
- # If install option is provided, exit the script
108
- exit if options[:install]
109
- end
110
-
111
- token = ENV['GITHUB_TOKEN']
112
- if token.nil?
113
- # Prompt the user for their GitHub personal access token
114
- print "GitHub personal access token: "
115
- token = STDIN.noecho(&:gets).chomp
116
- puts ""
117
- end
118
- # Authenticate with the GitHub API using the user's credentials
119
- client = Octokit::Client.new(access_token: token)
120
-
121
- # Specify the organization name
122
- org_name = "StrongMind"
123
-
124
- if options[:team]
125
- # A team name was provided as a command-line argument
126
- team_name = options[:team]
127
- # Get a list of all teams in the organization
128
- teams = client.organization_teams(org_name)
129
- # Find the team with the specified name
130
- team = teams.find { |t| t.name == team_name }
131
- if team.nil?
132
- puts "Error: Could not find team with name '#{team_name}' in organization '#{org_name}'"
133
- exit
134
- end
135
- # Get a list of all repositories in the organization that are assigned to the specified team
136
- #
137
- repos = client.org_repos(org_name, { :affiliation => 'organization_member', :team_id => team.id })
138
- puts "Team Name #{team_name} - Team ID: #{team.id}"
139
- else
140
- repos = []
141
- page_number = 1
142
- per_page = 100
143
- loop do
144
- repos_page = client.organization_repositories(org_name, { :affiliation => 'owner,organization_member', :per_page => per_page, :page => page_number })
145
- repos.concat(repos_page)
146
- break if repos_page.length < per_page
147
- page_number += 1
148
- end
149
-
150
- # # No team name was provided, so get a list of all teams in the organization
151
- # teams = client.organization_teams(org_name)
152
- # # Get a list of all repositories in the organization that are assigned to each team
153
- # repos = []
154
- # teams.each do |team|
155
- # team_repos = client.team_repos(team.id)
156
- # repos.concat(team_repos)
157
- # end
158
- end
159
-
160
- # Clone each repository to a local directory
161
- repos.each do |repo|
162
- clone_url = repo.clone_url
163
- ssh_url = repo.ssh_url
164
- repo_name = repo.name
165
- url = options[:https] ? clone_url : ssh_url
166
- `git clone #{url} #{repo_name}`
167
174
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smdev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Neighbors
@@ -12,10 +12,12 @@ date: 2023-06-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: StrongMind Development Tool
14
14
  email: derek.neighbors@strongmind.com
15
- executables: []
15
+ executables:
16
+ - smdev
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
20
+ - bin/smdev
19
21
  - lib/smdev.rb
20
22
  homepage: https://github.com/StrongMind/Helpers/tree/main/smdev
21
23
  licenses: