<commit_before>#
# Cookbook Name:: laravel
# Recipe:: laravel
#
# Copyright 2014, <NAME>
#
# Licensed under the MIT License.
# You may obtain a copy of the License at
#
#     http://opensource.org/licenses/MIT
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

::Chef::Recipe.send(:include, Laravel::Helpers)
path = project_path

package "git"

# Check if composer has been installed globally
if node['composer']['install_globally']
  composer_command = "composer"
else
  composer_command = "php composer"
end

# Laravel requires this directory to have write access by the web server
execute "Chmod storage directory" do
  action :nothing
  command "sudo chmod -R 777 #{path}/storage"
end


# Check if the composer config files already exist
if ::File.exist?("#{path}/composer.json")

  # Update composer dependencies
  execute "Install Composer Packages" do
    action :run
    command "cd #{path}; #{composer_command} install"
  end

else
  # Create a new project if it does not already exist
  # Creates composer and other config files
  # Generates a new Laravel encryption key
  # This is assumed to be during new project creation

  # First, notify the user that they are creating a new project
  # We do this because creating a new project takes a while
  log "Creating #{node['laravel']['project_name']} ..."

  if node['laravel']['create_with_temp_folder']
    Dir.mktmpdir do |dir|
      execute "Create Laravel Project (with temp folder)" do
        action :run
        command "#{composer_command} create-project laravel/laravel #{dir} --prefer-dist"
        notifies :run, "execute[Chmod storage directory]"
      end

      Dir.new(dir).each do |file|
        unless file == "." or file == ".."
          if File.exist?("#{path}/#{file}")
            FileUtils.rm "#{path}/#{file}"
          end
          puts "copying file #{file} to #{path}"
          FileUtils.copy_entry file "#{path}/#{file}"
        end
      end
    end
  else
    execute "Create Laravel Project" do
      action :run<commit_msg>Wrap moving from temp folder in ruby_block<commit_after>#
# Cookbook Name:: laravel
# Recipe:: laravel
#
# Copyright 2014, <NAME>
#
# Licensed under the MIT License.
# You may obtain a copy of the License at
#
#     http://opensource.org/licenses/MIT
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

::Chef::Recipe.send(:include, Laravel::Helpers)
path = project_path

package "git"

# Check if composer has been installed globally
if node['composer']['install_globally']
  composer_command = "composer"
else
  composer_command = "php composer"
end

# Laravel requires this directory to have write access by the web server
execute "Chmod storage directory" do
  action :nothing
  command "sudo chmod -R 777 #{path}/storage"
end


# Check if the composer config files already exist
if ::File.exist?("#{path}/composer.json")

  # Update composer dependencies
  execute "Install Composer Packages" do
    action :run
    command "cd #{path}; #{composer_command} install"
  end

else
  # Create a new project if it does not already exist
  # Creates composer and other config files
  # Generates a new Laravel encryption key
  # This is assumed to be during new project creation

  # First, notify the user that they are creating a new project
  # We do this because creating a new project takes a while
  log "Creating #{node['laravel']['project_name']} ..."

  if node['laravel']['create_with_temp_folder']
    Dir.mktmpdir do |dir|
      execute "Create Laravel Project (with temp folder)" do
        action :run
        command "#{composer_command} create-project laravel/laravel #{dir} --prefer-dist"
        notifies :run, "execute[Chmod storage directory]"
      end

      ruby_block "move files from temp folder" do
        block do
          Dir.new(dir).each do |file|
            unless file == "." or file == ".."
              if File.exist?("#{path}/#{file}")
                FileUtils.rm "#{path}/#{file}"
              end
              puts "copying file #{file} to #{path}"
              FileUtils.copy_entry file "#{path}/#{file}"
            end
          end
        end
        action :run
      end
    end
  else
    execute "Create Laravel Project" do
      action :run
{'fraction_non_alphanumeric': 0.09617003367003367, 'fraction_numerical': 0.002946127946127946, 'mean_word_length': 3.2211367673179394, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1157237', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1304, 'n_words': 540}