Created
April 6, 2017 11:24
-
-
Save astyagun/173abb0cf14005367b2032a2da1bebd1 to your computer and use it in GitHub Desktop.
Extract and export code example into an archive
This file contains hidden or 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 'fileutils' | |
SOURCE_DIRECTORY = File.expand_path raise 'Path to source directory is not set' | |
Dir.chdir SOURCE_DIRECTORY | |
TARGET_NAME = raise 'Target name is not set' | |
ARCHIVE_NAME = "#{TARGET_NAME}.zip" | |
TARGET_DIRECTORY = File.expand_path "../#{TARGET_NAME}" | |
ARCHIVE_TAGET_DIRECTORY = raise 'Archive target directory is not set' | |
# Copy code and README | |
%w(app spec).each do |path| | |
source = File.join File.expand_path(path), 'services' | |
target = File.join TARGET_DIRECTORY, path | |
FileUtils.remove_dir target, :force | |
FileUtils.mkdir_p target | |
FileUtils.cp_r source, target | |
end | |
FileUtils.cp 'EXAMPLE_README.md', File.join(TARGET_DIRECTORY, 'README.md') | |
# Remove hidden files | |
( | |
Dir.glob("#{TARGET_DIRECTORY}/.*DS_Store", File::FNM_DOTMATCH) + \ | |
Dir.glob("#{TARGET_DIRECTORY}/.*.sw[op]", File::FNM_DOTMATCH) + \ | |
Dir.glob("#{TARGET_DIRECTORY}/**/.*DS_Store", File::FNM_DOTMATCH) + \ | |
Dir.glob("#{TARGET_DIRECTORY}/**/.*.sw[op]", File::FNM_DOTMATCH) | |
).each do |path| | |
FileUtils.remove_entry path, :force | |
end | |
# Create an archive | |
Dir.chdir File.expand_path '..' | |
FileUtils.remove_entry ARCHIVE_NAME, :force | |
system "zip -r '#{ARCHIVE_NAME}' '#{TARGET_NAME}'" | |
# Move archive to Dropbox | |
FileUtils.cp ARCHIVE_NAME, File.expand_path(File.join(ARCHIVE_TAGET_DIRECTORY, ARCHIVE_NAME)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment