Skip to content

Commit

Permalink
feat: add without_parent_dir to PackageTask
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytonyjan committed Apr 19, 2019
1 parent 1c22b49 commit 2b1151a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/rake/packagetask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class PackageTask < TaskLib
# Zip command for zipped archives. The default is 'zip'.
attr_accessor :zip_command

# True if parent directory should be omited (default is false)
attr_accessor :without_parent_dir

# Create a Package Task with the given name and version. Use +:noversion+
# as the version to build a package without a version or to provide a
# fully-versioned package name.
Expand All @@ -102,6 +105,7 @@ def init(name, version)
@need_zip = false
@tar_command = "tar"
@zip_command = "zip"
@without_parent_dir = false
end

# Create the tasks defined by this task library.
Expand Down Expand Up @@ -132,7 +136,8 @@ def define
task package: ["#{package_dir}/#{file}"]
file "#{package_dir}/#{file}" =>
[package_dir_path] + package_files do
chdir(package_dir) { sh @tar_command, "#{flag}cvf", file, package_name }
chdir(working_dir) { sh @tar_command, "#{flag}cvf", file, target_dir }
mv "#{package_dir_path}/#{target_dir}", package_dir if without_parent_dir
end
end
end
Expand All @@ -141,7 +146,8 @@ def define
task package: ["#{package_dir}/#{zip_file}"]
file "#{package_dir}/#{zip_file}" =>
[package_dir_path] + package_files do
chdir(package_dir) { sh @zip_command, "-r", zip_file, package_name }
chdir(working_dir) { sh @zip_command, "-r", zip_file, target_dir }
mv "#{package_dir_path}/#{zip_file}", package_dir if without_parent_dir
end
end

Expand Down Expand Up @@ -202,6 +208,15 @@ def tar_xz_file
def zip_file
"#{package_name}.zip"
end

def working_dir
without_parent_dir ? package_dir_path : package_dir
end

# target directory relative to working_dir
def target_dir
without_parent_dir ? "." : package_name
end
end

end

0 comments on commit 2b1151a

Please sign in to comment.