2015-04-04 09:53:59 -07:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
// KIND, either express or implied. See the License for the
|
|
|
|
|
// specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2025-03-25 14:28:37 +01:00
|
|
|
const fs = require('fs'),
|
2015-04-04 09:53:59 -07:00
|
|
|
path = require('path');
|
|
|
|
|
|
2025-03-25 14:28:37 +01:00
|
|
|
const COPYRIGHT_TEXT = [
|
2015-04-04 09:53:59 -07:00
|
|
|
'// Licensed to the Software Freedom Conservancy (SFC) under one',
|
|
|
|
|
'// or more contributor license agreements. See the NOTICE file',
|
|
|
|
|
'// distributed with this work for additional information',
|
|
|
|
|
'// regarding copyright ownership. The SFC licenses this file',
|
|
|
|
|
'// to you under the Apache License, Version 2.0 (the',
|
|
|
|
|
'// "License"); you may not use this file except in compliance',
|
|
|
|
|
'// with the License. You may obtain a copy of the License at',
|
|
|
|
|
'//',
|
|
|
|
|
'// http://www.apache.org/licenses/LICENSE-2.0',
|
|
|
|
|
'//',
|
|
|
|
|
'// Unless required by applicable law or agreed to in writing,',
|
|
|
|
|
'// software distributed under the License is distributed on an',
|
|
|
|
|
'// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY',
|
|
|
|
|
'// KIND, either express or implied. See the License for the',
|
|
|
|
|
'// specific language governing permissions and limitations',
|
|
|
|
|
'// under the License.',
|
|
|
|
|
''
|
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
|
|
|
2025-03-25 14:28:37 +01:00
|
|
|
let BASE_PATH = path.normalize(path.join(__dirname, '../javascript'));
|
2015-04-04 09:53:59 -07:00
|
|
|
|
|
|
|
|
// Ignore files whose copyright is not SFC or need manual inspection.
|
2025-03-25 14:28:37 +01:00
|
|
|
let IGNORE_PATHS = [
|
2015-04-04 09:53:59 -07:00
|
|
|
path.join(BASE_PATH, 'atoms/test/jquery.min.js'),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
updateDir(BASE_PATH);
|
|
|
|
|
|
|
|
|
|
function updateDir(dirname) {
|
|
|
|
|
dirname = path.normalize(dirname);
|
|
|
|
|
console.log('Scanning directory %s', dirname);
|
|
|
|
|
fs.readdirSync(dirname).forEach(function(filePath) {
|
|
|
|
|
if (filePath === 'node_modules') return;
|
|
|
|
|
|
|
|
|
|
filePath = path.normalize(path.join(dirname, filePath));
|
2025-03-25 14:28:37 +01:00
|
|
|
if (IGNORE_PATHS.indexOf(filePath) !== -1) {
|
2015-04-04 09:53:59 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fs.statSync(filePath).isDirectory()) {
|
|
|
|
|
updateDir(filePath);
|
|
|
|
|
} else if (/.*\.js$/.test(filePath)) {
|
2025-03-25 14:28:37 +01:00
|
|
|
let index = -1;
|
|
|
|
|
let lines = fs.readFileSync(filePath, 'utf8').split(/\n/);
|
2015-04-04 09:53:59 -07:00
|
|
|
lines.some(function(line) {
|
|
|
|
|
if (line.slice(0, 2) === '//') {
|
|
|
|
|
index += 1;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-25 14:28:37 +01:00
|
|
|
let content = COPYRIGHT_TEXT;
|
|
|
|
|
if (index === -1) {
|
2015-04-04 09:53:59 -07:00
|
|
|
console.log('...file is missing copyright header: %s', filePath);
|
|
|
|
|
content += '\n' + lines.join('\n');
|
|
|
|
|
} else {
|
2025-03-25 14:28:37 +01:00
|
|
|
let current = lines.slice(0, index + 1).join('\n') + '\n';
|
2015-04-04 09:53:59 -07:00
|
|
|
if (current === content) {
|
|
|
|
|
// console.log('...header is up-to-date: %s', filePath);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
console.log('...replacing copyright header: %s', filePath);
|
|
|
|
|
content += lines.slice(index + 1).join('\n');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|