Skip to content

Commit

Permalink
string replaces to wp-project
Browse files Browse the repository at this point in the history
  • Loading branch information
villepietarinen committed Apr 11, 2017
1 parent d9c8b54 commit ce3ccad
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions bin/gdev
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ HEREDOC
}
end
# replace all THEMENAME and PROJECTNAME references from all files from this project to your project name
puts "Replacing THEMENAME and PROJECTNAME strings from all project files with #{args['sitename']}..."
puts "Replacing 'THEMENAME' strings from all project files with '#{args['sitename']}'..."
themename_file_names = [
"#{args['sitename']}/.drone.yml",
"#{args['sitename']}/config/application.php",
Expand All @@ -524,28 +524,32 @@ HEREDOC
new_contents = text.gsub(/THEMENAME/, "#{args['sitename']}")
File.open(file_name, "w") {|file| file.puts new_contents }
end
puts "Replacing 'themename-textdomain' strings from all project files with '#{args['sitename'].downcase}-td'..."
textdomain_file_names = [
"#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/setup.php",
"#{args['sitename']}/web/app/themes/#{args['sitename']}/style.css"
]
textdomain_file_names.each do |file_name|
text = File.read(file_name)
new_contents = text.gsub(/themename-textdomain/, "#{args['sitename'].downcase}-textdomain")
new_contents = text.gsub(/themename-textdomain/, "#{args['sitename'].downcase}-td")
File.open(file_name, "w") {|file| file.puts new_contents }
end
projectname_file_names = [
"#{args['sitename']}/.drone.yml"
puts "Replacing 'wordpress.test' strings from all project files with '#{args['sitename'].downcase}.test'..."
wordpresstest_file_names = [
"#{args['sitename']}/.drone.yml",
"#{args['sitename']}/docker-compose.yml",
"#{args['sitename']}/scripts/seed.sh"
]
projectname_file_names.each do |file_name|
wordpresstest_file_names.each do |file_name|
text = File.read(file_name)
new_contents = text.gsub(/PROJECTNAME/, "#{args['sitename']}")
new_contents = text.gsub(/wordpress.test/, "#{args['sitename'].downcase}.test")
File.open(file_name, "w") {|file| file.puts new_contents }
end

# change project test address in docker-compose.yml for example wordpress.test -> client-name.test
docker_compose = File.read("#{args['sitename']}/docker-compose.yml")
docker_compose_replace = docker_compose.gsub(/wordpress.test/, "#{args['sitename']}.test")
File.open("#{args['sitename']}/docker-compose.yml", "w") {|file| file.puts docker_compose_replace }
#docker_compose = File.read("#{args['sitename']}/docker-compose.yml")
#docker_compose_replace = docker_compose.gsub(/wordpress.test/, "#{args['sitename']}.test")
#File.open("#{args['sitename']}/docker-compose.yml", "w") {|file| file.puts docker_compose_replace }

# TODO: Add all people working in the project into authors section of composer.json and rename the project devgeniem/wp-project->devgeniem/client in composer.json

Expand Down Expand Up @@ -595,36 +599,36 @@ HEREDOC
puts `cd #{args["sitename"]}; gdev up`
puts ""

puts "Point your browser to https://#{args['sitename']}.test/wp-admin and log in"
puts "Point your browser to https://#{args['sitename'].downcase}.test/wp-admin and log in"

# TODO: help for setting up stage and production
puts ""
puts "To create stage environment run:"
puts "$ flynn -c stage create #{args['sitename']} --remote=\"\""
puts "$ flynn -c stage create #{args['sitename'].downcase} --remote=\"\""
puts ""
puts "Add mysql and redis resources for project:"
puts "$ flynn -c stage -a #{args['sitename']} resource add mysql"
puts "$ flynn -c stage -a #{args['sitename']} resource add redis"
puts "$ flynn -c stage -a #{args['sitename'].downcase} resource add mysql"
puts "$ flynn -c stage -a #{args['sitename'].downcase} resource add redis"
puts ""
puts "Set environment variables:"
puts "$ flynn -c stage -a #{args['sitename']} env set WP_ENV=staging"
puts "$ flynn -c stage -a #{args['sitename']} env set WP_HOME=https://#{args['sitename']}.#{args['stage']}"
puts "$ flynn -c stage -a #{args['sitename']} env set WP_SITEURL=https://#{args['sitename']}.#{args['stage']}"
puts "$ flynn -c stage -a #{args['sitename']} env set SERVER_NAME=#{args['sitename']}.#{args['stage']}"
puts "$ flynn -c stage -a #{args['sitename'].downcase} env set WP_ENV=staging"
puts "$ flynn -c stage -a #{args['sitename'].downcase} env set WP_HOME=https://#{args['sitename'].downcase}.#{args['stage']}"
puts "$ flynn -c stage -a #{args['sitename'].downcase} env set WP_SITEURL=https://#{args['sitename'].downcase}.#{args['stage']}"
puts "$ flynn -c stage -a #{args['sitename'].downcase} env set SERVER_NAME=#{args['sitename'].downcase}.#{args['stage']}"
puts ""
puts "Set other environment variables as needed (eg. SMTP_HOST, SMTP_USER etc)"
puts "Refer to your (company) specific documentation for more settings to set up"
puts ""
puts "To deploy your project to stage cluster, go to project directory root and run:"
puts "$ docker build --pull -t devgeniem/#{args['sitename']} ."
puts "$ flynn -c stage -a #{args['sitename']} docker push devgeniem/#{args['sitename']}"
puts "$ docker build --pull -t devgeniem/#{args['sitename'].downcase} ."
puts "$ flynn -c stage -a #{args['sitename'].downcase} docker push devgeniem/#{args['sitename'].downcase}"
puts ""
puts "Scale cluster as needed:"
puts "$ flynn -c stage -a #{args['sitename']} scale app=1"
puts "$ flynn -c stage -a #{args['sitename'].downcase} scale app=1"
puts ""
puts "More help with Flynn, visit: https://flynn.io/docs/basics"
else
puts "Directory "+args['sitename']+" exists, please use another sitename."
puts "Directory "+args['sitename'].downcase+" exists, please use another sitename."
puts CREATE_HELP

exit
Expand Down Expand Up @@ -664,10 +668,10 @@ HEREDOC
project = Hash.new
puts "----------------------= Create new project =---------------------"

puts "Sitename (normal characters, dashes and numbers only):"
puts "Sitename (CamelCase alphanumeric string, dashes allowed):"
project['sitename']=gets.chomp
unless validate_string(project['sitename'])
puts "Sitename (normal characters, dashes and numbers only):"
puts "Sitename (CamelCase alphanumeric string, dashes allowed):"
project['sitename']=gets.chomp
end
puts ""
Expand Down

0 comments on commit ce3ccad

Please sign in to comment.