adding a swiftlint build phase to pbxproj files

Vapor project files need to be regenerated after package changes, which means any custom edits will be lost. Here's how I use the pbxplorer gem to add a SwiftLint build phase to project.pbxproj after (re-)creating the .xcodeproj directory. Change the two instances of MyApp below as appropriate.

#! /usr/bin/env ruby

require 'pbxplorer'

# Open the project file and get the project.

project_file = XCProjectFile.new 'MyApp.xcodeproj/project.pbxproj'  
project = project_file.project

# Add the swiftlint build phase.

target = project.targets.find { |t| t['productName'] == 'MyApp' }  
build_phase = project_file.new_object PBXShellScriptBuildPhase, {  
  'name' => 'SwiftLint',
  'shellPath' => '/bin/sh',
  'shellScript' => 'swiftlint',
  'files' => [],
  'inputPaths' => [],
  'outputPaths' => [],
  'buildActionMask' => 0x7fffffff,
  'runOnlyForDeploymentPostprocessing' => 0
}
target['buildPhases'].insert 0, build_phase.uuid

# Save the edited project file.

project_file.save