-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate_license.rb
executable file
·60 lines (52 loc) · 2.03 KB
/
update_license.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
#!/usr/bin/env ruby
ruby_regex = /^#.\*{79}.*#.\*{79}$/m
erb_regex = /^<%.*#.\*{79}.*#.\*{79}.%>$/m
js_regex = %r{^/\* @preserve.*Copyright.*#.\*/}m
ruby_header_text = <<~EOT
# *******************************************************************************
# OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
# See also https://openstudio.net/license
# *******************************************************************************
EOT
ruby_header_text.strip!
erb_header_text = <<~EOT
<%
# *******************************************************************************
# OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
# See also https://openstudio.net/license
# *******************************************************************************
%>
EOT
erb_header_text.strip!
js_header_text = <<~EOT
/* @preserve
* OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC. reserved.
* See also https://openstudio.net/license
*/
EOT
js_header_text.strip!
paths = [
{ glob: 'lib/**/*.rb', license: ruby_header_text, regex: ruby_regex },
{ glob: 'spec/openstudio/workflow/*.rb', license: ruby_header_text, regex: ruby_regex },
{ glob: 'spec/openstudio/workflow/*.rb', license: ruby_header_text, regex: ruby_regex },
# single files
{ glob: 'spec/list_registry_options.rb', license: ruby_header_text, regex: ruby_regex },
{ glob: 'spec/spec_helper.rb', license: ruby_header_text, regex: ruby_regex }
]
paths.each do |path|
Dir[path[:glob]].each do |file|
puts "Updating license in file #{file}"
f = File.read(file)
if f =~ path[:regex]
puts ' License found -- updating'
File.open(file, 'w') { |write| write << f.gsub(path[:regex], path[:license]) }
else
puts ' No license found -- adding'
if f =~ /#!/
puts ' CANNOT add license to file automatically, add it manually and it will update automatically in the future'
next
end
File.open(file, 'w') { |write| write << f.insert(0, "#{path[:license]}\n\n") }
end
end
end