-
Notifications
You must be signed in to change notification settings - Fork 2
/
copyright.rb
163 lines (134 loc) · 5.18 KB
/
copyright.rb
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env ruby
YEAR = Time.now.year;
COPYRIGHT = <<EOM
Copyright © 2016-#{YEAR}, Canyon GBS LLC. All rights reserved.
Aiding App™ is licensed under the Elastic License 2.0. For more details,
see <https://github.com/canyongbs/aidingapp/blob/main/LICENSE.>
Notice:
- You may not provide the software to third parties as a hosted or managed
service, where the service provides users with access to any substantial set of
the features or functionality of the software.
- You may not move, change, disable, or circumvent the license key functionality
in the software, and you may not remove or obscure any functionality in the
software that is protected by the license key.
- You may not alter, remove, or obscure any licensing, copyright, or other notices
of the licensor in the software. Any use of the licensor’s trademarks is subject
to applicable law.
- Canyon GBS LLC respects the intellectual property rights of others and expects the
same in return. Canyon GBS™ and Aiding App™ are registered trademarks of
Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks
vigorously.
- The software solution, including services, infrastructure, and code, is offered as a
Software as a Service (SaaS) by Canyon GBS LLC.
- Use of this software implies agreement to the license terms and conditions as stated
in the Elastic License 2.0.
For more information or inquiries please visit our website at
<https://www.canyongbs.com> or contact us via email at legal@canyongbs.com.
EOM
def evaluateFile(filePath, startTag, endTag)
fullCopyright = "#{startTag}\n#{COPYRIGHT}\n#{endTag}"
if copyrightTagExists(startTag, endTag, filePath)
if copyrightNeedsUpdate(
startTag,
endTag,
filePath
)
puts "Updating copyright in #{filePath}...".brown
replace(filePath, startTag, endTag, "\n#{COPYRIGHT}\n")
else
puts "No changes needed in #{filePath}, skipping...".green
end
else
puts "Copyright not found in #{filePath}, adding copyright...".brown
insert(filePath, fullCopyright)
end
end
def copyrightTagExists(startTag, endTag, filePath)
!File.read(filePath).scan(/(?<=#{Regexp.escape(startTag)})([\S\s]*?)(?=#{Regexp.escape(endTag)})/m).empty?
end
def copyrightNeedsUpdate(startTag, endTag, filePath)
File.read(filePath).scan(/(?<=#{Regexp.escape(startTag)})(\n#{Regexp.escape(COPYRIGHT)}\n)(?=#{Regexp.escape(endTag)})/m).empty?
end
def insert(filePath, tag)
# If is a php file, insert after the opening php tag
if !(filePath =~ /\.blade\.php\z/) && File.extname(filePath) == '.php'
content = File.read(filePath)
File.write(filePath, content.gsub(/<\?php/, "<?php\n\n#{tag}"))
else
File.write(filePath, "#{tag}\n#{File.read(filePath)}")
end
end
def replace(filePath, startTag, endTag, replacement)
content = File.read(filePath)
File.write(filePath, content.gsub(/(?<=#{Regexp.escape(startTag)})[\S\s]*?(?=#{Regexp.escape(endTag)})/m, replacement))
end
def blade(filePath)
startTag = "{{--\n<COPYRIGHT>"
endTag = "</COPYRIGHT>\n--}}"
evaluateFile(filePath, startTag, endTag)
end
def php(filePath)
startTag = "/*\n<COPYRIGHT>"
endTag = "</COPYRIGHT>\n*/"
evaluateFile(filePath, startTag, endTag)
end
def js(filePath)
startTag = "/*\n<COPYRIGHT>"
endTag = "</COPYRIGHT>\n*/"
evaluateFile(filePath, startTag, endTag)
end
def css(filePath)
startTag = "/*\n<COPYRIGHT>"
endTag = "</COPYRIGHT>\n*/"
evaluateFile(filePath, startTag, endTag)
end
def vue(filePath)
startTag = "<!--\n<COPYRIGHT>"
endTag = "</COPYRIGHT>\n-->"
evaluateFile(filePath, startTag, endTag)
end
def handle(filePath)
if filePath =~ /\.blade\.php\z/
blade(filePath)
else
case File.extname(filePath)
when '.php'
php(filePath)
when '.js'
js(filePath)
when '.css'
css(filePath)
when '.vue'
vue(filePath)
else
puts "Unknown file type: #{filePath}, skipping...".gray
end
end
end
class String
def black; "\e[30m#{self}\e[0m" end
def red; "\e[31m#{self}\e[0m" end
def green; "\e[32m#{self}\e[0m" end
def brown; "\e[33m#{self}\e[0m" end
def blue; "\e[34m#{self}\e[0m" end
def magenta; "\e[35m#{self}\e[0m" end
def cyan; "\e[36m#{self}\e[0m" end
def gray; "\e[37m#{self}\e[0m" end
def bg_black; "\e[40m#{self}\e[0m" end
def bg_red; "\e[41m#{self}\e[0m" end
def bg_green; "\e[42m#{self}\e[0m" end
def bg_brown; "\e[43m#{self}\e[0m" end
def bg_blue; "\e[44m#{self}\e[0m" end
def bg_magenta; "\e[45m#{self}\e[0m" end
def bg_cyan; "\e[46m#{self}\e[0m" end
def bg_gray; "\e[47m#{self}\e[0m" end
def bold; "\e[1m#{self}\e[22m" end
def italic; "\e[3m#{self}\e[23m" end
def underline; "\e[4m#{self}\e[24m" end
def blink; "\e[5m#{self}\e[25m" end
def reverse_color; "\e[7m#{self}\e[27m" end
end
system('git', 'add', '.')
`git ls-files`.split.each do |file|
handle(file.chomp)
end