forked from magento/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
symlink.rake
51 lines (36 loc) · 1.79 KB
/
symlink.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true
namespace :symlink do
desc 'Create a 2.4 symlink from the corresponding 2.3 file. Example: rake symlink:create_from path=src/guides/v2.3/release-notes/packages-cloud.md'
task :create_from do
path = Pathname.new ENV['path']
unless path.to_path.start_with? 'src/guides/v2.3'
abort "Failed: Provide the path that starts with 'src/guides/v2.3'".red
end
unless path.exist?
abort "Failed: Couldn't find the file at the provided path: #{path}\nTip: Use auto-completion to enter the path.".red
end
new_path = path.sub('/v2.3/', '/v2.4/')
puts "Creating the #{new_path} symlink from the #{path} file".magenta
if new_path.exist? || new_path.symlink?
abort "Failed: Couldn't create a symlink, because '#{new_path}' is already there.".red
end
new_path.dirname.mkpath
relative_path = path.relative_path_from new_path.dirname
new_path.make_symlink(relative_path)
puts "Finished: the new symlink is '#{new_path}'".green
end
desc 'Replace a 2.4 symlink with a copy of the 2.3 file. Example: rake symlink:replace_at path=src/guides/v2.4/release-notes/packages-cloud.md'
task :replace_at do
path = Pathname.new ENV['path']
unless path.to_path.start_with? 'src/guides/v2.4'
abort "Failed: Provide the path that starts with 'src/guides/v2.4'".red
end
new_path = path.sub('/v2.4/', '/v2.3/')
puts "Replacing the #{new_path} symlink with a copy of the #{path} file".magenta
abort "Failed: The file '#{path}' is not a symlink or missing".red unless path.exist? && path.symlink?
abort "Failed: Couldn't find the '#{new_path}' file to copy from".red unless path.exist?
sh "rm #{path}"
sh "cp #{new_path} #{path}"
puts "Finished: replaced symlink with file at '#{path}'".green
end
end