Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/update_copyright.js
2864 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
'use strict';
19
20
const fs = require('fs'),
21
path = require('path');
22
23
const COPYRIGHT_TEXT = [
24
'// Licensed to the Software Freedom Conservancy (SFC) under one',
25
'// or more contributor license agreements. See the NOTICE file',
26
'// distributed with this work for additional information',
27
'// regarding copyright ownership. The SFC licenses this file',
28
'// to you under the Apache License, Version 2.0 (the',
29
'// "License"); you may not use this file except in compliance',
30
'// with the License. You may obtain a copy of the License at',
31
'//',
32
'// http://www.apache.org/licenses/LICENSE-2.0',
33
'//',
34
'// Unless required by applicable law or agreed to in writing,',
35
'// software distributed under the License is distributed on an',
36
'// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY',
37
'// KIND, either express or implied. See the License for the',
38
'// specific language governing permissions and limitations',
39
'// under the License.',
40
''
41
].join('\n');
42
43
44
let BASE_PATH = path.normalize(path.join(__dirname, '../javascript'));
45
46
// Ignore files whose copyright is not SFC or need manual inspection.
47
let IGNORE_PATHS = [
48
path.join(BASE_PATH, 'atoms/test/jquery.min.js'),
49
];
50
51
updateDir(BASE_PATH);
52
53
function updateDir(dirname) {
54
dirname = path.normalize(dirname);
55
console.log('Scanning directory %s', dirname);
56
fs.readdirSync(dirname).forEach(function(filePath) {
57
if (filePath === 'node_modules') return;
58
59
filePath = path.normalize(path.join(dirname, filePath));
60
if (IGNORE_PATHS.indexOf(filePath) !== -1) {
61
return;
62
}
63
64
if (fs.statSync(filePath).isDirectory()) {
65
updateDir(filePath);
66
} else if (/.*\.js$/.test(filePath)) {
67
let index = -1;
68
let lines = fs.readFileSync(filePath, 'utf8').split(/\n/);
69
lines.some(function(line) {
70
if (line.slice(0, 2) === '//') {
71
index += 1;
72
return false;
73
}
74
return true;
75
});
76
77
let content = COPYRIGHT_TEXT;
78
if (index === -1) {
79
console.log('...file is missing copyright header: %s', filePath);
80
content += '\n' + lines.join('\n');
81
} else {
82
let current = lines.slice(0, index + 1).join('\n') + '\n';
83
if (current === content) {
84
// console.log('...header is up-to-date: %s', filePath);
85
return;
86
} else {
87
console.log('...replacing copyright header: %s', filePath);
88
content += lines.slice(index + 1).join('\n');
89
}
90
}
91
fs.writeFileSync(filePath, content, 'utf8');
92
}
93
})
94
}
95
96