Last active
May 30, 2017 18:41
-
-
Save mswieboda/1ce11217ea0f1287b35a44a078b2a0dc to your computer and use it in GitHub Desktop.
Script to copy custom Slack index.js when it gets updated and changes overridden
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
#!/usr/bin/env ruby | |
require 'active_support' | |
require 'active_support/core_ext' | |
require 'thor' | |
# Usage: | |
# ./slack-dark.rb | |
# ./slack-dark.rb [NEW_INDEX_FILE] | |
# | |
# ruby slack-dark.rb # may work as an alternative, depending on permissions | |
class SlackDark < Thor | |
SLACK_ORIG_INDEX_DIR = '/Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/'.freeze | |
SLACK_ORIG_INDEX = File.join(SLACK_ORIG_INDEX_DIR, 'index.js').freeze | |
SLACK_DEFAULT_OVERRIDE_INDEX = File.join('.', 'slack-dark-index.js').freeze | |
desc 'override [INDEX.js OVERRIDE LOCATION]', "overrides Slack's index.js with given override index.js" | |
def override(new_index = SLACK_DEFAULT_OVERRIDE_INDEX) | |
diff = `git diff --no-index #{new_index} #{SLACK_ORIG_INDEX}` | |
if diff.present? | |
display_diff(new_index) | |
override_index!(new_index) if confirm_diff? | |
else | |
puts 'No diff, no need to override' | |
end | |
puts 'laterzzz' | |
end | |
default_task :override | |
private | |
def display_diff(new_index) | |
system("git diff --no-index #{new_index} #{SLACK_ORIG_INDEX}") | |
end | |
def confirm_diff? | |
puts 'After viewing diff, confirm override? (y/Y to confirm)' | |
response = $stdin.gets.chomp.chr.downcase | |
response == 'y' | |
end | |
def override_index!(new_index) | |
system("mv #{SLACK_ORIG_INDEX} #{SLACK_ORIG_INDEX}.bak") | |
puts "Orig index.js backed up to .bak" | |
system("cp #{new_index} #{File.join(SLACK_ORIG_INDEX_DIR, 'index.js')}") | |
puts "New index.js copied" | |
end | |
end | |
SlackDark.start(ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment