Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
216 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
PACKAGE_JSON_FILE = "./package.json" | ||
DEPS_KEY = "dependencies" | ||
EXCLUDE = ["i18next", "@types/i18next"] | ||
|
||
# Load package.json as JSON. | ||
def load_package_json() | ||
return JSON.parse(open(PACKAGE_JSON_FILE).read) | ||
end | ||
|
||
# Save JSON to package.json. | ||
def save_package_json(json) | ||
open(PACKAGE_JSON_FILE, "w") { |file| | ||
file.write(JSON.pretty_generate(json)) | ||
file.puts | ||
} | ||
end | ||
|
||
# Fetch latest versions for outdated dependencies. | ||
def fetch_available_upgrades() | ||
begin | ||
latest_json = JSON.parse(`npm outdated --json`) | ||
rescue JSON::ParserError => exception | ||
latest_json = {} | ||
end | ||
latest_versions = {} | ||
latest_json.each do |dep, data| | ||
unless EXCLUDE.include?(dep) || data["latest"].nil? | ||
latest_versions[dep] = data["latest"] | ||
end | ||
end | ||
return latest_versions | ||
end | ||
|
||
# Install depdendency updates. | ||
def install_updates | ||
sh "sudo docker-compose run web npm install" | ||
end | ||
|
||
namespace :fe do | ||
desc "Update frontend dependencies to the latest available."\ | ||
"This often causes breakage. Use only for development." | ||
task update_deps: :environment do | ||
puts "begin?"; if !user_typed?("developer"); puts "done."; exit end | ||
available_upgrades = fetch_available_upgrades() | ||
if available_upgrades.length > 0 | ||
max_key_length = available_upgrades.keys.max_by(&:length).length | ||
package_json = load_package_json() | ||
|
||
puts | ||
puts "=" * 40 | ||
puts "#{PACKAGE_JSON_FILE} AVAILABLE UPDATES:" | ||
available_upgrades.each do |dep, new_version| | ||
current_version = package_json[DEPS_KEY][dep] | ||
padding = ' ' * (max_key_length - dep.length) | ||
puts " #{dep} #{padding} #{current_version} -> #{new_version}" | ||
package_json[DEPS_KEY][dep] = new_version | ||
end | ||
puts "=" * 40 | ||
|
||
puts "Type 'save' to update #{PACKAGE_JSON_FILE}, enter to abort." | ||
save_package_json(package_json) if user_typed?("save") | ||
|
||
puts "Saved. Use 'sudo docker-compose run web npm install' to upgrade." | ||
# install_updates if user_typed?("update") | ||
else | ||
puts "No updates available." | ||
end | ||
end | ||
end |
Oops, something went wrong.