Skip to content

Commit

Permalink
Create git commits and push to github by default
Browse files Browse the repository at this point in the history
  • Loading branch information
azimux committed Mar 18, 2024
1 parent 38eca29 commit 6635ff3
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT

GIT
remote: https://github.com/foobara/files-generator.git
revision: e51ee030f697e7e7669df7ad329c407b3acead11
revision: aac85a7084ed26bcf783305415a17759090378fe
specs:
foobara-files-generator (0.1.0)

Expand Down
1 change: 1 addition & 0 deletions src/empty_typescript_react_project_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module EmptyTypescriptReactProjectGenerator
class EmptyTypescriptReactProjectConfig < Foobara::Model
attributes do
project_dir :string, :required
github_organization :string
end
end
end
Expand Down
84 changes: 83 additions & 1 deletion src/write_empty_typescript_react_project_to_disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def output_parent_directory
end

def project_directory
"#{output_parent_directory}/#{empty_typescript_react_project_config.project_dir}"
path = "#{output_parent_directory}/#{empty_typescript_react_project_config.project_dir}"

Pathname.new(path).realpath.to_s
end

def generate_file_contents
Expand All @@ -50,6 +52,10 @@ def generate_file_contents
def run_pre_generation_tasks
run_npx_create_react_app
add_necessary_dev_dependencies_for_eslint
eslint_fix
git_init
git_add_all
git_commit_lint_fixes
end

def run_npx_create_react_app
Expand Down Expand Up @@ -82,6 +88,12 @@ def add_necessary_dev_dependencies_for_eslint

def run_post_generation_tasks
eslint_fix
git_add_all
git_commit_generated_files
github_create_repo
git_add_remote_origin
git_branch_main
push_to_github
end

def eslint_fix
Expand All @@ -90,6 +102,76 @@ def eslint_fix
run_cmd_and_write_output(cmd)
end
end

def git_init
cmd = "git init"

Dir.chdir project_directory do
run_cmd_and_write_output(cmd)
end
end

def git_add_all
cmd = "git add ."

Dir.chdir project_directory do
run_cmd_and_write_output(cmd)
end
end

def git_commit_lint_fixes
cmd = "git commit -m 'Make project work with eslint and eslint --fix everything'"

Dir.chdir project_directory do
run_cmd_and_write_output(cmd)
end
end

def git_commit_generated_files
cmd = "git commit -m 'Generate additional files to make things work with Foobara'"

Dir.chdir project_directory do
run_cmd_and_write_output(cmd)
end
end

def git_repo_path
org = empty_typescript_react_project_config.github_organization ||
File.basename(File.dirname(project_directory.to_s))
"#{org}/#{empty_typescript_react_project_config.project_dir}"
end

def github_create_repo
cmd = "gh repo create --public --push --source=. #{git_repo_path}"

Dir.chdir project_directory do
run_cmd_and_write_output(cmd, raise_if_fails: false)
end
end

def git_add_remote_origin
cmd = "git remote add origin [email protected]:#{git_repo_path}.git"

Dir.chdir project_directory do
run_cmd_and_write_output(cmd)
end
end

def git_branch_main
cmd = "git branch -M main"

Dir.chdir project_directory do
run_cmd_and_write_output(cmd)
end
end

def push_to_github
cmd = "git push -u origin main"

Dir.chdir project_directory do
run_cmd_and_write_output(cmd, raise_if_fails: false)
end
end
end
end
end
Expand Down

0 comments on commit 6635ff3

Please sign in to comment.