MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / updateDir

Function updateDir

javascript/update_copyright.js:53–94  ·  view source on GitHub ↗
(dirname)

Source from the content-addressed store, hash-verified

51updateDir(BASE_PATH);
52
53function 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}

Callers 1

Calls 7

normalizeMethod · 0.80
joinMethod · 0.80
splitMethod · 0.80
logMethod · 0.65
isDirectoryMethod · 0.65
forEachMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected