Skip to content

Commit

Permalink
dev(license-headers): add dupe detector
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Jul 10, 2024
1 parent 6728dd2 commit e6e92dc
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tools/license-headers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,49 @@ const cmd_sync_fn = async () => {
after;
fs.writeFileSync(value.path, new_source);
} else {
let cut_diff_info = diff_info;
let cut_source = source;
const cut_header = async () => {
cut_source = cut_source.slice(cut_diff_info.range[1]);
cut_diff_info = await license_checker.compare({
filename: value.name,
source: cut_source,
});
};
await cut_header();
const cut_range = [
diff_info.range[1],
diff_info.range[1],
];
const cut_diff_infos = [];
while ( cut_diff_info.has_header ) {
cut_diff_infos.push(cut_diff_info);
cut_range[1] = cut_diff_info.range[1];
await cut_header();
}
if ( cut_range[0] !== cut_range[1] ) {
process.stdout.write(`\x1B[31;1mDUPLICATE\x1B[0m\n`);
process.stdout.write('\x1B[36;1m==== KEEP ====\x1B[0m\n');
process.stdout.write(diff_info.term_diff + '\n');
process.stdout.write('\x1B[36;1m==== REMOVE ====\x1B[0m\n');
for ( const diff_info of cut_diff_infos ) {
process.stdout.write(diff_info.term_diff);
}
process.stdout.write('\n\x1B[36;1m=======\x1B[0m\n');
const prompt = new enq.Select({
message: 'Select Action',
choices: [
{ name: 'skip', message: 'Skip' },
{ name: 'remove', message: 'Remove' },
]
})
const action = await prompt.run();
if ( action === 'skip' ) continue;
const new_source =
source.slice(0, cut_range[0]) +
source.slice(cut_range[1]);
fs.writeFileSync(value.path, new_source);
}
counts.ok++;
process.stdout.write(`\x1B[32;1mOK\x1B[0m\n`);
}
Expand Down

0 comments on commit e6e92dc

Please sign in to comment.