Skip to content

Commit

Permalink
dev(tools): add conflict prompt to license-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Jul 10, 2024
1 parent f006c9e commit d0a5a57
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tools/comment-parser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ const BlockCommentParser = ({
return {
parse: async (stream) => {
stream.skip_whitespace();
stream.debug('starting at', await stream.debug())
if ( ! stream.matches(start) ) return;
if ( ! await stream.matches(start) ) return;
stream.fwd(start.length);
const contents = await stream.get_until(end);
if ( ! contents ) return;
Expand Down Expand Up @@ -221,7 +220,7 @@ const CommentParser = () => {
javascript: {
parsers: [
['lines', {
prefix: '// ',
prefix: '//',
}],
['block', {
start: '/*',
Expand All @@ -231,7 +230,7 @@ const CommentParser = () => {
],
writers: {
lines: ['lines', {
prefix: '//'
prefix: '// '
}],
block: ['block', {
start: '/*',
Expand Down Expand Up @@ -312,6 +311,7 @@ const CommentParser = () => {
break;
}
}
console.log('comment?', comment);
if ( ! comment ) break;
results.push(comment);
}
Expand Down
21 changes: 21 additions & 0 deletions tools/license-headers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

const levenshtein = require('js-levenshtein');
const DiffMatchPatch = require('diff-match-patch');
const enq = require('enquirer');
const dmp = new DiffMatchPatch();
const dedent = require('dedent');

Expand Down Expand Up @@ -121,6 +122,8 @@ const LicenseChecker = ({
break;
}
}

console.log('headers', headers);

const combined = headers_lines.slice(top, bottom).flat();
const combined_txt = combined.join('\n');
Expand All @@ -130,6 +133,12 @@ const LicenseChecker = ({
header2: combined_txt,
})

if ( diff_info.distance > 0.7*desired_header.length ) {
return {
has_header: false,
};
}

diff_info.range = [
headers[top].range[0],
headers[bottom-1].range[1],
Expand Down Expand Up @@ -385,6 +394,18 @@ const cmd_sync_fn = async () => {
if ( diff_info.distance !== 0 ) {
counts.conflict++;
process.stdout.write(`\x1B[31;1mCONFLICT\x1B[0m\n`);
process.stdout.write('\x1B[36;1m=======\x1B[0m\n');
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: 'replace', message: 'Replace' },
]
})
const action = await prompt.run();
console.log('action', action);
} else {
counts.ok++;
process.stdout.write(`\x1B[32;1mOK\x1B[0m\n`);
Expand Down
1 change: 1 addition & 0 deletions tools/license-headers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"console-table-printer": "^2.12.1",
"dedent": "^1.5.3",
"diff-match-patch": "^1.0.5",
"enquirer": "^2.4.1",
"js-levenshtein": "^1.1.6",
"yaml": "^2.4.5"
}
Expand Down

0 comments on commit d0a5a57

Please sign in to comment.